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 1129293002: Fix the System Profile with extensions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove autogenerated actions 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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 // static 299 // static
300 Profile* ProfileManager::GetLastUsedProfile() { 300 Profile* ProfileManager::GetLastUsedProfile() {
301 ProfileManager* profile_manager = g_browser_process->profile_manager(); 301 ProfileManager* profile_manager = g_browser_process->profile_manager();
302 return profile_manager->GetLastUsedProfile(profile_manager->user_data_dir_); 302 return profile_manager->GetLastUsedProfile(profile_manager->user_data_dir_);
303 } 303 }
304 304
305 // static 305 // static
306 Profile* ProfileManager::GetLastUsedProfileAllowedByPolicy() { 306 Profile* ProfileManager::GetLastUsedProfileAllowedByPolicy() {
307 Profile* profile = GetLastUsedProfile(); 307 Profile* profile = GetLastUsedProfile();
308 if (profile->IsGuestSession() || 308 if (profile->IsGuestSession() ||
309 profile->IsSystemProfile() ||
309 IncognitoModePrefs::GetAvailability(profile->GetPrefs()) == 310 IncognitoModePrefs::GetAvailability(profile->GetPrefs()) ==
310 IncognitoModePrefs::FORCED) { 311 IncognitoModePrefs::FORCED) {
311 return profile->GetOffTheRecordProfile(); 312 return profile->GetOffTheRecordProfile();
312 } 313 }
313 return profile; 314 return profile;
314 } 315 }
315 316
316 // static 317 // static
317 std::vector<Profile*> ProfileManager::GetLastOpenedProfiles() { 318 std::vector<Profile*> ProfileManager::GetLastOpenedProfiles() {
318 ProfileManager* profile_manager = g_browser_process->profile_manager(); 319 ProfileManager* profile_manager = g_browser_process->profile_manager();
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 } 433 }
433 434
434 ProfileMetrics::UpdateReportedProfilesStatistics(this); 435 ProfileMetrics::UpdateReportedProfilesStatistics(this);
435 } 436 }
436 437
437 // Call or enqueue the callback. 438 // Call or enqueue the callback.
438 if (!callback.is_null()) { 439 if (!callback.is_null()) {
439 if (iter != profiles_info_.end() && info->created) { 440 if (iter != profiles_info_.end() && info->created) {
440 Profile* profile = info->profile.get(); 441 Profile* profile = info->profile.get();
441 // If this was the guest profile, apply settings and go OffTheRecord. 442 // If this was the guest profile, apply settings and go OffTheRecord.
442 if (profile->GetPath() == ProfileManager::GetGuestProfilePath()) { 443 // The system profile also needs characteristics of being off the record,
443 SetGuestProfilePrefs(profile); 444 // such as having no extensions, not writing to disk, etc.
445 if (profile->IsGuestSession() || profile->IsSystemProfile()) {
446 SetNonPersonalProfilePrefs(profile);
444 profile = profile->GetOffTheRecordProfile(); 447 profile = profile->GetOffTheRecordProfile();
445 } 448 }
446 // Profile has already been created. Run callback immediately. 449 // Profile has already been created. Run callback immediately.
447 callback.Run(profile, Profile::CREATE_STATUS_INITIALIZED); 450 callback.Run(profile, Profile::CREATE_STATUS_INITIALIZED);
448 } else { 451 } else {
449 // Profile is either already in the process of being created, or new. 452 // Profile is either already in the process of being created, or new.
450 // Add callback to the list. 453 // Add callback to the list.
451 info->callbacks.push_back(callback); 454 info->callbacks.push_back(callback);
452 } 455 }
453 } 456 }
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 info->created = true; 1000 info->created = true;
998 } else { 1001 } else {
999 profile = NULL; 1002 profile = NULL;
1000 profiles_info_.erase(iter); 1003 profiles_info_.erase(iter);
1001 // TODO(yiyaoliu): This is temporary, remove it after it's not used. 1004 // TODO(yiyaoliu): This is temporary, remove it after it's not used.
1002 UMA_HISTOGRAM_COUNTS_100("UMA.ProfilesCount.AfterErase", 1005 UMA_HISTOGRAM_COUNTS_100("UMA.ProfilesCount.AfterErase",
1003 profiles_info_.size()); 1006 profiles_info_.size());
1004 } 1007 }
1005 1008
1006 if (profile) { 1009 if (profile) {
1007 // If this was the guest profile, finish setting its special status. 1010 // If this was the guest or system profile, finish setting its special
1008 if (profile->GetPath() == ProfileManager::GetGuestProfilePath()) 1011 // status.
1009 SetGuestProfilePrefs(profile); 1012 if (profile->IsGuestSession() || profile->IsSystemProfile())
1013 SetNonPersonalProfilePrefs(profile);
1010 1014
1011 // Invoke CREATED callback for incognito profiles. 1015 // Invoke CREATED callback for incognito profiles.
1012 if (go_off_the_record) 1016 if (go_off_the_record)
1013 RunCallbacks(callbacks, profile, Profile::CREATE_STATUS_CREATED); 1017 RunCallbacks(callbacks, profile, Profile::CREATE_STATUS_CREATED);
1014 } 1018 }
1015 1019
1016 // Invoke INITIALIZED or FAIL for all profiles. 1020 // Invoke INITIALIZED or FAIL for all profiles.
1017 RunCallbacks(callbacks, profile, 1021 RunCallbacks(callbacks, profile,
1018 profile ? Profile::CREATE_STATUS_INITIALIZED : 1022 profile ? Profile::CREATE_STATUS_INITIALIZED :
1019 Profile::CREATE_STATUS_LOCAL_FAIL); 1023 Profile::CREATE_STATUS_LOCAL_FAIL);
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
1319 username, 1323 username,
1320 icon_index, 1324 icon_index,
1321 supervised_user_id); 1325 supervised_user_id);
1322 1326
1323 if (profile->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) { 1327 if (profile->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) {
1324 cache.SetProfileIsEphemeralAtIndex( 1328 cache.SetProfileIsEphemeralAtIndex(
1325 cache.GetIndexOfProfileWithPath(profile->GetPath()), true); 1329 cache.GetIndexOfProfileWithPath(profile->GetPath()), true);
1326 } 1330 }
1327 } 1331 }
1328 1332
1329 void ProfileManager::SetGuestProfilePrefs(Profile* profile) { 1333 void ProfileManager::SetNonPersonalProfilePrefs(Profile* profile) {
1330 PrefService* prefs = profile->GetPrefs(); 1334 PrefService* prefs = profile->GetPrefs();
1331 prefs->SetBoolean(prefs::kSigninAllowed, false); 1335 prefs->SetBoolean(prefs::kSigninAllowed, false);
1332 prefs->SetBoolean(bookmarks::prefs::kEditBookmarksEnabled, false); 1336 prefs->SetBoolean(bookmarks::prefs::kEditBookmarksEnabled, false);
1333 prefs->SetBoolean(bookmarks::prefs::kShowBookmarkBar, false); 1337 prefs->SetBoolean(bookmarks::prefs::kShowBookmarkBar, false);
1334 prefs->ClearPref(DefaultSearchManager::kDefaultSearchProviderDataPrefName); 1338 prefs->ClearPref(DefaultSearchManager::kDefaultSearchProviderDataPrefName);
1335 // This can be removed in the future but needs to be present through
1336 // a release (or two) so that any existing installs get switched to
1337 // the new state and away from the previous "forced" state.
1338 IncognitoModePrefs::SetAvailability(prefs, IncognitoModePrefs::ENABLED);
1339 } 1339 }
1340 1340
1341 bool ProfileManager::ShouldGoOffTheRecord(Profile* profile) { 1341 bool ProfileManager::ShouldGoOffTheRecord(Profile* profile) {
1342 #if defined(OS_CHROMEOS) 1342 #if defined(OS_CHROMEOS)
1343 if (profile->GetPath().BaseName().value() == chrome::kInitialProfile) { 1343 if (profile->GetPath().BaseName().value() == chrome::kInitialProfile) {
1344 return true; 1344 return true;
1345 } 1345 }
1346 #endif 1346 #endif
1347 return profile->IsGuestSession(); 1347 return profile->IsGuestSession() || profile->IsSystemProfile();
1348 } 1348 }
1349 1349
1350 void ProfileManager::RunCallbacks(const std::vector<CreateCallback>& callbacks, 1350 void ProfileManager::RunCallbacks(const std::vector<CreateCallback>& callbacks,
1351 Profile* profile, 1351 Profile* profile,
1352 Profile::CreateStatus status) { 1352 Profile::CreateStatus status) {
1353 for (size_t i = 0; i < callbacks.size(); ++i) 1353 for (size_t i = 0; i < callbacks.size(); ++i)
1354 callbacks[i].Run(profile, status); 1354 callbacks[i].Run(profile, status);
1355 } 1355 }
1356 1356
1357 ProfileManager::ProfileInfo::ProfileInfo( 1357 ProfileManager::ProfileInfo::ProfileInfo(
1358 Profile* profile, 1358 Profile* profile,
1359 bool created) 1359 bool created)
1360 : profile(profile), 1360 : profile(profile),
1361 created(created) { 1361 created(created) {
1362 } 1362 }
1363 1363
1364 ProfileManager::ProfileInfo::~ProfileInfo() { 1364 ProfileManager::ProfileInfo::~ProfileInfo() {
1365 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); 1365 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release());
1366 } 1366 }
1367 1367
1368 #if !defined(OS_ANDROID) && !defined(OS_IOS) 1368 #if !defined(OS_ANDROID) && !defined(OS_IOS)
1369 void ProfileManager::UpdateLastUser(Profile* last_active) { 1369 void ProfileManager::UpdateLastUser(Profile* last_active) {
1370 PrefService* local_state = g_browser_process->local_state(); 1370 PrefService* local_state = g_browser_process->local_state();
1371 DCHECK(local_state); 1371 DCHECK(local_state);
1372 // Only keep track of profiles that we are managing; tests may create others. 1372 // Only keep track of profiles that we are managing; tests may create others.
1373 if (profiles_info_.find(last_active->GetPath()) != profiles_info_.end()) { 1373 // Also never consider the SystemProfile as "active".
1374 if (profiles_info_.find(last_active->GetPath()) != profiles_info_.end() &&
1375 !last_active->IsSystemProfile()) {
1374 std::string profile_path_base = 1376 std::string profile_path_base =
1375 last_active->GetPath().BaseName().MaybeAsASCII(); 1377 last_active->GetPath().BaseName().MaybeAsASCII();
1376 if (profile_path_base != GetLastUsedProfileName()) 1378 if (profile_path_base != GetLastUsedProfileName())
1377 local_state->SetString(prefs::kProfileLastUsed, profile_path_base); 1379 local_state->SetString(prefs::kProfileLastUsed, profile_path_base);
1378 1380
1379 ProfileInfoCache& cache = GetProfileInfoCache(); 1381 ProfileInfoCache& cache = GetProfileInfoCache();
1380 size_t profile_index = 1382 size_t profile_index =
1381 cache.GetIndexOfProfileWithPath(last_active->GetPath()); 1383 cache.GetIndexOfProfileWithPath(last_active->GetPath());
1382 if (profile_index != std::string::npos) { 1384 if (profile_index != std::string::npos) {
1383 #if !defined(OS_CHROMEOS) 1385 #if !defined(OS_CHROMEOS)
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1467 } 1469 }
1468 1470
1469 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path); 1471 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path);
1470 if (!original_callback.is_null()) 1472 if (!original_callback.is_null())
1471 original_callback.Run(loaded_profile, status); 1473 original_callback.Run(loaded_profile, status);
1472 } 1474 }
1473 1475
1474 ProfileManagerWithoutInit::ProfileManagerWithoutInit( 1476 ProfileManagerWithoutInit::ProfileManagerWithoutInit(
1475 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { 1477 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) {
1476 } 1478 }
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