Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <set> | 5 #include <set> |
| 6 | 6 |
| 7 #include "chrome/browser/profiles/profile_manager.h" | 7 #include "chrome/browser/profiles/profile_manager.h" |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 18 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/extensions/default_apps_trial.h" | 19 #include "chrome/browser/extensions/default_apps_trial.h" |
| 20 #include "chrome/browser/extensions/extension_service.h" | 20 #include "chrome/browser/extensions/extension_service.h" |
| 21 #include "chrome/browser/prefs/pref_service.h" | 21 #include "chrome/browser/prefs/pref_service.h" |
| 22 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 22 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 23 #include "chrome/browser/profiles/profile_info_cache.h" | 23 #include "chrome/browser/profiles/profile_info_cache.h" |
| 24 #include "chrome/browser/profiles/profile_metrics.h" | |
| 24 #include "chrome/browser/sessions/session_service_factory.h" | 25 #include "chrome/browser/sessions/session_service_factory.h" |
| 25 #include "chrome/browser/sync/profile_sync_service.h" | 26 #include "chrome/browser/sync/profile_sync_service.h" |
| 26 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
| 27 #include "chrome/browser/ui/browser_window.h" | 28 #include "chrome/browser/ui/browser_window.h" |
| 28 #include "chrome/browser/ui/webui/sync_promo_ui.h" | 29 #include "chrome/browser/ui/webui/sync_promo_ui.h" |
| 29 #include "chrome/common/chrome_constants.h" | 30 #include "chrome/common/chrome_constants.h" |
| 30 #include "chrome/common/chrome_notification_types.h" | 31 #include "chrome/common/chrome_notification_types.h" |
| 31 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
| 32 #include "chrome/common/logging_chrome.h" | 33 #include "chrome/common/logging_chrome.h" |
| 33 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 379 // that's already loaded. | 380 // that's already loaded. |
| 380 if (GetProfileByPath(profile->GetPath())) { | 381 if (GetProfileByPath(profile->GetPath())) { |
| 381 NOTREACHED() << "Attempted to add profile with the same path (" << | 382 NOTREACHED() << "Attempted to add profile with the same path (" << |
| 382 profile->GetPath().value() << | 383 profile->GetPath().value() << |
| 383 ") as an already-loaded profile."; | 384 ") as an already-loaded profile."; |
| 384 return false; | 385 return false; |
| 385 } | 386 } |
| 386 | 387 |
| 387 RegisterProfile(profile, true); | 388 RegisterProfile(profile, true); |
| 388 DoFinalInit(profile, ShouldGoOffTheRecord()); | 389 DoFinalInit(profile, ShouldGoOffTheRecord()); |
| 390 ProfileMetrics::LogNumberOfProfiles(false); | |
|
Ilya Sherman
2011/12/09 00:53:41
nit: Rather than using a bool, I think the style g
rpetterson
2011/12/09 01:44:35
Done.
| |
| 389 return true; | 391 return true; |
| 390 } | 392 } |
| 391 | 393 |
| 392 ProfileManager::ProfileInfo* ProfileManager::RegisterProfile(Profile* profile, | 394 ProfileManager::ProfileInfo* ProfileManager::RegisterProfile(Profile* profile, |
| 393 bool created) { | 395 bool created) { |
| 394 ProfileInfo* info = new ProfileInfo(profile, created); | 396 ProfileInfo* info = new ProfileInfo(profile, created); |
| 395 profiles_info_.insert(std::make_pair(profile->GetPath(), info)); | 397 profiles_info_.insert(std::make_pair(profile->GetPath(), info)); |
| 396 return info; | 398 return info; |
| 397 } | 399 } |
| 398 | 400 |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 679 if (profile) { | 681 if (profile) { |
| 680 BrowserList::CloseAllBrowsersWithProfile(profile); | 682 BrowserList::CloseAllBrowsersWithProfile(profile); |
| 681 | 683 |
| 682 // Disable sync for doomed profile. | 684 // Disable sync for doomed profile. |
| 683 if (profile->HasProfileSyncService()) | 685 if (profile->HasProfileSyncService()) |
| 684 profile->GetProfileSyncService()->DisableForUser(); | 686 profile->GetProfileSyncService()->DisableForUser(); |
| 685 } | 687 } |
| 686 | 688 |
| 687 QueueProfileDirectoryForDeletion(profile_dir); | 689 QueueProfileDirectoryForDeletion(profile_dir); |
| 688 cache.DeleteProfileFromCache(profile_dir); | 690 cache.DeleteProfileFromCache(profile_dir); |
| 691 | |
| 692 ProfileMetrics::LogNumberOfProfiles(false); | |
| 689 } | 693 } |
| 690 | 694 |
| 691 // static | 695 // static |
| 692 bool ProfileManager::IsMultipleProfilesEnabled() { | 696 bool ProfileManager::IsMultipleProfilesEnabled() { |
| 693 #if defined(OS_CHROMEOS) | 697 #if defined(OS_CHROMEOS) |
| 694 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles); | 698 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles); |
| 695 #else | 699 #else |
| 696 return true; | 700 return true; |
| 697 #endif | 701 #endif |
| 698 } | 702 } |
| 699 | 703 |
| 700 void ProfileManager::AutoloadProfiles() { | 704 void ProfileManager::AutoloadProfiles() { |
| 701 ProfileInfoCache& cache = GetProfileInfoCache(); | 705 ProfileInfoCache& cache = GetProfileInfoCache(); |
| 702 size_t number_of_profiles = cache.GetNumberOfProfiles(); | 706 size_t number_of_profiles = cache.GetNumberOfProfiles(); |
| 703 for (size_t p = 0; p < number_of_profiles; ++p) { | 707 for (size_t p = 0; p < number_of_profiles; ++p) { |
| 704 if (cache.GetBackgroundStatusOfProfileAtIndex(p)) { | 708 if (cache.GetBackgroundStatusOfProfileAtIndex(p)) { |
| 705 // If status is true, that profile is running background apps. By calling | 709 // If status is true, that profile is running background apps. By calling |
| 706 // GetProfile, we automatically cause the profile to be loaded which will | 710 // GetProfile, we automatically cause the profile to be loaded which will |
| 707 // register it with the BackgroundModeManager. | 711 // register it with the BackgroundModeManager. |
| 708 GetProfile(cache.GetPathOfProfileAtIndex(p)); | 712 GetProfile(cache.GetPathOfProfileAtIndex(p)); |
| 709 } | 713 } |
| 710 } | 714 } |
| 715 ProfileMetrics::LogNumberOfProfiles(true); | |
| 711 } | 716 } |
| 712 | 717 |
| 713 ProfileManagerWithoutInit::ProfileManagerWithoutInit( | 718 ProfileManagerWithoutInit::ProfileManagerWithoutInit( |
| 714 const FilePath& user_data_dir) : ProfileManager(user_data_dir) { | 719 const FilePath& user_data_dir) : ProfileManager(user_data_dir) { |
| 715 } | 720 } |
| 716 | 721 |
| 717 void ProfileManager::RegisterTestingProfile(Profile* profile, | 722 void ProfileManager::RegisterTestingProfile(Profile* profile, |
| 718 bool add_to_cache) { | 723 bool add_to_cache) { |
| 719 RegisterProfile(profile, true); | 724 RegisterProfile(profile, true); |
| 720 if (add_to_cache) | 725 if (add_to_cache) |
| 721 AddProfileToCache(profile); | 726 AddProfileToCache(profile); |
| 722 } | 727 } |
| 723 | 728 |
| 724 #if defined(OS_WIN) | 729 #if defined(OS_WIN) |
| 725 void ProfileManager::RemoveProfileShortcutManagerForTesting() { | 730 void ProfileManager::RemoveProfileShortcutManagerForTesting() { |
| 726 profile_info_cache_->RemoveObserver(profile_shortcut_manager_.get()); | 731 profile_info_cache_->RemoveObserver(profile_shortcut_manager_.get()); |
| 727 } | 732 } |
| 728 #endif | 733 #endif |
| OLD | NEW |