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.h" | 5 #include "chrome/test/base/testing_profile.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 // ChromeBrowserMainPartsChromeos::PreEarlyInitialization. | 155 // ChromeBrowserMainPartsChromeos::PreEarlyInitialization. |
156 const char TestingProfile::kTestUserProfileDir[] = "test-user"; | 156 const char TestingProfile::kTestUserProfileDir[] = "test-user"; |
157 #else | 157 #else |
158 const char TestingProfile::kTestUserProfileDir[] = "Default"; | 158 const char TestingProfile::kTestUserProfileDir[] = "Default"; |
159 #endif | 159 #endif |
160 | 160 |
161 TestingProfile::TestingProfile() | 161 TestingProfile::TestingProfile() |
162 : start_time_(Time::Now()), | 162 : start_time_(Time::Now()), |
163 testing_prefs_(NULL), | 163 testing_prefs_(NULL), |
164 incognito_(false), | 164 incognito_(false), |
| 165 original_profile_(NULL), |
165 last_session_exited_cleanly_(true), | 166 last_session_exited_cleanly_(true), |
166 profile_dependency_manager_(ProfileDependencyManager::GetInstance()), | 167 profile_dependency_manager_(ProfileDependencyManager::GetInstance()), |
167 delegate_(NULL) { | 168 delegate_(NULL) { |
168 CreateTempProfileDir(); | 169 CreateTempProfileDir(); |
169 profile_path_ = temp_dir_.path(); | 170 profile_path_ = temp_dir_.path(); |
170 | 171 |
171 Init(); | 172 Init(); |
172 FinishInit(); | 173 FinishInit(); |
173 } | 174 } |
174 | 175 |
175 TestingProfile::TestingProfile(const FilePath& path) | 176 TestingProfile::TestingProfile(const FilePath& path) |
176 : start_time_(Time::Now()), | 177 : start_time_(Time::Now()), |
177 testing_prefs_(NULL), | 178 testing_prefs_(NULL), |
178 incognito_(false), | 179 incognito_(false), |
| 180 original_profile_(NULL), |
179 last_session_exited_cleanly_(true), | 181 last_session_exited_cleanly_(true), |
180 profile_path_(path), | 182 profile_path_(path), |
181 profile_dependency_manager_(ProfileDependencyManager::GetInstance()), | 183 profile_dependency_manager_(ProfileDependencyManager::GetInstance()), |
182 delegate_(NULL) { | 184 delegate_(NULL) { |
183 Init(); | 185 Init(); |
184 FinishInit(); | 186 FinishInit(); |
185 } | 187 } |
186 | 188 |
187 TestingProfile::TestingProfile(const FilePath& path, | 189 TestingProfile::TestingProfile(const FilePath& path, |
188 Delegate* delegate) | 190 Delegate* delegate) |
189 : start_time_(Time::Now()), | 191 : start_time_(Time::Now()), |
190 testing_prefs_(NULL), | 192 testing_prefs_(NULL), |
191 incognito_(false), | 193 incognito_(false), |
| 194 original_profile_(NULL), |
192 last_session_exited_cleanly_(true), | 195 last_session_exited_cleanly_(true), |
193 profile_path_(path), | 196 profile_path_(path), |
194 profile_dependency_manager_(ProfileDependencyManager::GetInstance()), | 197 profile_dependency_manager_(ProfileDependencyManager::GetInstance()), |
195 delegate_(delegate) { | 198 delegate_(delegate) { |
196 Init(); | 199 Init(); |
197 if (delegate_) { | 200 if (delegate_) { |
198 MessageLoop::current()->PostTask(FROM_HERE, | 201 MessageLoop::current()->PostTask(FROM_HERE, |
199 base::Bind(&TestingProfile::FinishInit, | 202 base::Bind(&TestingProfile::FinishInit, |
200 base::Unretained(this))); | 203 base::Unretained(this))); |
201 } else { | 204 } else { |
202 FinishInit(); | 205 FinishInit(); |
203 } | 206 } |
204 } | 207 } |
205 | 208 |
206 TestingProfile::TestingProfile( | 209 TestingProfile::TestingProfile( |
207 const FilePath& path, | 210 const FilePath& path, |
208 Delegate* delegate, | 211 Delegate* delegate, |
209 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy, | 212 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy, |
210 scoped_ptr<PrefServiceSyncable> prefs, | 213 scoped_ptr<PrefServiceSyncable> prefs, |
211 bool off_the_record) | 214 bool off_the_record) |
212 : start_time_(Time::Now()), | 215 : start_time_(Time::Now()), |
213 prefs_(prefs.release()), | 216 prefs_(prefs.release()), |
214 testing_prefs_(NULL), | 217 testing_prefs_(NULL), |
215 incognito_(off_the_record), | 218 incognito_(off_the_record), |
| 219 original_profile_(NULL), |
216 last_session_exited_cleanly_(true), | 220 last_session_exited_cleanly_(true), |
217 extension_special_storage_policy_(extension_policy), | 221 extension_special_storage_policy_(extension_policy), |
218 profile_path_(path), | 222 profile_path_(path), |
219 profile_dependency_manager_(ProfileDependencyManager::GetInstance()), | 223 profile_dependency_manager_(ProfileDependencyManager::GetInstance()), |
220 delegate_(delegate) { | 224 delegate_(delegate) { |
221 | 225 |
222 // If no profile path was supplied, create one. | 226 // If no profile path was supplied, create one. |
223 if (profile_path_.empty()) { | 227 if (profile_path_.empty()) { |
224 CreateTempProfileDir(); | 228 CreateTempProfileDir(); |
225 profile_path_ = temp_dir_.path(); | 229 profile_path_ = temp_dir_.path(); |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 } | 496 } |
493 | 497 |
494 bool TestingProfile::IsOffTheRecord() const { | 498 bool TestingProfile::IsOffTheRecord() const { |
495 return incognito_; | 499 return incognito_; |
496 } | 500 } |
497 | 501 |
498 void TestingProfile::SetOffTheRecordProfile(Profile* profile) { | 502 void TestingProfile::SetOffTheRecordProfile(Profile* profile) { |
499 incognito_profile_.reset(profile); | 503 incognito_profile_.reset(profile); |
500 } | 504 } |
501 | 505 |
| 506 void TestingProfile::SetOriginalProfile(Profile* profile) { |
| 507 original_profile_ = profile; |
| 508 } |
| 509 |
502 Profile* TestingProfile::GetOffTheRecordProfile() { | 510 Profile* TestingProfile::GetOffTheRecordProfile() { |
503 return incognito_profile_.get(); | 511 return incognito_profile_.get(); |
504 } | 512 } |
505 | 513 |
506 bool TestingProfile::HasOffTheRecordProfile() { | 514 bool TestingProfile::HasOffTheRecordProfile() { |
507 return incognito_profile_.get() != NULL; | 515 return incognito_profile_.get() != NULL; |
508 } | 516 } |
509 | 517 |
510 Profile* TestingProfile::GetOriginalProfile() { | 518 Profile* TestingProfile::GetOriginalProfile() { |
| 519 if (original_profile_) |
| 520 return original_profile_; |
511 return this; | 521 return this; |
512 } | 522 } |
513 | 523 |
514 ExtensionService* TestingProfile::GetExtensionService() { | 524 ExtensionService* TestingProfile::GetExtensionService() { |
515 return extensions::ExtensionSystem::Get(this)->extension_service(); | 525 return extensions::ExtensionSystem::Get(this)->extension_service(); |
516 } | 526 } |
517 | 527 |
518 void TestingProfile::SetExtensionSpecialStoragePolicy( | 528 void TestingProfile::SetExtensionSpecialStoragePolicy( |
519 ExtensionSpecialStoragePolicy* extension_special_storage_policy) { | 529 ExtensionSpecialStoragePolicy* extension_special_storage_policy) { |
520 extension_special_storage_policy_ = extension_special_storage_policy; | 530 extension_special_storage_policy_ = extension_special_storage_policy; |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() { | 805 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() { |
796 DCHECK(!build_called_); | 806 DCHECK(!build_called_); |
797 build_called_ = true; | 807 build_called_ = true; |
798 return scoped_ptr<TestingProfile>(new TestingProfile( | 808 return scoped_ptr<TestingProfile>(new TestingProfile( |
799 path_, | 809 path_, |
800 delegate_, | 810 delegate_, |
801 extension_policy_, | 811 extension_policy_, |
802 pref_service_.Pass(), | 812 pref_service_.Pass(), |
803 off_the_record_)); | 813 off_the_record_)); |
804 } | 814 } |
OLD | NEW |