Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: chrome/browser/profiles/profile_manager.cc

Issue 1157273006: Fix the System Profile to not load extensions. It could otherwise be forced to by GPO. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2403
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/profiles/profile_manager.h ('k') | chrome/browser/profiles/profile_window.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/profiles/profile_manager.h" 5 #include "chrome/browser/profiles/profile_manager.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 // static 297 // static
298 Profile* ProfileManager::GetLastUsedProfile() { 298 Profile* ProfileManager::GetLastUsedProfile() {
299 ProfileManager* profile_manager = g_browser_process->profile_manager(); 299 ProfileManager* profile_manager = g_browser_process->profile_manager();
300 return profile_manager->GetLastUsedProfile(profile_manager->user_data_dir_); 300 return profile_manager->GetLastUsedProfile(profile_manager->user_data_dir_);
301 } 301 }
302 302
303 // static 303 // static
304 Profile* ProfileManager::GetLastUsedProfileAllowedByPolicy() { 304 Profile* ProfileManager::GetLastUsedProfileAllowedByPolicy() {
305 Profile* profile = GetLastUsedProfile(); 305 Profile* profile = GetLastUsedProfile();
306 if (profile->IsGuestSession() || 306 if (profile->IsGuestSession() ||
307 profile->IsSystemProfile() ||
307 IncognitoModePrefs::GetAvailability(profile->GetPrefs()) == 308 IncognitoModePrefs::GetAvailability(profile->GetPrefs()) ==
308 IncognitoModePrefs::FORCED) { 309 IncognitoModePrefs::FORCED) {
309 return profile->GetOffTheRecordProfile(); 310 return profile->GetOffTheRecordProfile();
310 } 311 }
311 return profile; 312 return profile;
312 } 313 }
313 314
314 // static 315 // static
315 std::vector<Profile*> ProfileManager::GetLastOpenedProfiles() { 316 std::vector<Profile*> ProfileManager::GetLastOpenedProfiles() {
316 ProfileManager* profile_manager = g_browser_process->profile_manager(); 317 ProfileManager* profile_manager = g_browser_process->profile_manager();
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 } 431 }
431 432
432 ProfileMetrics::UpdateReportedProfilesStatistics(this); 433 ProfileMetrics::UpdateReportedProfilesStatistics(this);
433 } 434 }
434 435
435 // Call or enqueue the callback. 436 // Call or enqueue the callback.
436 if (!callback.is_null()) { 437 if (!callback.is_null()) {
437 if (iter != profiles_info_.end() && info->created) { 438 if (iter != profiles_info_.end() && info->created) {
438 Profile* profile = info->profile.get(); 439 Profile* profile = info->profile.get();
439 // If this was the guest profile, apply settings and go OffTheRecord. 440 // If this was the guest profile, apply settings and go OffTheRecord.
440 if (profile->GetPath() == ProfileManager::GetGuestProfilePath()) { 441 // The system profile also needs characteristics of being off the record,
441 SetGuestProfilePrefs(profile); 442 // such as having no extensions, not writing to disk, etc.
443 if (profile->IsGuestSession() || profile->IsSystemProfile()) {
444 SetNonPersonalProfilePrefs(profile);
442 profile = profile->GetOffTheRecordProfile(); 445 profile = profile->GetOffTheRecordProfile();
443 } 446 }
444 // Profile has already been created. Run callback immediately. 447 // Profile has already been created. Run callback immediately.
445 callback.Run(profile, Profile::CREATE_STATUS_INITIALIZED); 448 callback.Run(profile, Profile::CREATE_STATUS_INITIALIZED);
446 } else { 449 } else {
447 // Profile is either already in the process of being created, or new. 450 // Profile is either already in the process of being created, or new.
448 // Add callback to the list. 451 // Add callback to the list.
449 info->callbacks.push_back(callback); 452 info->callbacks.push_back(callback);
450 } 453 }
451 } 454 }
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 info->created = true; 998 info->created = true;
996 } else { 999 } else {
997 profile = NULL; 1000 profile = NULL;
998 profiles_info_.erase(iter); 1001 profiles_info_.erase(iter);
999 // TODO(yiyaoliu): This is temporary, remove it after it's not used. 1002 // TODO(yiyaoliu): This is temporary, remove it after it's not used.
1000 UMA_HISTOGRAM_COUNTS_100("UMA.ProfilesCount.AfterErase", 1003 UMA_HISTOGRAM_COUNTS_100("UMA.ProfilesCount.AfterErase",
1001 profiles_info_.size()); 1004 profiles_info_.size());
1002 } 1005 }
1003 1006
1004 if (profile) { 1007 if (profile) {
1005 // If this was the guest profile, finish setting its special status. 1008 // If this was the guest or system profile, finish setting its special
1006 if (profile->GetPath() == ProfileManager::GetGuestProfilePath()) 1009 // status.
1007 SetGuestProfilePrefs(profile); 1010 if (profile->IsGuestSession() || profile->IsSystemProfile())
1011 SetNonPersonalProfilePrefs(profile);
1008 1012
1009 // Invoke CREATED callback for incognito profiles. 1013 // Invoke CREATED callback for incognito profiles.
1010 if (go_off_the_record) 1014 if (go_off_the_record)
1011 RunCallbacks(callbacks, profile, Profile::CREATE_STATUS_CREATED); 1015 RunCallbacks(callbacks, profile, Profile::CREATE_STATUS_CREATED);
1012 } 1016 }
1013 1017
1014 // Invoke INITIALIZED or FAIL for all profiles. 1018 // Invoke INITIALIZED or FAIL for all profiles.
1015 RunCallbacks(callbacks, profile, 1019 RunCallbacks(callbacks, profile,
1016 profile ? Profile::CREATE_STATUS_INITIALIZED : 1020 profile ? Profile::CREATE_STATUS_INITIALIZED :
1017 Profile::CREATE_STATUS_LOCAL_FAIL); 1021 Profile::CREATE_STATUS_LOCAL_FAIL);
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
1316 username, 1320 username,
1317 icon_index, 1321 icon_index,
1318 supervised_user_id); 1322 supervised_user_id);
1319 1323
1320 if (profile->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) { 1324 if (profile->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) {
1321 cache.SetProfileIsEphemeralAtIndex( 1325 cache.SetProfileIsEphemeralAtIndex(
1322 cache.GetIndexOfProfileWithPath(profile->GetPath()), true); 1326 cache.GetIndexOfProfileWithPath(profile->GetPath()), true);
1323 } 1327 }
1324 } 1328 }
1325 1329
1326 void ProfileManager::SetGuestProfilePrefs(Profile* profile) { 1330 void ProfileManager::SetNonPersonalProfilePrefs(Profile* profile) {
1327 PrefService* prefs = profile->GetPrefs(); 1331 PrefService* prefs = profile->GetPrefs();
1328 prefs->SetBoolean(prefs::kSigninAllowed, false); 1332 prefs->SetBoolean(prefs::kSigninAllowed, false);
1329 prefs->SetBoolean(bookmarks::prefs::kEditBookmarksEnabled, false); 1333 prefs->SetBoolean(bookmarks::prefs::kEditBookmarksEnabled, false);
1330 prefs->SetBoolean(bookmarks::prefs::kShowBookmarkBar, false); 1334 prefs->SetBoolean(bookmarks::prefs::kShowBookmarkBar, false);
1331 prefs->ClearPref(DefaultSearchManager::kDefaultSearchProviderDataPrefName); 1335 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);
1336 } 1336 }
1337 1337
1338 bool ProfileManager::ShouldGoOffTheRecord(Profile* profile) { 1338 bool ProfileManager::ShouldGoOffTheRecord(Profile* profile) {
1339 #if defined(OS_CHROMEOS) 1339 #if defined(OS_CHROMEOS)
1340 if (profile->GetPath().BaseName().value() == chrome::kInitialProfile) { 1340 if (profile->GetPath().BaseName().value() == chrome::kInitialProfile) {
1341 return true; 1341 return true;
1342 } 1342 }
1343 #endif 1343 #endif
1344 return profile->IsGuestSession(); 1344 return profile->IsGuestSession() || profile->IsSystemProfile();
1345 } 1345 }
1346 1346
1347 void ProfileManager::RunCallbacks(const std::vector<CreateCallback>& callbacks, 1347 void ProfileManager::RunCallbacks(const std::vector<CreateCallback>& callbacks,
1348 Profile* profile, 1348 Profile* profile,
1349 Profile::CreateStatus status) { 1349 Profile::CreateStatus status) {
1350 for (size_t i = 0; i < callbacks.size(); ++i) 1350 for (size_t i = 0; i < callbacks.size(); ++i)
1351 callbacks[i].Run(profile, status); 1351 callbacks[i].Run(profile, status);
1352 } 1352 }
1353 1353
1354 ProfileManager::ProfileInfo::ProfileInfo( 1354 ProfileManager::ProfileInfo::ProfileInfo(
1355 Profile* profile, 1355 Profile* profile,
1356 bool created) 1356 bool created)
1357 : profile(profile), 1357 : profile(profile),
1358 created(created) { 1358 created(created) {
1359 } 1359 }
1360 1360
1361 ProfileManager::ProfileInfo::~ProfileInfo() { 1361 ProfileManager::ProfileInfo::~ProfileInfo() {
1362 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); 1362 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release());
1363 } 1363 }
1364 1364
1365 #if !defined(OS_ANDROID) && !defined(OS_IOS) 1365 #if !defined(OS_ANDROID) && !defined(OS_IOS)
1366 void ProfileManager::UpdateLastUser(Profile* last_active) { 1366 void ProfileManager::UpdateLastUser(Profile* last_active) {
1367 PrefService* local_state = g_browser_process->local_state(); 1367 PrefService* local_state = g_browser_process->local_state();
1368 DCHECK(local_state); 1368 DCHECK(local_state);
1369 // Only keep track of profiles that we are managing; tests may create others. 1369 // 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()) {
1371 std::string profile_path_base = 1373 std::string profile_path_base =
1372 last_active->GetPath().BaseName().MaybeAsASCII(); 1374 last_active->GetPath().BaseName().MaybeAsASCII();
1373 if (profile_path_base != GetLastUsedProfileName()) 1375 if (profile_path_base != GetLastUsedProfileName())
1374 local_state->SetString(prefs::kProfileLastUsed, profile_path_base); 1376 local_state->SetString(prefs::kProfileLastUsed, profile_path_base);
1375 1377
1376 ProfileInfoCache& cache = GetProfileInfoCache(); 1378 ProfileInfoCache& cache = GetProfileInfoCache();
1377 size_t profile_index = 1379 size_t profile_index =
1378 cache.GetIndexOfProfileWithPath(last_active->GetPath()); 1380 cache.GetIndexOfProfileWithPath(last_active->GetPath());
1379 if (profile_index != std::string::npos) 1381 if (profile_index != std::string::npos)
1380 cache.SetProfileActiveTimeAtIndex(profile_index); 1382 cache.SetProfileActiveTimeAtIndex(profile_index);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1455 } 1457 }
1456 1458
1457 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path); 1459 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path);
1458 if (!original_callback.is_null()) 1460 if (!original_callback.is_null())
1459 original_callback.Run(loaded_profile, status); 1461 original_callback.Run(loaded_profile, status);
1460 } 1462 }
1461 1463
1462 ProfileManagerWithoutInit::ProfileManagerWithoutInit( 1464 ProfileManagerWithoutInit::ProfileManagerWithoutInit(
1463 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { 1465 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) {
1464 } 1466 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_manager.h ('k') | chrome/browser/profiles/profile_window.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698