| OLD | NEW |
| 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/test/base/testing_profile_manager.h" | 5 #include "chrome/test/base/testing_profile_manager.h" |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/prefs/pref_service_syncable.h" | 9 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 10 #include "chrome/browser/profiles/profile_info_cache.h" | 10 #include "chrome/browser/profiles/profile_info_cache.h" |
| 11 #include "chrome/browser/profiles/profile_manager.h" | 11 #include "chrome/browser/profiles/profile_manager.h" |
| 12 #include "chrome/common/chrome_constants.h" | 12 #include "chrome/common/chrome_constants.h" |
| 13 #include "chrome/test/base/testing_browser_process.h" | 13 #include "chrome/test/base/testing_browser_process.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 #if defined(OS_CHROMEOS) | 16 #if defined(OS_CHROMEOS) |
| 17 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 17 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 18 #endif | 18 #endif |
| 19 | 19 |
| 20 const char kGuestProfileName[] = "Guest"; | 20 const char kGuestProfileName[] = "Guest"; |
| 21 const char kSystemProfileName[] = "System"; |
| 21 | 22 |
| 22 namespace testing { | 23 namespace testing { |
| 23 | 24 |
| 24 class ProfileManager : public ::ProfileManagerWithoutInit { | 25 class ProfileManager : public ::ProfileManagerWithoutInit { |
| 25 public: | 26 public: |
| 26 explicit ProfileManager(const base::FilePath& user_data_dir) | 27 explicit ProfileManager(const base::FilePath& user_data_dir) |
| 27 : ::ProfileManagerWithoutInit(user_data_dir) {} | 28 : ::ProfileManagerWithoutInit(user_data_dir) {} |
| 28 | 29 |
| 29 protected: | 30 protected: |
| 30 Profile* CreateProfileHelper(const base::FilePath& file_path) override { | 31 Profile* CreateProfileHelper(const base::FilePath& file_path) override { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 TestingProfile::Builder().BuildIncognito(profile); | 130 TestingProfile::Builder().BuildIncognito(profile); |
| 130 | 131 |
| 131 profile_manager_->AddProfile(profile); // Takes ownership. | 132 profile_manager_->AddProfile(profile); // Takes ownership. |
| 132 profile_manager_->SetGuestProfilePrefs(profile); | 133 profile_manager_->SetGuestProfilePrefs(profile); |
| 133 | 134 |
| 134 testing_profiles_.insert(std::make_pair(kGuestProfileName, profile)); | 135 testing_profiles_.insert(std::make_pair(kGuestProfileName, profile)); |
| 135 | 136 |
| 136 return profile; | 137 return profile; |
| 137 } | 138 } |
| 138 | 139 |
| 140 TestingProfile* TestingProfileManager::CreateSystemProfile() { |
| 141 DCHECK(called_set_up_); |
| 142 |
| 143 // Create the profile and register it. |
| 144 TestingProfile::Builder builder; |
| 145 builder.SetPath(ProfileManager::GetSystemProfilePath()); |
| 146 |
| 147 // Add the guest profile to the profile manager, but not to the info cache. |
| 148 TestingProfile* profile = builder.Build().release(); |
| 149 profile->set_profile_name(kSystemProfileName); |
| 150 |
| 151 profile_manager_->AddProfile(profile); // Takes ownership. |
| 152 |
| 153 testing_profiles_.insert(std::make_pair(kSystemProfileName, profile)); |
| 154 |
| 155 return profile; |
| 156 } |
| 157 |
| 139 void TestingProfileManager::DeleteTestingProfile(const std::string& name) { | 158 void TestingProfileManager::DeleteTestingProfile(const std::string& name) { |
| 140 DCHECK(called_set_up_); | 159 DCHECK(called_set_up_); |
| 141 | 160 |
| 142 TestingProfilesMap::iterator it = testing_profiles_.find(name); | 161 TestingProfilesMap::iterator it = testing_profiles_.find(name); |
| 143 DCHECK(it != testing_profiles_.end()); | 162 DCHECK(it != testing_profiles_.end()); |
| 144 | 163 |
| 145 TestingProfile* profile = it->second; | 164 TestingProfile* profile = it->second; |
| 146 | 165 |
| 147 ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); | 166 ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); |
| 148 cache.DeleteProfileFromCache(profile->GetPath()); | 167 cache.DeleteProfileFromCache(profile->GetPath()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 163 | 182 |
| 164 void TestingProfileManager::DeleteGuestProfile() { | 183 void TestingProfileManager::DeleteGuestProfile() { |
| 165 DCHECK(called_set_up_); | 184 DCHECK(called_set_up_); |
| 166 | 185 |
| 167 TestingProfilesMap::iterator it = testing_profiles_.find(kGuestProfileName); | 186 TestingProfilesMap::iterator it = testing_profiles_.find(kGuestProfileName); |
| 168 DCHECK(it != testing_profiles_.end()); | 187 DCHECK(it != testing_profiles_.end()); |
| 169 | 188 |
| 170 profile_manager_->profiles_info_.erase(ProfileManager::GetGuestProfilePath()); | 189 profile_manager_->profiles_info_.erase(ProfileManager::GetGuestProfilePath()); |
| 171 } | 190 } |
| 172 | 191 |
| 192 void TestingProfileManager::DeleteSystemProfile() { |
| 193 DCHECK(called_set_up_); |
| 194 |
| 195 TestingProfilesMap::iterator it = testing_profiles_.find(kSystemProfileName); |
| 196 DCHECK(it != testing_profiles_.end()); |
| 197 |
| 198 profile_manager_->profiles_info_.erase( |
| 199 ProfileManager::GetSystemProfilePath()); |
| 200 } |
| 201 |
| 173 void TestingProfileManager::DeleteProfileInfoCache() { | 202 void TestingProfileManager::DeleteProfileInfoCache() { |
| 174 profile_manager_->profile_info_cache_.reset(NULL); | 203 profile_manager_->profile_info_cache_.reset(NULL); |
| 175 } | 204 } |
| 176 | 205 |
| 177 void TestingProfileManager::SetLoggedIn(bool logged_in) { | 206 void TestingProfileManager::SetLoggedIn(bool logged_in) { |
| 178 profile_manager_->logged_in_ = logged_in; | 207 profile_manager_->logged_in_ = logged_in; |
| 179 } | 208 } |
| 180 | 209 |
| 181 void TestingProfileManager::UpdateLastUser(Profile* last_active) { | 210 void TestingProfileManager::UpdateLastUser(Profile* last_active) { |
| 182 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 211 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 204 << "ProfileManager already exists"; | 233 << "ProfileManager already exists"; |
| 205 | 234 |
| 206 // Set up the directory for profiles. | 235 // Set up the directory for profiles. |
| 207 ASSERT_TRUE(profiles_dir_.CreateUniqueTempDir()); | 236 ASSERT_TRUE(profiles_dir_.CreateUniqueTempDir()); |
| 208 | 237 |
| 209 profile_manager_ = new testing::ProfileManager(profiles_dir_.path()); | 238 profile_manager_ = new testing::ProfileManager(profiles_dir_.path()); |
| 210 browser_process_->SetProfileManager(profile_manager_); // Takes ownership. | 239 browser_process_->SetProfileManager(profile_manager_); // Takes ownership. |
| 211 | 240 |
| 212 called_set_up_ = true; | 241 called_set_up_ = true; |
| 213 } | 242 } |
| OLD | NEW |