Skip to content

Commit a515307

Browse files
author
Mike Lerman
committed
Fix the System Profile to not load extensions. It could otherwise be forced to by GPO.
A few releases ago I introduced a System Profile to back the User Manager (https://codereview.chromium.org/847733005). This profile, however, is causing some problems. I'm trying to reduce those by making clearer the contract of what it's for: A profile that doesn't take a browser window, has no extensions, writes little to disk, etc. This certainly addresses issue #4 raised within the bug, and address the other issues as well (I can't repro them). This CL generally hardens Chrome for the System Profile in a lot of the same ways we do the Guest Profile. BUG=482176 [email protected] Review URL: https://codereview.chromium.org/1129293002 Cr-Commit-Position: refs/heads/master@{#331276} (cherry picked from commit 7831f57) Review URL: https://codereview.chromium.org/1157273006 Cr-Commit-Position: refs/branch-heads/2403@{crosswalk-project#116} Cr-Branched-From: f54b809-refs/heads/master@{#330231}
1 parent 1ea9eac commit a515307

13 files changed

+64
-35
lines changed

chrome/browser/app_controller_mac.mm

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,9 +1032,10 @@ - (void)commandDispatch:(id)sender {
10321032
NSInteger tag = [sender tag];
10331033

10341034
// If there are no browser windows, and we are trying to open a browser
1035-
// for a locked profile, we have to show the User Manager instead as the
1036-
// locked profile needs authentication.
1037-
if (IsProfileSignedOut(lastProfile)) {
1035+
// for a locked profile or the system profile, we have to show the User
1036+
// Manager instead as the locked profile needs authentication and the system
1037+
// profile cannot have a browser.
1038+
if (IsProfileSignedOut(lastProfile) || lastProfile->IsSystemProfile()) {
10381039
UserManager::Show(base::FilePath(),
10391040
profiles::USER_MANAGER_NO_TUTORIAL,
10401041
profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);
@@ -1246,11 +1247,12 @@ - (BOOL)applicationShouldHandleReopen:(NSApplication*)theApplication
12461247

12471248
// Otherwise open a new window.
12481249
// If the last profile was locked, we have to open the User Manager, as the
1249-
// profile requires authentication. Similarly, because guest mode is
1250-
// implemented as forced incognito, we can't open a new guest browser either,
1251-
// so we have to show the User Manager as well.
1250+
// profile requires authentication. Similarly, because guest mode and system
1251+
// profile are implemented as forced incognito, we can't open a new guest
1252+
// browser either, so we have to show the User Manager as well.
12521253
Profile* lastProfile = [self lastProfile];
1253-
if (lastProfile->IsGuestSession() || IsProfileSignedOut(lastProfile)) {
1254+
if (lastProfile->IsGuestSession() || IsProfileSignedOut(lastProfile) ||
1255+
lastProfile->IsSystemProfile()) {
12541256
UserManager::Show(base::FilePath(),
12551257
profiles::USER_MANAGER_NO_TUTORIAL,
12561258
profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);

chrome/browser/extensions/chrome_process_manager_delegate.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ bool ChromeProcessManagerDelegate::IsBackgroundPageAllowed(
4141
content::BrowserContext* context) const {
4242
Profile* profile = static_cast<Profile*>(context);
4343

44-
bool is_normal_session = !profile->IsGuestSession();
44+
bool is_normal_session = !profile->IsGuestSession() &&
45+
!profile->IsSystemProfile();
4546
#if defined(OS_CHROMEOS)
4647
is_normal_session = is_normal_session &&
4748
user_manager::UserManager::Get()->IsUserLoggedIn();

chrome/browser/extensions/extension_system_impl.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@ void ExtensionSystemImpl::Shared::Init(bool extensions_enabled) {
310310
// ExtensionService depends on RuntimeData.
311311
runtime_data_.reset(new RuntimeData(ExtensionRegistry::Get(profile_)));
312312

313-
bool autoupdate_enabled = !profile_->IsGuestSession();
313+
bool autoupdate_enabled = !profile_->IsGuestSession() &&
314+
!profile_->IsSystemProfile();
314315
#if defined(OS_CHROMEOS)
315316
if (!extensions_enabled)
316317
autoupdate_enabled = false;

chrome/browser/extensions/tab_helper.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ bool TabHelper::CanCreateApplicationShortcuts() const {
144144

145145
bool TabHelper::CanCreateBookmarkApp() const {
146146
return !profile_->IsGuestSession() &&
147+
!profile_->IsSystemProfile() &&
147148
IsValidBookmarkAppUrl(web_contents()->GetURL());
148149
}
149150

chrome/browser/profiles/profile_manager.cc

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ Profile* ProfileManager::GetLastUsedProfile() {
304304
Profile* ProfileManager::GetLastUsedProfileAllowedByPolicy() {
305305
Profile* profile = GetLastUsedProfile();
306306
if (profile->IsGuestSession() ||
307+
profile->IsSystemProfile() ||
307308
IncognitoModePrefs::GetAvailability(profile->GetPrefs()) ==
308309
IncognitoModePrefs::FORCED) {
309310
return profile->GetOffTheRecordProfile();
@@ -437,8 +438,10 @@ void ProfileManager::CreateProfileAsync(
437438
if (iter != profiles_info_.end() && info->created) {
438439
Profile* profile = info->profile.get();
439440
// If this was the guest profile, apply settings and go OffTheRecord.
440-
if (profile->GetPath() == ProfileManager::GetGuestProfilePath()) {
441-
SetGuestProfilePrefs(profile);
441+
// The system profile also needs characteristics of being off the record,
442+
// such as having no extensions, not writing to disk, etc.
443+
if (profile->IsGuestSession() || profile->IsSystemProfile()) {
444+
SetNonPersonalProfilePrefs(profile);
442445
profile = profile->GetOffTheRecordProfile();
443446
}
444447
// Profile has already been created. Run callback immediately.
@@ -1002,9 +1005,10 @@ void ProfileManager::OnProfileCreated(Profile* profile,
10021005
}
10031006

10041007
if (profile) {
1005-
// If this was the guest profile, finish setting its special status.
1006-
if (profile->GetPath() == ProfileManager::GetGuestProfilePath())
1007-
SetGuestProfilePrefs(profile);
1008+
// If this was the guest or system profile, finish setting its special
1009+
// status.
1010+
if (profile->IsGuestSession() || profile->IsSystemProfile())
1011+
SetNonPersonalProfilePrefs(profile);
10081012

10091013
// Invoke CREATED callback for incognito profiles.
10101014
if (go_off_the_record)
@@ -1323,16 +1327,12 @@ void ProfileManager::AddProfileToCache(Profile* profile) {
13231327
}
13241328
}
13251329

1326-
void ProfileManager::SetGuestProfilePrefs(Profile* profile) {
1330+
void ProfileManager::SetNonPersonalProfilePrefs(Profile* profile) {
13271331
PrefService* prefs = profile->GetPrefs();
13281332
prefs->SetBoolean(prefs::kSigninAllowed, false);
13291333
prefs->SetBoolean(bookmarks::prefs::kEditBookmarksEnabled, false);
13301334
prefs->SetBoolean(bookmarks::prefs::kShowBookmarkBar, false);
13311335
prefs->ClearPref(DefaultSearchManager::kDefaultSearchProviderDataPrefName);
1332-
// This can be removed in the future but needs to be present through
1333-
// a release (or two) so that any existing installs get switched to
1334-
// the new state and away from the previous "forced" state.
1335-
IncognitoModePrefs::SetAvailability(prefs, IncognitoModePrefs::ENABLED);
13361336
}
13371337

13381338
bool ProfileManager::ShouldGoOffTheRecord(Profile* profile) {
@@ -1341,7 +1341,7 @@ bool ProfileManager::ShouldGoOffTheRecord(Profile* profile) {
13411341
return true;
13421342
}
13431343
#endif
1344-
return profile->IsGuestSession();
1344+
return profile->IsGuestSession() || profile->IsSystemProfile();
13451345
}
13461346

13471347
void ProfileManager::RunCallbacks(const std::vector<CreateCallback>& callbacks,
@@ -1367,7 +1367,9 @@ void ProfileManager::UpdateLastUser(Profile* last_active) {
13671367
PrefService* local_state = g_browser_process->local_state();
13681368
DCHECK(local_state);
13691369
// Only keep track of profiles that we are managing; tests may create others.
1370-
if (profiles_info_.find(last_active->GetPath()) != profiles_info_.end()) {
1370+
// Also never consider the SystemProfile as "active".
1371+
if (profiles_info_.find(last_active->GetPath()) != profiles_info_.end() &&
1372+
!last_active->IsSystemProfile()) {
13711373
std::string profile_path_base =
13721374
last_active->GetPath().BaseName().MaybeAsASCII();
13731375
if (profile_path_base != GetLastUsedProfileName())

chrome/browser/profiles/profile_manager.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,9 @@ class ProfileManager : public base::NonThreadSafe,
286286
// Adds |profile| to the profile info cache if it hasn't been added yet.
287287
void AddProfileToCache(Profile* profile);
288288

289-
// Apply settings for (desktop) Guest User profile.
290-
void SetGuestProfilePrefs(Profile* profile);
289+
// Apply settings for profiles created by the system rather than users: The
290+
// (desktop) Guest User profile and (desktop) System Profile.
291+
void SetNonPersonalProfilePrefs(Profile* profile);
291292

292293
// For ChromeOS, determines if profile should be otr.
293294
bool ShouldGoOffTheRecord(Profile* profile);

chrome/browser/profiles/profile_window.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ bool IsLockAvailable(Profile* profile) {
383383
if (!switches::IsNewProfileManagement())
384384
return false;
385385

386-
if (profile->IsGuestSession())
386+
if (profile->IsGuestSession() || profile->IsSystemProfile())
387387
return false;
388388

389389
std::string hosted_domain = profile->GetPrefs()->

chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,9 @@ ChromeLauncherController::ChromeLauncherController(Profile* profile,
374374
// Use the original profile as on chromeos we may get a temporary off the
375375
// record profile, unless in guest session (where off the record profile is
376376
// the right one).
377-
Profile* active_profile = ProfileManager::GetActiveUserProfile();
378-
profile_ = active_profile->IsGuestSession() ? active_profile :
379-
active_profile->GetOriginalProfile();
377+
profile_ = ProfileManager::GetActiveUserProfile();
378+
if (!profile_->IsGuestSession() && !profile_->IsSystemProfile())
379+
profile_ = profile_->GetOriginalProfile();
380380

381381
app_sync_ui_state_ = AppSyncUIState::Get(profile_);
382382
if (app_sync_ui_state_)
@@ -2052,7 +2052,8 @@ bool ChromeLauncherController::IsIncognito(
20522052
const content::WebContents* web_contents) const {
20532053
const Profile* profile =
20542054
Profile::FromBrowserContext(web_contents->GetBrowserContext());
2055-
return profile->IsOffTheRecord() && !profile->IsGuestSession();
2055+
return profile->IsOffTheRecord() && !profile->IsGuestSession() &&
2056+
!profile->IsSystemProfile();
20562057
}
20572058

20582059
void ChromeLauncherController::CloseWindowedAppsFromRemovedExtension(

chrome/browser/ui/browser.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,12 @@ Browser::Browser(const CreateParams& params)
365365
CHECK(IncognitoModePrefs::CanOpenBrowser(profile_));
366366
CHECK(!profile_->IsGuestSession() || profile_->IsOffTheRecord())
367367
<< "Only off the record browser may be opened in guest mode";
368+
DCHECK(!profile_->IsSystemProfile())
369+
<< "The system profile should never have a real browser.";
370+
// TODO(mlerman): After this hits stable channel, see if there are counts
371+
// for this metric. If not, change the DCHECK above to a CHECK.
372+
if (profile_->IsSystemProfile())
373+
content::RecordAction(base::UserMetricsAction("BrowserForSystemProfile"));
368374

369375
// TODO(jeremy): Move to initializer list once flag is removed.
370376
if (IsFastTabUnloadEnabled())

chrome/browser/ui/browser_command_controller.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,10 @@ void BrowserCommandController::InitCommandState() {
954954
command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true);
955955

956956
// Show various bits of UI
957-
const bool guest_session = profile()->IsGuestSession();
957+
const bool guest_session = profile()->IsGuestSession() ||
958+
profile()->IsSystemProfile();
959+
DCHECK(!profile()->IsSystemProfile())
960+
<< "Ought to never have browser for the system profile.";
958961
const bool normal_window = browser_->is_type_tabbed();
959962
UpdateOpenFileState(&command_updater_);
960963
command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, false);
@@ -1193,6 +1196,7 @@ void BrowserCommandController::UpdateCommandsForBookmarkBar() {
11931196
command_updater_.UpdateCommandEnabled(
11941197
IDC_SHOW_BOOKMARK_BAR,
11951198
browser_defaults::bookmarks_enabled && !profile()->IsGuestSession() &&
1199+
!profile()->IsSystemProfile() &&
11961200
!profile()->GetPrefs()->IsManagedPreference(
11971201
bookmarks::prefs::kShowBookmarkBar) &&
11981202
IsShowingMainUI());

chrome/browser/ui/startup/startup_browser_creator.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -682,15 +682,16 @@ bool StartupBrowserCreator::ProcessCmdLineImpl(
682682
bool signin_required = profile_index != std::string::npos &&
683683
profile_info.ProfileIsSigninRequiredAtIndex(profile_index);
684684

685-
// Guest or locked profiles cannot be re-opened on startup. The only
686-
// exception is if there's already a Guest window open in a separate
685+
// Guest, system or locked profiles cannot be re-opened on startup. The
686+
// only exception is if there's already a Guest window open in a separate
687687
// process (for example, launching a new browser after clicking on a
688688
// downloaded file in Guest mode).
689-
bool has_guest_browsers = last_used_profile->IsGuestSession() &&
689+
bool guest_or_system = last_used_profile->IsGuestSession() ||
690+
last_used_profile->IsSystemProfile();
691+
bool has_guest_browsers = guest_or_system &&
690692
chrome::GetTotalBrowserCountForProfile(
691693
last_used_profile->GetOffTheRecordProfile()) > 0;
692-
if (signin_required ||
693-
(last_used_profile->IsGuestSession() && !has_guest_browsers)) {
694+
if (signin_required || (guest_or_system && !has_guest_browsers)) {
694695
profiles::UserManagerProfileSelected action =
695696
command_line.HasSwitch(switches::kShowAppList) ?
696697
profiles::USER_MANAGER_SELECT_PROFILE_APP_LAUNCHER :

chrome/test/base/testing_profile_manager.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ TestingProfile* TestingProfileManager::CreateGuestProfile() {
130130
TestingProfile::Builder().BuildIncognito(profile);
131131

132132
profile_manager_->AddProfile(profile); // Takes ownership.
133-
profile_manager_->SetGuestProfilePrefs(profile);
133+
profile_manager_->SetNonPersonalProfilePrefs(profile);
134134

135135
testing_profiles_.insert(std::make_pair(kGuestProfileName, profile));
136136

tools/metrics/actions/actions.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,6 +1781,15 @@ should be able to be added at any place in this file.
17811781
<description>Please enter the description of this user action.</description>
17821782
</action>
17831783

1784+
<action name="BrowserForSystemProfile">
1785+
<owner>[email protected]</owner>
1786+
<description>
1787+
A browser opened with the System Profile. Tsk, tsk. Any non-zero amount
1788+
means something is using the system profile for a browser when it likely
1789+
shouldn't be.
1790+
</description>
1791+
</action>
1792+
17841793
<action name="BrowserPlugin.Guest.AbnormalDeath">
17851794
<owner>Please list the metric's owners. Add more owner tags as needed.</owner>
17861795
<description>Please enter the description of this user action.</description>

0 commit comments

Comments
 (0)