| 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 // ChromeBrowserMainPartsChromeos::PreEarlyInitialization. | 156 // ChromeBrowserMainPartsChromeos::PreEarlyInitialization. |
| 157 const char TestingProfile::kTestUserProfileDir[] = "test-user"; | 157 const char TestingProfile::kTestUserProfileDir[] = "test-user"; |
| 158 #else | 158 #else |
| 159 const char TestingProfile::kTestUserProfileDir[] = "Default"; | 159 const char TestingProfile::kTestUserProfileDir[] = "Default"; |
| 160 #endif | 160 #endif |
| 161 | 161 |
| 162 TestingProfile::TestingProfile() | 162 TestingProfile::TestingProfile() |
| 163 : start_time_(Time::Now()), | 163 : start_time_(Time::Now()), |
| 164 testing_prefs_(NULL), | 164 testing_prefs_(NULL), |
| 165 incognito_(false), | 165 incognito_(false), |
| 166 original_profile_(NULL), |
| 166 last_session_exited_cleanly_(true), | 167 last_session_exited_cleanly_(true), |
| 167 profile_dependency_manager_(ProfileDependencyManager::GetInstance()), | 168 profile_dependency_manager_(ProfileDependencyManager::GetInstance()), |
| 168 delegate_(NULL) { | 169 delegate_(NULL) { |
| 169 CreateTempProfileDir(); | 170 CreateTempProfileDir(); |
| 170 profile_path_ = temp_dir_.path(); | 171 profile_path_ = temp_dir_.path(); |
| 171 | 172 |
| 172 Init(); | 173 Init(); |
| 173 FinishInit(); | 174 FinishInit(); |
| 174 } | 175 } |
| 175 | 176 |
| 176 TestingProfile::TestingProfile(const base::FilePath& path) | 177 TestingProfile::TestingProfile(const base::FilePath& path) |
| 177 : start_time_(Time::Now()), | 178 : start_time_(Time::Now()), |
| 178 testing_prefs_(NULL), | 179 testing_prefs_(NULL), |
| 179 incognito_(false), | 180 incognito_(false), |
| 181 original_profile_(NULL), |
| 180 last_session_exited_cleanly_(true), | 182 last_session_exited_cleanly_(true), |
| 181 profile_path_(path), | 183 profile_path_(path), |
| 182 profile_dependency_manager_(ProfileDependencyManager::GetInstance()), | 184 profile_dependency_manager_(ProfileDependencyManager::GetInstance()), |
| 183 delegate_(NULL) { | 185 delegate_(NULL) { |
| 184 Init(); | 186 Init(); |
| 185 FinishInit(); | 187 FinishInit(); |
| 186 } | 188 } |
| 187 | 189 |
| 188 TestingProfile::TestingProfile(const base::FilePath& path, | 190 TestingProfile::TestingProfile(const base::FilePath& path, |
| 189 Delegate* delegate) | 191 Delegate* delegate) |
| 190 : start_time_(Time::Now()), | 192 : start_time_(Time::Now()), |
| 191 testing_prefs_(NULL), | 193 testing_prefs_(NULL), |
| 192 incognito_(false), | 194 incognito_(false), |
| 195 original_profile_(NULL), |
| 193 last_session_exited_cleanly_(true), | 196 last_session_exited_cleanly_(true), |
| 194 profile_path_(path), | 197 profile_path_(path), |
| 195 profile_dependency_manager_(ProfileDependencyManager::GetInstance()), | 198 profile_dependency_manager_(ProfileDependencyManager::GetInstance()), |
| 196 delegate_(delegate) { | 199 delegate_(delegate) { |
| 197 Init(); | 200 Init(); |
| 198 if (delegate_) { | 201 if (delegate_) { |
| 199 MessageLoop::current()->PostTask(FROM_HERE, | 202 MessageLoop::current()->PostTask(FROM_HERE, |
| 200 base::Bind(&TestingProfile::FinishInit, | 203 base::Bind(&TestingProfile::FinishInit, |
| 201 base::Unretained(this))); | 204 base::Unretained(this))); |
| 202 } else { | 205 } else { |
| 203 FinishInit(); | 206 FinishInit(); |
| 204 } | 207 } |
| 205 } | 208 } |
| 206 | 209 |
| 207 TestingProfile::TestingProfile( | 210 TestingProfile::TestingProfile( |
| 208 const base::FilePath& path, | 211 const base::FilePath& path, |
| 209 Delegate* delegate, | 212 Delegate* delegate, |
| 210 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy, | 213 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy, |
| 211 scoped_ptr<PrefServiceSyncable> prefs) | 214 scoped_ptr<PrefServiceSyncable> prefs) |
| 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_(false), | 218 incognito_(false), |
| 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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 } | 497 } |
| 494 | 498 |
| 495 bool TestingProfile::IsOffTheRecord() const { | 499 bool TestingProfile::IsOffTheRecord() const { |
| 496 return incognito_; | 500 return incognito_; |
| 497 } | 501 } |
| 498 | 502 |
| 499 void TestingProfile::SetOffTheRecordProfile(Profile* profile) { | 503 void TestingProfile::SetOffTheRecordProfile(Profile* profile) { |
| 500 incognito_profile_.reset(profile); | 504 incognito_profile_.reset(profile); |
| 501 } | 505 } |
| 502 | 506 |
| 507 void TestingProfile::SetOriginalProfile(Profile* profile) { |
| 508 original_profile_ = profile; |
| 509 } |
| 510 |
| 503 Profile* TestingProfile::GetOffTheRecordProfile() { | 511 Profile* TestingProfile::GetOffTheRecordProfile() { |
| 504 return incognito_profile_.get(); | 512 return incognito_profile_.get(); |
| 505 } | 513 } |
| 506 | 514 |
| 507 bool TestingProfile::HasOffTheRecordProfile() { | 515 bool TestingProfile::HasOffTheRecordProfile() { |
| 508 return incognito_profile_.get() != NULL; | 516 return incognito_profile_.get() != NULL; |
| 509 } | 517 } |
| 510 | 518 |
| 511 Profile* TestingProfile::GetOriginalProfile() { | 519 Profile* TestingProfile::GetOriginalProfile() { |
| 520 if (original_profile_) |
| 521 return original_profile_; |
| 512 return this; | 522 return this; |
| 513 } | 523 } |
| 514 | 524 |
| 515 ExtensionService* TestingProfile::GetExtensionService() { | 525 ExtensionService* TestingProfile::GetExtensionService() { |
| 516 return extensions::ExtensionSystem::Get(this)->extension_service(); | 526 return extensions::ExtensionSystem::Get(this)->extension_service(); |
| 517 } | 527 } |
| 518 | 528 |
| 519 void TestingProfile::SetExtensionSpecialStoragePolicy( | 529 void TestingProfile::SetExtensionSpecialStoragePolicy( |
| 520 ExtensionSpecialStoragePolicy* extension_special_storage_policy) { | 530 ExtensionSpecialStoragePolicy* extension_special_storage_policy) { |
| 521 extension_special_storage_policy_ = extension_special_storage_policy; | 531 extension_special_storage_policy_ = extension_special_storage_policy; |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 | 820 |
| 811 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() { | 821 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() { |
| 812 DCHECK(!build_called_); | 822 DCHECK(!build_called_); |
| 813 build_called_ = true; | 823 build_called_ = true; |
| 814 return scoped_ptr<TestingProfile>(new TestingProfile( | 824 return scoped_ptr<TestingProfile>(new TestingProfile( |
| 815 path_, | 825 path_, |
| 816 delegate_, | 826 delegate_, |
| 817 extension_policy_, | 827 extension_policy_, |
| 818 pref_service_.Pass())); | 828 pref_service_.Pass())); |
| 819 } | 829 } |
| OLD | NEW |