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

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

Issue 1129293002: Fix the System Profile with extensions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: and a few fewer unnecessary checks 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
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 // SystemProfile also needs characteristics of being off the record, such
msw 2015/05/21 04:34:43 nit: "The system profile"
Mike Lerman 2015/05/21 15:27:31 Done.
442 // as having no extensions, not writing to disk, etc.
443 if (profile->GetPath() == ProfileManager::GetGuestProfilePath() ||
444 profile->GetPath() == ProfileManager::GetSystemProfilePath()) {
msw 2015/05/21 04:34:43 nit: use profile->IsSystemProfile() instead? (ditt
Mike Lerman 2015/05/21 15:27:31 This works now, as these items are set during prof
441 SetGuestProfilePrefs(profile); 445 SetGuestProfilePrefs(profile);
msw 2015/05/21 04:34:43 nit: maybe this should be renamed?
Mike Lerman 2015/05/21 15:27:30 I tried "SetNonPersonalProfilePrefs" since the pro
msw 2015/05/21 17:48:11 SetNonPersonalProfilePrefs sgtm. SetSystemProfileP
442 profile = profile->GetOffTheRecordProfile(); 446 profile = profile->GetOffTheRecordProfile();
443 } 447 }
444 // Profile has already been created. Run callback immediately. 448 // Profile has already been created. Run callback immediately.
445 callback.Run(profile, Profile::CREATE_STATUS_INITIALIZED); 449 callback.Run(profile, Profile::CREATE_STATUS_INITIALIZED);
446 } else { 450 } else {
447 // Profile is either already in the process of being created, or new. 451 // Profile is either already in the process of being created, or new.
448 // Add callback to the list. 452 // Add callback to the list.
449 info->callbacks.push_back(callback); 453 info->callbacks.push_back(callback);
450 } 454 }
451 } 455 }
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 info->created = true; 999 info->created = true;
996 } else { 1000 } else {
997 profile = NULL; 1001 profile = NULL;
998 profiles_info_.erase(iter); 1002 profiles_info_.erase(iter);
999 // TODO(yiyaoliu): This is temporary, remove it after it's not used. 1003 // TODO(yiyaoliu): This is temporary, remove it after it's not used.
1000 UMA_HISTOGRAM_COUNTS_100("UMA.ProfilesCount.AfterErase", 1004 UMA_HISTOGRAM_COUNTS_100("UMA.ProfilesCount.AfterErase",
1001 profiles_info_.size()); 1005 profiles_info_.size());
1002 } 1006 }
1003 1007
1004 if (profile) { 1008 if (profile) {
1005 // If this was the guest profile, finish setting its special status. 1009 // If this was the guest profile, finish setting its special status.
msw 2015/05/21 04:34:43 nit: update comment.
Mike Lerman 2015/05/21 15:27:30 Done.
1006 if (profile->GetPath() == ProfileManager::GetGuestProfilePath()) 1010 if (profile->GetPath() == ProfileManager::GetGuestProfilePath() ||
msw 2015/05/21 04:34:43 ditto nit: use IsSystemProfile() and IsGuestSessio
Mike Lerman 2015/05/21 15:27:31 Done.
1011 profile->GetPath() == ProfileManager::GetSystemProfilePath()) {
1007 SetGuestProfilePrefs(profile); 1012 SetGuestProfilePrefs(profile);
1013 }
1008 1014
1009 // Invoke CREATED callback for incognito profiles. 1015 // Invoke CREATED callback for incognito profiles.
1010 if (go_off_the_record) 1016 if (go_off_the_record)
1011 RunCallbacks(callbacks, profile, Profile::CREATE_STATUS_CREATED); 1017 RunCallbacks(callbacks, profile, Profile::CREATE_STATUS_CREATED);
1012 } 1018 }
1013 1019
1014 // Invoke INITIALIZED or FAIL for all profiles. 1020 // Invoke INITIALIZED or FAIL for all profiles.
1015 RunCallbacks(callbacks, profile, 1021 RunCallbacks(callbacks, profile,
1016 profile ? Profile::CREATE_STATUS_INITIALIZED : 1022 profile ? Profile::CREATE_STATUS_INITIALIZED :
1017 Profile::CREATE_STATUS_LOCAL_FAIL); 1023 Profile::CREATE_STATUS_LOCAL_FAIL);
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1322 cache.GetIndexOfProfileWithPath(profile->GetPath()), true); 1328 cache.GetIndexOfProfileWithPath(profile->GetPath()), true);
1323 } 1329 }
1324 } 1330 }
1325 1331
1326 void ProfileManager::SetGuestProfilePrefs(Profile* profile) { 1332 void ProfileManager::SetGuestProfilePrefs(Profile* profile) {
1327 PrefService* prefs = profile->GetPrefs(); 1333 PrefService* prefs = profile->GetPrefs();
1328 prefs->SetBoolean(prefs::kSigninAllowed, false); 1334 prefs->SetBoolean(prefs::kSigninAllowed, false);
1329 prefs->SetBoolean(bookmarks::prefs::kEditBookmarksEnabled, false); 1335 prefs->SetBoolean(bookmarks::prefs::kEditBookmarksEnabled, false);
1330 prefs->SetBoolean(bookmarks::prefs::kShowBookmarkBar, false); 1336 prefs->SetBoolean(bookmarks::prefs::kShowBookmarkBar, false);
1331 prefs->ClearPref(DefaultSearchManager::kDefaultSearchProviderDataPrefName); 1337 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 } 1338 }
1337 1339
1338 bool ProfileManager::ShouldGoOffTheRecord(Profile* profile) { 1340 bool ProfileManager::ShouldGoOffTheRecord(Profile* profile) {
1339 #if defined(OS_CHROMEOS) 1341 #if defined(OS_CHROMEOS)
1340 if (profile->GetPath().BaseName().value() == chrome::kInitialProfile) { 1342 if (profile->GetPath().BaseName().value() == chrome::kInitialProfile) {
1341 return true; 1343 return true;
1342 } 1344 }
1343 #endif 1345 #endif
1344 return profile->IsGuestSession(); 1346 return profile->IsGuestSession() || profile->IsSystemProfile();
1345 } 1347 }
1346 1348
1347 void ProfileManager::RunCallbacks(const std::vector<CreateCallback>& callbacks, 1349 void ProfileManager::RunCallbacks(const std::vector<CreateCallback>& callbacks,
1348 Profile* profile, 1350 Profile* profile,
1349 Profile::CreateStatus status) { 1351 Profile::CreateStatus status) {
1350 for (size_t i = 0; i < callbacks.size(); ++i) 1352 for (size_t i = 0; i < callbacks.size(); ++i)
1351 callbacks[i].Run(profile, status); 1353 callbacks[i].Run(profile, status);
1352 } 1354 }
1353 1355
1354 ProfileManager::ProfileInfo::ProfileInfo( 1356 ProfileManager::ProfileInfo::ProfileInfo(
1355 Profile* profile, 1357 Profile* profile,
1356 bool created) 1358 bool created)
1357 : profile(profile), 1359 : profile(profile),
1358 created(created) { 1360 created(created) {
1359 } 1361 }
1360 1362
1361 ProfileManager::ProfileInfo::~ProfileInfo() { 1363 ProfileManager::ProfileInfo::~ProfileInfo() {
1362 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); 1364 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release());
1363 } 1365 }
1364 1366
1365 #if !defined(OS_ANDROID) && !defined(OS_IOS) 1367 #if !defined(OS_ANDROID) && !defined(OS_IOS)
1366 void ProfileManager::UpdateLastUser(Profile* last_active) { 1368 void ProfileManager::UpdateLastUser(Profile* last_active) {
1367 PrefService* local_state = g_browser_process->local_state(); 1369 PrefService* local_state = g_browser_process->local_state();
1368 DCHECK(local_state); 1370 DCHECK(local_state);
1369 // Only keep track of profiles that we are managing; tests may create others. 1371 // Only keep track of profiles that we are managing; tests may create others.
1370 if (profiles_info_.find(last_active->GetPath()) != profiles_info_.end()) { 1372 // Also never consider the SystemProfile as "active".
1373 if (profiles_info_.find(last_active->GetPath()) != profiles_info_.end() &&
1374 !last_active->IsSystemProfile()) {
1371 std::string profile_path_base = 1375 std::string profile_path_base =
1372 last_active->GetPath().BaseName().MaybeAsASCII(); 1376 last_active->GetPath().BaseName().MaybeAsASCII();
1373 if (profile_path_base != GetLastUsedProfileName()) 1377 if (profile_path_base != GetLastUsedProfileName())
1374 local_state->SetString(prefs::kProfileLastUsed, profile_path_base); 1378 local_state->SetString(prefs::kProfileLastUsed, profile_path_base);
1375 1379
1376 ProfileInfoCache& cache = GetProfileInfoCache(); 1380 ProfileInfoCache& cache = GetProfileInfoCache();
1377 size_t profile_index = 1381 size_t profile_index =
1378 cache.GetIndexOfProfileWithPath(last_active->GetPath()); 1382 cache.GetIndexOfProfileWithPath(last_active->GetPath());
1379 if (profile_index != std::string::npos) 1383 if (profile_index != std::string::npos)
1380 cache.SetProfileActiveTimeAtIndex(profile_index); 1384 cache.SetProfileActiveTimeAtIndex(profile_index);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1455 } 1459 }
1456 1460
1457 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path); 1461 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path);
1458 if (!original_callback.is_null()) 1462 if (!original_callback.is_null())
1459 original_callback.Run(loaded_profile, status); 1463 original_callback.Run(loaded_profile, status);
1460 } 1464 }
1461 1465
1462 ProfileManagerWithoutInit::ProfileManagerWithoutInit( 1466 ProfileManagerWithoutInit::ProfileManagerWithoutInit(
1463 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { 1467 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) {
1464 } 1468 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698