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/extensions/extension_special_storage_policy.h" | 9 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
10 #include "chrome/browser/prefs/pref_service_syncable.h" | 10 #include "chrome/browser/prefs/pref_service_syncable.h" |
11 #include "chrome/browser/profiles/profile_info_cache.h" | 11 #include "chrome/browser/profiles/profile_info_cache.h" |
12 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.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 const std::string kGuestProfileName = "Guest"; | 16 const std::string kGuestProfileName = "Guest"; |
| 17 const std::string kUserManagerProfileName = "UserManager"; |
17 | 18 |
18 namespace testing { | 19 namespace testing { |
19 | 20 |
20 class ProfileManager : public ::ProfileManagerWithoutInit { | 21 class ProfileManager : public ::ProfileManagerWithoutInit { |
21 public: | 22 public: |
22 explicit ProfileManager(const base::FilePath& user_data_dir) | 23 explicit ProfileManager(const base::FilePath& user_data_dir) |
23 : ::ProfileManagerWithoutInit(user_data_dir) {} | 24 : ::ProfileManagerWithoutInit(user_data_dir) {} |
24 | 25 |
25 protected: | 26 protected: |
26 virtual Profile* CreateProfileHelper( | 27 virtual Profile* CreateProfileHelper( |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 otr_profile->SetOriginalProfile(profile); | 119 otr_profile->SetOriginalProfile(profile); |
119 profile->SetOffTheRecordProfile(otr_profile.PassAs<Profile>()); | 120 profile->SetOffTheRecordProfile(otr_profile.PassAs<Profile>()); |
120 profile_manager_->AddProfile(profile); // Takes ownership. | 121 profile_manager_->AddProfile(profile); // Takes ownership. |
121 profile_manager_->SetGuestProfilePrefs(profile); | 122 profile_manager_->SetGuestProfilePrefs(profile); |
122 | 123 |
123 testing_profiles_.insert(std::make_pair(kGuestProfileName, profile)); | 124 testing_profiles_.insert(std::make_pair(kGuestProfileName, profile)); |
124 | 125 |
125 return profile; | 126 return profile; |
126 } | 127 } |
127 | 128 |
| 129 TestingProfile* TestingProfileManager::CreateUserManagerProfile() { |
| 130 DCHECK(called_set_up_); |
| 131 |
| 132 // Create the profile and register it. |
| 133 TestingProfile::Builder builder; |
| 134 builder.SetGuestSession(); |
| 135 builder.SetPath(ProfileManager::GetUserManagerProfilePath()); |
| 136 |
| 137 // Add the profile to the profile manager, but not to the info cache. |
| 138 TestingProfile* profile = builder.Build().release(); |
| 139 profile->set_profile_name(kUserManagerProfileName); |
| 140 profile_manager_->AddProfile(profile); // Takes ownership. |
| 141 testing_profiles_.insert(std::make_pair(kUserManagerProfileName, profile)); |
| 142 |
| 143 return profile; |
| 144 } |
| 145 |
128 void TestingProfileManager::DeleteTestingProfile(const std::string& name) { | 146 void TestingProfileManager::DeleteTestingProfile(const std::string& name) { |
129 DCHECK(called_set_up_); | 147 DCHECK(called_set_up_); |
130 | 148 |
131 TestingProfilesMap::iterator it = testing_profiles_.find(name); | 149 TestingProfilesMap::iterator it = testing_profiles_.find(name); |
132 DCHECK(it != testing_profiles_.end()); | 150 DCHECK(it != testing_profiles_.end()); |
133 | |
134 TestingProfile* profile = it->second; | 151 TestingProfile* profile = it->second; |
135 | 152 |
136 ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); | 153 DeleteProfileWithPath(profile->GetPath()); |
137 cache.DeleteProfileFromCache(profile->GetPath()); | |
138 | |
139 profile_manager_->profiles_info_.erase(profile->GetPath()); | |
140 } | 154 } |
141 | 155 |
142 void TestingProfileManager::DeleteGuestProfile() { | 156 void TestingProfileManager::DeleteProfileWithPath(const base::FilePath& path) { |
143 DCHECK(called_set_up_); | 157 DCHECK(called_set_up_); |
144 | 158 |
145 TestingProfilesMap::iterator it = testing_profiles_.find(kGuestProfileName); | 159 ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); |
146 DCHECK(it != testing_profiles_.end()); | 160 if (cache.GetIndexOfProfileWithPath(path) != std::string::npos) { |
| 161 cache.DeleteProfileFromCache(path); |
| 162 } |
147 | 163 |
148 profile_manager_->profiles_info_.erase(ProfileManager::GetGuestProfilePath()); | 164 profile_manager_->profiles_info_.erase(path); |
149 } | 165 } |
150 | 166 |
151 void TestingProfileManager::DeleteProfileInfoCache() { | 167 void TestingProfileManager::DeleteProfileInfoCache() { |
152 profile_manager_->profile_info_cache_.reset(NULL); | 168 profile_manager_->profile_info_cache_.reset(NULL); |
153 } | 169 } |
154 | 170 |
155 void TestingProfileManager::SetLoggedIn(bool logged_in) { | 171 void TestingProfileManager::SetLoggedIn(bool logged_in) { |
156 profile_manager_->logged_in_ = logged_in; | 172 profile_manager_->logged_in_ = logged_in; |
157 } | 173 } |
158 | 174 |
(...skipping 17 matching lines...) Expand all Loading... |
176 << "ProfileManager already exists"; | 192 << "ProfileManager already exists"; |
177 | 193 |
178 // Set up the directory for profiles. | 194 // Set up the directory for profiles. |
179 ASSERT_TRUE(profiles_dir_.CreateUniqueTempDir()); | 195 ASSERT_TRUE(profiles_dir_.CreateUniqueTempDir()); |
180 | 196 |
181 profile_manager_ = new testing::ProfileManager(profiles_dir_.path()); | 197 profile_manager_ = new testing::ProfileManager(profiles_dir_.path()); |
182 browser_process_->SetProfileManager(profile_manager_); // Takes ownership. | 198 browser_process_->SetProfileManager(profile_manager_); // Takes ownership. |
183 | 199 |
184 called_set_up_ = true; | 200 called_set_up_ = true; |
185 } | 201 } |
OLD | NEW |