| 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_info_util.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 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 g_browser_process->local_state(), user_data_dir_)); | 593 g_browser_process->local_state(), user_data_dir_)); |
| 593 } | 594 } |
| 594 return *profile_info_cache_.get(); | 595 return *profile_info_cache_.get(); |
| 595 } | 596 } |
| 596 | 597 |
| 597 void ProfileManager::AddProfileToCache(Profile* profile) { | 598 void ProfileManager::AddProfileToCache(Profile* profile) { |
| 598 ProfileInfoCache& cache = GetProfileInfoCache(); | 599 ProfileInfoCache& cache = GetProfileInfoCache(); |
| 599 if (profile->GetPath().DirName() != cache.GetUserDataDir()) | 600 if (profile->GetPath().DirName() != cache.GetUserDataDir()) |
| 600 return; | 601 return; |
| 601 | 602 |
| 602 if (cache.GetIndexOfProfileWithPath(profile->GetPath()) != std::string::npos) | 603 ProfileInfoEntry entry; |
| 604 if (cache.GetInfoForProfile(profile->GetPath(), &entry)) { |
| 605 // The profile is already in the cache, nothing to do. |
| 603 return; | 606 return; |
| 607 } |
| 604 | 608 |
| 605 string16 username = UTF8ToUTF16(profile->GetPrefs()->GetString( | 609 entry.set_path(profile->GetPath()); |
| 606 prefs::kGoogleServicesUsername)); | 610 entry.set_user_name(UTF8ToUTF16(profile->GetPrefs()->GetString( |
| 611 prefs::kGoogleServicesUsername))); |
| 607 | 612 |
| 608 if (profile->GetPath() == GetDefaultProfileDir(cache.GetUserDataDir())) { | 613 if (profile->GetPath() == GetDefaultProfileDir(cache.GetUserDataDir())) { |
| 609 cache.AddProfileToCache( | 614 entry.set_name(l10n_util::GetStringUTF16(IDS_DEFAULT_PROFILE_NAME)); |
| 610 profile->GetPath(), | 615 entry.set_icon_index(0); |
| 611 l10n_util::GetStringUTF16(IDS_DEFAULT_PROFILE_NAME), username, 0); | |
| 612 } else { | 616 } else { |
| 613 size_t icon_index = cache.ChooseAvatarIconIndexForNewProfile(); | 617 const std::vector<ProfileInfoEntry>& entries = |
| 614 cache.AddProfileToCache(profile->GetPath(), | 618 cache.GetProfilesSortedByName(); |
| 615 cache.ChooseNameForNewProfile(icon_index), | 619 entry.set_icon_index(profiles::ChooseAvatarIconIndexForNewProfile(entries)); |
| 616 username, | 620 entry.set_name( |
| 617 icon_index); | 621 profiles::ChooseNameForNewProfile(entries, entry.icon_index())); |
| 618 } | 622 } |
| 623 |
| 624 cache.SetInfoForProfile(entry); |
| 619 } | 625 } |
| 620 | 626 |
| 621 bool ProfileManager::ShouldGoOffTheRecord() { | 627 bool ProfileManager::ShouldGoOffTheRecord() { |
| 622 bool go_off_the_record = false; | 628 bool go_off_the_record = false; |
| 623 #if defined(OS_CHROMEOS) | 629 #if defined(OS_CHROMEOS) |
| 624 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 630 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 625 if (!logged_in_ && | 631 if (!logged_in_ && |
| 626 (!command_line.HasSwitch(switches::kTestType) || | 632 (!command_line.HasSwitch(switches::kTestType) || |
| 627 command_line.HasSwitch(switches::kLoginProfile))) { | 633 command_line.HasSwitch(switches::kLoginProfile))) { |
| 628 go_off_the_record = true; | 634 go_off_the_record = true; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 656 bool ProfileManager::IsMultipleProfilesEnabled() { | 662 bool ProfileManager::IsMultipleProfilesEnabled() { |
| 657 #if defined(OS_CHROMEOS) | 663 #if defined(OS_CHROMEOS) |
| 658 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles); | 664 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles); |
| 659 #else | 665 #else |
| 660 return true; | 666 return true; |
| 661 #endif | 667 #endif |
| 662 } | 668 } |
| 663 | 669 |
| 664 void ProfileManager::AutoloadProfiles() { | 670 void ProfileManager::AutoloadProfiles() { |
| 665 ProfileInfoCache& cache = GetProfileInfoCache(); | 671 ProfileInfoCache& cache = GetProfileInfoCache(); |
| 666 size_t number_of_profiles = cache.GetNumberOfProfiles(); | 672 const std::vector<ProfileInfoEntry> entries(cache.GetProfilesSortedByName()); |
| 667 for (size_t p = 0; p < number_of_profiles; ++p) { | 673 for (std::vector<ProfileInfoEntry>::const_iterator it = entries.begin(); |
| 668 if (cache.GetBackgroundStatusOfProfileAtIndex(p)) { | 674 it != entries.end(); ++it) { |
| 675 if (it->is_running_background_apps()) { |
| 669 // If status is true, that profile is running background apps. By calling | 676 // If status is true, that profile is running background apps. By calling |
| 670 // GetProfile, we automatically cause the profile to be loaded which will | 677 // GetProfile, we automatically cause the profile to be loaded which will |
| 671 // register it with the BackgroundModeManager. | 678 // register it with the BackgroundModeManager. |
| 672 GetProfile(cache.GetPathOfProfileAtIndex(p)); | 679 GetProfile(it->path()); |
| 673 } | 680 } |
| 674 } | 681 } |
| 675 } | 682 } |
| 676 | 683 |
| 677 ProfileManagerWithoutInit::ProfileManagerWithoutInit( | 684 ProfileManagerWithoutInit::ProfileManagerWithoutInit( |
| 678 const FilePath& user_data_dir) : ProfileManager(user_data_dir) { | 685 const FilePath& user_data_dir) : ProfileManager(user_data_dir) { |
| 679 } | 686 } |
| 680 | 687 |
| 681 void ProfileManager::RegisterTestingProfile(Profile* profile, | 688 void ProfileManager::RegisterTestingProfile(Profile* profile, |
| 682 bool add_to_cache) { | 689 bool add_to_cache) { |
| 683 RegisterProfile(profile, true); | 690 RegisterProfile(profile, true); |
| 684 if (add_to_cache) | 691 if (add_to_cache) |
| 685 AddProfileToCache(profile); | 692 AddProfileToCache(profile); |
| 686 } | 693 } |
| OLD | NEW |