diff options
author | rlp@chromium.org <rlp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-12 23:38:03 +0000 |
---|---|---|
committer | rlp@chromium.org <rlp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-12 23:38:03 +0000 |
commit | 27917083687c4398f21234ed51ee69e6863ed82a (patch) | |
tree | 507384f8eeb0ef50ff73faeb4e8af84069f5c72d /chrome/browser/profiles | |
parent | bdc1b48740f319838da527e4a57e4ba454bfdfc4 (diff) | |
download | chromium_src-27917083687c4398f21234ed51ee69e6863ed82a.zip chromium_src-27917083687c4398f21234ed51ee69e6863ed82a.tar.gz chromium_src-27917083687c4398f21234ed51ee69e6863ed82a.tar.bz2 |
Autoload any profiles with background applications running.
BUG=91560
TEST=added ProfileManagerTest.AutoloadProfilesWithBackgroundApps
Review URL: http://codereview.chromium.org/8080011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105191 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/profiles')
-rw-r--r-- | chrome/browser/profiles/profile_info_cache.cc | 22 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_info_cache.h | 4 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_info_cache_unittest.cc | 27 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_info_interface.h | 5 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_manager.cc | 13 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_manager.h | 3 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_manager_unittest.cc | 26 |
7 files changed, 98 insertions, 2 deletions
diff --git a/chrome/browser/profiles/profile_info_cache.cc b/chrome/browser/profiles/profile_info_cache.cc index fcf9f00..96a17e1 100644 --- a/chrome/browser/profiles/profile_info_cache.cc +++ b/chrome/browser/profiles/profile_info_cache.cc @@ -27,6 +27,7 @@ namespace { const char kNameKey[] = "name"; const char kUserNameKey[] = "user_name"; const char kAvatarIconKey[] = "avatar_icon"; +const char kBackgroundAppsKey[] = "background_apps"; const char kDefaultUrlPrefix[] = "chrome://theme/IDR_PROFILE_AVATAR_"; const int kDefaultAvatarIconResources[] = { @@ -98,6 +99,8 @@ void ProfileInfoCache::AddProfileToCache(const FilePath& profile_path, info->SetString(kNameKey, name); info->SetString(kUserNameKey, username); info->SetString(kAvatarIconKey, GetDefaultAvatarIconUrl(icon_index)); + // Default value for whether background apps are running is false. + info->SetBoolean(kBackgroundAppsKey, false); cache->Set(key, info.release()); sorted_keys_.insert(FindPositionForProfile(key, name), key); @@ -167,6 +170,14 @@ const gfx::Image& ProfileInfoCache::GetAvatarIconOfProfileAtIndex( return ResourceBundle::GetSharedInstance().GetImageNamed(resource_id); } +bool ProfileInfoCache::GetBackgroundStatusOfProfileAtIndex( + size_t index) const { + bool background_app_status; + GetInfoForProfileAtIndex(index)->GetBoolean(kBackgroundAppsKey, + &background_app_status); + return background_app_status; +} + size_t ProfileInfoCache::GetAvatarIconIndexOfProfileAtIndex(size_t index) const { std::string icon_url; @@ -203,6 +214,17 @@ void ProfileInfoCache::SetAvatarIconOfProfileAtIndex(size_t index, SetInfoForProfileAtIndex(index, info.release()); } +void ProfileInfoCache::SetBackgroundStatusOfProfileAtIndex( + size_t index, + bool running_background_apps) { + if (GetBackgroundStatusOfProfileAtIndex(index) == running_background_apps) + return; + scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); + info->SetBoolean(kBackgroundAppsKey, running_background_apps); + // This takes ownership of |info|. + SetInfoForProfileAtIndex(index, info.release()); +} + string16 ProfileInfoCache::ChooseNameForNewProfile() { for (int name_index = 1; ; ++name_index) { string16 name = l10n_util::GetStringFUTF16Int( diff --git a/chrome/browser/profiles/profile_info_cache.h b/chrome/browser/profiles/profile_info_cache.h index b4fe501..f369ef0 100644 --- a/chrome/browser/profiles/profile_info_cache.h +++ b/chrome/browser/profiles/profile_info_cache.h @@ -49,12 +49,16 @@ class ProfileInfoCache : public ProfileInfoInterface { virtual string16 GetUserNameOfProfileAtIndex(size_t index) const OVERRIDE; virtual const gfx::Image& GetAvatarIconOfProfileAtIndex( size_t index) const OVERRIDE; + virtual bool GetBackgroundStatusOfProfileAtIndex( + size_t index) const OVERRIDE; size_t GetAvatarIconIndexOfProfileAtIndex(size_t index) const; void SetNameOfProfileAtIndex(size_t index, const string16& name); void SetUserNameOfProfileAtIndex(size_t index, const string16& user_name); void SetAvatarIconOfProfileAtIndex(size_t index, size_t icon_index); + void SetBackgroundStatusOfProfileAtIndex(size_t index, + bool running_background_apps); // Returns unique name that can be assigned to a newly created profile. string16 ChooseNameForNewProfile(); diff --git a/chrome/browser/profiles/profile_info_cache_unittest.cc b/chrome/browser/profiles/profile_info_cache_unittest.cc index 5fea20f..be03de0 100644 --- a/chrome/browser/profiles/profile_info_cache_unittest.cc +++ b/chrome/browser/profiles/profile_info_cache_unittest.cc @@ -114,4 +114,31 @@ TEST_F(ProfileInfoCacheUnittests, MutateProfile) { GetCache()->GetAvatarIconOfProfileAtIndex(1); } +TEST_F(ProfileInfoCacheUnittests, BackgroundModeStatus) { + GetCache()->AddProfileToCache( + GetUserDataDir().Append(StringToFilePath("path_1")), + ASCIIToUTF16("name_1"), string16(), 0); + GetCache()->AddProfileToCache( + GetUserDataDir().Append(StringToFilePath("path_2")), + ASCIIToUTF16("name_2"), string16(), 0); + + EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); + EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); + + GetCache()->SetBackgroundStatusOfProfileAtIndex(1, true); + + EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); + EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); + + GetCache()->SetBackgroundStatusOfProfileAtIndex(0, true); + + EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); + EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); + + GetCache()->SetBackgroundStatusOfProfileAtIndex(1, false); + + EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); + EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); +} + } // namespace diff --git a/chrome/browser/profiles/profile_info_interface.h b/chrome/browser/profiles/profile_info_interface.h index 9677be9..6a08f9a 100644 --- a/chrome/browser/profiles/profile_info_interface.h +++ b/chrome/browser/profiles/profile_info_interface.h @@ -31,6 +31,11 @@ class ProfileInfoInterface { virtual const gfx::Image& GetAvatarIconOfProfileAtIndex( size_t index) const = 0; + // Returns true if the profile at the given index is currently running any + // background apps. + virtual bool GetBackgroundStatusOfProfileAtIndex( + size_t index) const = 0; + protected: virtual ~ProfileInfoInterface() {} }; diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profiles/profile_manager.cc index a05ab60..bf88997c 100644 --- a/chrome/browser/profiles/profile_manager.cc +++ b/chrome/browser/profiles/profile_manager.cc @@ -545,6 +545,19 @@ bool ProfileManager::IsMultipleProfilesEnabled() { #endif } +void ProfileManager::AutoloadProfiles() { + ProfileInfoCache& cache = GetProfileInfoCache(); + size_t number_of_profiles = cache.GetNumberOfProfiles(); + for (size_t p = 0; p < number_of_profiles; ++p) { + if (cache.GetBackgroundStatusOfProfileAtIndex(p)) { + // If status is true, that profile is running background apps. By calling + // GetProfile, we automatically cause the profile to be loaded which will + // register it with the BackgroundModeManager. + GetProfile(cache.GetPathOfProfileAtIndex(p)); + } + } +} + ProfileManagerWithoutInit::ProfileManagerWithoutInit( const FilePath& user_data_dir) : ProfileManager(user_data_dir) { } diff --git a/chrome/browser/profiles/profile_manager.h b/chrome/browser/profiles/profile_manager.h index f894555..27347ab 100644 --- a/chrome/browser/profiles/profile_manager.h +++ b/chrome/browser/profiles/profile_manager.h @@ -180,6 +180,9 @@ class ProfileManager : public base::NonThreadSafe, // Checks if multiple profiles is enabled. static bool IsMultipleProfilesEnabled(); + // Autoloads profiles if they are running background apps. + void AutoloadProfiles(); + // Register and add testing profile to the ProfileManager. Use ONLY in tests. // This allows the creation of Profiles outside of the standard creation path // for testing. If |addToCache|, add to ProfileInfoCache as well. diff --git a/chrome/browser/profiles/profile_manager_unittest.cc b/chrome/browser/profiles/profile_manager_unittest.cc index 49a5a72..4e23a73 100644 --- a/chrome/browser/profiles/profile_manager_unittest.cc +++ b/chrome/browser/profiles/profile_manager_unittest.cc @@ -9,6 +9,7 @@ #include "base/path_service.h" #include "base/scoped_temp_dir.h" #include "base/system_monitor/system_monitor.h" +#include "base/utf_string_conversions.h" #include "base/values.h" #include "build/build_config.h" #include "chrome/browser/browser_process.h" @@ -16,6 +17,7 @@ #include "chrome/browser/io_thread.h" #include "chrome/browser/prefs/browser_prefs.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/profiles/profile_info_cache.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_notification_types.h" @@ -48,8 +50,8 @@ class ProfileManagerTest : public testing::Test { ui_thread_(BrowserThread::UI, &message_loop_), db_thread_(BrowserThread::DB, &message_loop_), file_thread_(BrowserThread::FILE, &message_loop_), - io_thread_(local_state_.Get(), NULL, extension_event_router_forwarder_), - profile_manager_(new ProfileManagerWithoutInit(temp_dir_.path())) { + io_thread_(local_state_.Get(), NULL, + extension_event_router_forwarder_) { #if defined(OS_MACOSX) base::SystemMonitor::AllocateSystemIOPorts(); #endif @@ -61,6 +63,7 @@ class ProfileManagerTest : public testing::Test { virtual void SetUp() { // Create a new temporary directory, and store the path ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); + profile_manager_.reset(new ProfileManagerWithoutInit(temp_dir_.path())); } virtual void TearDown() { @@ -242,3 +245,22 @@ TEST_F(ProfileManagerTest, CreateProfilesAsync) { message_loop_.RunAllPending(); } + +TEST_F(ProfileManagerTest, AutoloadProfilesWithBackgroundApps) { + ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); + + EXPECT_EQ(0u, cache.GetNumberOfProfiles()); + cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_1"), + ASCIIToUTF16("name_1"), string16(), 0); + cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_2"), + ASCIIToUTF16("name_2"), string16(), 0); + cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_3"), + ASCIIToUTF16("name_3"), string16(), 0); + cache.SetBackgroundStatusOfProfileAtIndex(0, true); + cache.SetBackgroundStatusOfProfileAtIndex(2, true); + EXPECT_EQ(3u, cache.GetNumberOfProfiles()); + + profile_manager_->AutoloadProfiles(); + + EXPECT_EQ(2u, profile_manager_->GetLoadedProfiles().size()); +} |