Don't open the 'stats for nerds' in a non-incognito window when incognito is forced.

Incognito mode may be always-on by configuration policy. When that is set then
the TaskManager shouldn't open a new non-incognito window.

The TaskManager doesn't have an associated Profile, so it uses the last used
Profile. This change introduces a getter for the last used allowed Profile,
which returns the OTR Profile if that's dictated by policy.

BUG=244246

Review URL: https://chromiumcodereview.appspot.com/16072014

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@203128 0039d316-1c4b-4281-b951-d872f2087c98
parent 7ca79123
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/prefs/scoped_user_pref_update.h" #include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/browser/profiles/bookmark_model_loaded_observer.h" #include "chrome/browser/profiles/bookmark_model_loaded_observer.h"
#include "chrome/browser/profiles/profile_destroyer.h" #include "chrome/browser/profiles/profile_destroyer.h"
...@@ -246,6 +247,16 @@ Profile* ProfileManager::GetLastUsedProfile() { ...@@ -246,6 +247,16 @@ Profile* ProfileManager::GetLastUsedProfile() {
return profile_manager->GetLastUsedProfile(profile_manager->user_data_dir_); return profile_manager->GetLastUsedProfile(profile_manager->user_data_dir_);
} }
// static
Profile* ProfileManager::GetLastUsedProfileAllowedByPolicy() {
Profile* profile = GetLastUsedProfile();
if (IncognitoModePrefs::GetAvailability(profile->GetPrefs()) ==
IncognitoModePrefs::FORCED) {
return profile->GetOffTheRecordProfile();
}
return profile;
}
// static // static
std::vector<Profile*> ProfileManager::GetLastOpenedProfiles() { std::vector<Profile*> ProfileManager::GetLastOpenedProfiles() {
ProfileManager* profile_manager = g_browser_process->profile_manager(); ProfileManager* profile_manager = g_browser_process->profile_manager();
......
...@@ -109,8 +109,15 @@ class ProfileManager : public base::NonThreadSafe, ...@@ -109,8 +109,15 @@ class ProfileManager : public base::NonThreadSafe,
Profile* GetLastUsedProfile(const base::FilePath& user_data_dir); Profile* GetLastUsedProfile(const base::FilePath& user_data_dir);
// Same as instance method but provides the default user_data_dir as well. // Same as instance method but provides the default user_data_dir as well.
// If the Profile is going to be used to open a new window then consider using
// GetLastUsedProfileAllowedByPolicy() instead.
static Profile* GetLastUsedProfile(); static Profile* GetLastUsedProfile();
// Same as GetLastUsedProfile() but returns the incognito Profile if
// incognito mode is forced. This should be used if the last used Profile
// will be used to open new browser windows.
static Profile* GetLastUsedProfileAllowedByPolicy();
// Get the path of the last used profile, or if that's undefined, the default // Get the path of the last used profile, or if that's undefined, the default
// profile. // profile.
base::FilePath GetLastUsedProfileDir(const base::FilePath& user_data_dir); base::FilePath GetLastUsedProfileDir(const base::FilePath& user_data_dir);
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/io_thread.h" #include "chrome/browser/io_thread.h"
#include "chrome/browser/prefs/browser_prefs.h" #include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_info_cache.h" #include "chrome/browser/profiles/profile_info_cache.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
...@@ -428,6 +429,37 @@ TEST_F(ProfileManagerTest, InitProfileInfoCacheForAProfile) { ...@@ -428,6 +429,37 @@ TEST_F(ProfileManagerTest, InitProfileInfoCacheForAProfile) {
cache.GetAvatarIconIndexOfProfileAtIndex(profile_index)); cache.GetAvatarIconIndexOfProfileAtIndex(profile_index));
} }
TEST_F(ProfileManagerTest, GetLastUsedProfileAllowedByPolicy) {
ProfileManager* profile_manager = g_browser_process->profile_manager();
ASSERT_TRUE(profile_manager);
Profile* profile = profile_manager->GetLastUsedProfileAllowedByPolicy();
ASSERT_TRUE(profile);
EXPECT_FALSE(profile->IsOffTheRecord());
PrefService* prefs = profile->GetPrefs();
EXPECT_EQ(IncognitoModePrefs::ENABLED,
IncognitoModePrefs::GetAvailability(prefs));
// Attach an incognito Profile to the TestingProfile.
ASSERT_FALSE(profile->GetOffTheRecordProfile());
TestingProfile* incognito_profile = new TestingProfile();
incognito_profile->set_incognito(true);
EXPECT_TRUE(incognito_profile->IsOffTheRecord());
TestingProfile* testing_profile = static_cast<TestingProfile*>(profile);
testing_profile->SetOffTheRecordProfile(incognito_profile);
ASSERT_TRUE(profile->GetOffTheRecordProfile());
IncognitoModePrefs::SetAvailability(prefs, IncognitoModePrefs::DISABLED);
EXPECT_FALSE(
profile_manager->GetLastUsedProfileAllowedByPolicy()->IsOffTheRecord());
// GetLastUsedProfileAllowedByPolicy() returns the incognito Profile when
// incognito mode is forced.
IncognitoModePrefs::SetAvailability(prefs, IncognitoModePrefs::FORCED);
EXPECT_TRUE(
profile_manager->GetLastUsedProfileAllowedByPolicy()->IsOffTheRecord());
}
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
// There's no Browser object on Android. // There's no Browser object on Android.
TEST_F(ProfileManagerTest, LastOpenedProfiles) { TEST_F(ProfileManagerTest, LastOpenedProfiles) {
......
...@@ -1545,7 +1545,7 @@ TaskManager* TaskManager::GetInstance() { ...@@ -1545,7 +1545,7 @@ TaskManager* TaskManager::GetInstance() {
void TaskManager::OpenAboutMemory(chrome::HostDesktopType desktop_type) { void TaskManager::OpenAboutMemory(chrome::HostDesktopType desktop_type) {
Browser* browser = chrome::FindOrCreateTabbedBrowser( Browser* browser = chrome::FindOrCreateTabbedBrowser(
ProfileManager::GetLastUsedProfile(), desktop_type); ProfileManager::GetLastUsedProfileAllowedByPolicy(), desktop_type);
chrome::NavigateParams params(browser, GURL(chrome::kChromeUIMemoryURL), chrome::NavigateParams params(browser, GURL(chrome::kChromeUIMemoryURL),
content::PAGE_TRANSITION_LINK); content::PAGE_TRANSITION_LINK);
params.disposition = NEW_FOREGROUND_TAB; params.disposition = NEW_FOREGROUND_TAB;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment