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 "base/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 // Must be kept in sync with | 177 // Must be kept in sync with |
178 // ChromeBrowserMainPartsChromeos::PreEarlyInitialization. | 178 // ChromeBrowserMainPartsChromeos::PreEarlyInitialization. |
179 const char TestingProfile::kTestUserProfileDir[] = "test-user"; | 179 const char TestingProfile::kTestUserProfileDir[] = "test-user"; |
180 #else | 180 #else |
181 const char TestingProfile::kTestUserProfileDir[] = "Default"; | 181 const char TestingProfile::kTestUserProfileDir[] = "Default"; |
182 #endif | 182 #endif |
183 | 183 |
184 TestingProfile::TestingProfile() | 184 TestingProfile::TestingProfile() |
185 : start_time_(Time::Now()), | 185 : start_time_(Time::Now()), |
186 testing_prefs_(NULL), | 186 testing_prefs_(NULL), |
187 incognito_(false), | |
188 force_incognito_(false), | 187 force_incognito_(false), |
189 original_profile_(NULL), | 188 original_profile_(NULL), |
190 guest_session_(false), | 189 guest_session_(false), |
191 last_session_exited_cleanly_(true), | 190 last_session_exited_cleanly_(true), |
192 browser_context_dependency_manager_( | 191 browser_context_dependency_manager_( |
193 BrowserContextDependencyManager::GetInstance()), | 192 BrowserContextDependencyManager::GetInstance()), |
194 resource_context_(NULL), | 193 resource_context_(NULL), |
195 delegate_(NULL) { | 194 delegate_(NULL) { |
196 CreateTempProfileDir(); | 195 CreateTempProfileDir(); |
197 profile_path_ = temp_dir_.path(); | 196 profile_path_ = temp_dir_.path(); |
198 | 197 |
199 Init(); | 198 Init(); |
200 FinishInit(); | 199 FinishInit(); |
201 } | 200 } |
202 | 201 |
203 TestingProfile::TestingProfile(const base::FilePath& path) | 202 TestingProfile::TestingProfile(const base::FilePath& path) |
204 : start_time_(Time::Now()), | 203 : start_time_(Time::Now()), |
205 testing_prefs_(NULL), | 204 testing_prefs_(NULL), |
206 incognito_(false), | |
207 force_incognito_(false), | 205 force_incognito_(false), |
208 original_profile_(NULL), | 206 original_profile_(NULL), |
209 guest_session_(false), | 207 guest_session_(false), |
210 last_session_exited_cleanly_(true), | 208 last_session_exited_cleanly_(true), |
211 profile_path_(path), | 209 profile_path_(path), |
212 browser_context_dependency_manager_( | 210 browser_context_dependency_manager_( |
213 BrowserContextDependencyManager::GetInstance()), | 211 BrowserContextDependencyManager::GetInstance()), |
214 resource_context_(NULL), | 212 resource_context_(NULL), |
215 delegate_(NULL) { | 213 delegate_(NULL) { |
216 Init(); | 214 Init(); |
217 FinishInit(); | 215 FinishInit(); |
218 } | 216 } |
219 | 217 |
220 TestingProfile::TestingProfile(const base::FilePath& path, | 218 TestingProfile::TestingProfile(const base::FilePath& path, |
221 Delegate* delegate) | 219 Delegate* delegate) |
222 : start_time_(Time::Now()), | 220 : start_time_(Time::Now()), |
223 testing_prefs_(NULL), | 221 testing_prefs_(NULL), |
224 incognito_(false), | |
225 force_incognito_(false), | 222 force_incognito_(false), |
226 original_profile_(NULL), | 223 original_profile_(NULL), |
227 guest_session_(false), | 224 guest_session_(false), |
228 last_session_exited_cleanly_(true), | 225 last_session_exited_cleanly_(true), |
229 profile_path_(path), | 226 profile_path_(path), |
230 browser_context_dependency_manager_( | 227 browser_context_dependency_manager_( |
231 BrowserContextDependencyManager::GetInstance()), | 228 BrowserContextDependencyManager::GetInstance()), |
232 resource_context_(NULL), | 229 resource_context_(NULL), |
233 delegate_(delegate) { | 230 delegate_(delegate) { |
234 Init(); | 231 Init(); |
235 if (delegate_) { | 232 if (delegate_) { |
236 base::MessageLoop::current()->PostTask( | 233 base::MessageLoop::current()->PostTask( |
237 FROM_HERE, | 234 FROM_HERE, |
238 base::Bind(&TestingProfile::FinishInit, base::Unretained(this))); | 235 base::Bind(&TestingProfile::FinishInit, base::Unretained(this))); |
239 } else { | 236 } else { |
240 FinishInit(); | 237 FinishInit(); |
241 } | 238 } |
242 } | 239 } |
243 | 240 |
244 TestingProfile::TestingProfile( | 241 TestingProfile::TestingProfile( |
245 const base::FilePath& path, | 242 const base::FilePath& path, |
246 Delegate* delegate, | 243 Delegate* delegate, |
247 #if defined(ENABLE_EXTENSIONS) | 244 #if defined(ENABLE_EXTENSIONS) |
248 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy, | 245 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy, |
249 #endif | 246 #endif |
250 scoped_ptr<PrefServiceSyncable> prefs, | 247 scoped_ptr<PrefServiceSyncable> prefs, |
251 bool incognito, | 248 TestingProfile* incognito_parent, |
252 bool guest_session, | 249 bool guest_session, |
253 const std::string& supervised_user_id, | 250 const std::string& supervised_user_id, |
254 scoped_ptr<policy::PolicyService> policy_service, | 251 scoped_ptr<policy::PolicyService> policy_service, |
255 const TestingFactories& factories) | 252 const TestingFactories& factories) |
256 : start_time_(Time::Now()), | 253 : start_time_(Time::Now()), |
257 prefs_(prefs.release()), | 254 prefs_(prefs.release()), |
258 testing_prefs_(NULL), | 255 testing_prefs_(NULL), |
259 incognito_(incognito), | |
260 force_incognito_(false), | 256 force_incognito_(false), |
261 original_profile_(NULL), | 257 original_profile_(incognito_parent), |
262 guest_session_(guest_session), | 258 guest_session_(guest_session), |
263 supervised_user_id_(supervised_user_id), | 259 supervised_user_id_(supervised_user_id), |
264 last_session_exited_cleanly_(true), | 260 last_session_exited_cleanly_(true), |
265 #if defined(ENABLE_EXTENSIONS) | 261 #if defined(ENABLE_EXTENSIONS) |
266 extension_special_storage_policy_(extension_policy), | 262 extension_special_storage_policy_(extension_policy), |
267 #endif | 263 #endif |
268 profile_path_(path), | 264 profile_path_(path), |
269 browser_context_dependency_manager_( | 265 browser_context_dependency_manager_( |
270 BrowserContextDependencyManager::GetInstance()), | 266 BrowserContextDependencyManager::GetInstance()), |
271 resource_context_(NULL), | 267 resource_context_(NULL), |
272 delegate_(delegate), | 268 delegate_(delegate), |
273 policy_service_(policy_service.release()) { | 269 policy_service_(policy_service.release()) { |
270 if (incognito_parent) | |
271 incognito_parent->SetTestingOffTheRecordProfile(this); // Takes ownership. | |
272 | |
274 // If no profile path was supplied, create one. | 273 // If no profile path was supplied, create one. |
275 if (profile_path_.empty()) { | 274 if (profile_path_.empty()) { |
276 CreateTempProfileDir(); | 275 CreateTempProfileDir(); |
277 profile_path_ = temp_dir_.path(); | 276 profile_path_ = temp_dir_.path(); |
278 } | 277 } |
279 | 278 |
280 // Set any testing factories prior to initializing the services. | 279 // Set any testing factories prior to initializing the services. |
281 for (TestingFactories::const_iterator it = factories.begin(); | 280 for (TestingFactories::const_iterator it = factories.begin(); |
282 it != factories.end(); ++it) { | 281 it != factories.end(); ++it) { |
283 it->first->SetTestingFactory(this, it->second); | 282 it->first->SetTestingFactory(this, it->second); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 AndroidProfileOAuth2TokenService::set_is_testing_profile(); | 334 AndroidProfileOAuth2TokenService::set_is_testing_profile(); |
336 #endif | 335 #endif |
337 | 336 |
338 // Normally this would happen during browser startup, but for tests | 337 // Normally this would happen during browser startup, but for tests |
339 // we need to trigger creation of Profile-related services. | 338 // we need to trigger creation of Profile-related services. |
340 ChromeBrowserMainExtraPartsProfiles:: | 339 ChromeBrowserMainExtraPartsProfiles:: |
341 EnsureBrowserContextKeyedServiceFactoriesBuilt(); | 340 EnsureBrowserContextKeyedServiceFactoriesBuilt(); |
342 | 341 |
343 if (prefs_.get()) | 342 if (prefs_.get()) |
344 user_prefs::UserPrefs::Set(this, prefs_.get()); | 343 user_prefs::UserPrefs::Set(this, prefs_.get()); |
344 else if (IsOffTheRecord()) | |
345 CreateIncognitoPrefService(); | |
345 else | 346 else |
346 CreateTestingPrefService(); | 347 CreateTestingPrefService(); |
347 | 348 |
348 if (!base::PathExists(profile_path_)) | 349 if (!base::PathExists(profile_path_)) |
349 base::CreateDirectory(profile_path_); | 350 base::CreateDirectory(profile_path_); |
350 | 351 |
351 // TODO(joaodasilva): remove this once this PKS isn't created in ProfileImpl | 352 // TODO(joaodasilva): remove this once this PKS isn't created in ProfileImpl |
352 // anymore, after converting the PrefService to a PKS. Until then it must | 353 // anymore, after converting the PrefService to a PKS. Until then it must |
353 // be associated with a TestingProfile too. | 354 // be associated with a TestingProfile too. |
354 if (!IsOffTheRecord()) | 355 if (!IsOffTheRecord()) |
355 CreateProfilePolicyConnector(); | 356 CreateProfilePolicyConnector(); |
356 | 357 |
357 #if defined(ENABLE_EXTENSIONS) | 358 #if defined(ENABLE_EXTENSIONS) |
358 extensions::ExtensionSystemFactory::GetInstance()->SetTestingFactory( | 359 extensions::ExtensionSystemFactory::GetInstance()->SetTestingFactory( |
359 this, extensions::TestExtensionSystem::Build); | 360 this, extensions::TestExtensionSystem::Build); |
360 #endif | 361 #endif |
361 | 362 |
362 // If no original profile was specified for this profile: register preferences | 363 // Prefs for incognito profiles are set in CreateIncognitoPrefService() by |
363 // even if this is an incognito profile - this allows tests to create a | 364 // simulating ProfileImpl::GetOffTheRecordPrefs(). |
364 // standalone incognito profile while still having prefs registered. | 365 if (!IsOffTheRecord()) { |
365 if (!IsOffTheRecord() || !original_profile_) { | 366 DCHECK(!original_profile_); |
366 user_prefs::PrefRegistrySyncable* pref_registry = | 367 user_prefs::PrefRegistrySyncable* pref_registry = |
367 static_cast<user_prefs::PrefRegistrySyncable*>( | 368 static_cast<user_prefs::PrefRegistrySyncable*>( |
368 prefs_->DeprecatedGetPrefRegistry()); | 369 prefs_->DeprecatedGetPrefRegistry()); |
369 browser_context_dependency_manager_-> | 370 browser_context_dependency_manager_-> |
370 RegisterProfilePrefsForServices(this, pref_registry); | 371 RegisterProfilePrefsForServices(this, pref_registry); |
371 } | 372 } |
372 | 373 |
373 browser_context_dependency_manager_->CreateBrowserContextServicesForTest( | 374 browser_context_dependency_manager_->CreateBrowserContextServicesForTest( |
374 this); | 375 this); |
375 | 376 |
376 #if defined(ENABLE_NOTIFICATIONS) | 377 #if defined(ENABLE_NOTIFICATIONS) |
377 // Install profile keyed service factory hooks for dummy/test services | 378 // Install profile keyed service factory hooks for dummy/test services |
378 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory( | 379 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory( |
379 this, CreateTestDesktopNotificationService); | 380 this, CreateTestDesktopNotificationService); |
380 #endif | 381 #endif |
381 | 382 |
382 #if defined(ENABLE_MANAGED_USERS) | 383 #if defined(ENABLE_MANAGED_USERS) |
383 SupervisedUserSettingsService* settings_service = | 384 if (!IsOffTheRecord()) { |
384 SupervisedUserSettingsServiceFactory::GetForProfile(this); | 385 SupervisedUserSettingsService* settings_service = |
385 TestingPrefStore* store = new TestingPrefStore(); | 386 SupervisedUserSettingsServiceFactory::GetForProfile(this); |
386 settings_service->Init(store); | 387 TestingPrefStore* store = new TestingPrefStore(); |
387 store->SetInitializationCompleted(); | 388 settings_service->Init(store); |
389 store->SetInitializationCompleted(); | |
390 } | |
388 #endif | 391 #endif |
389 | 392 |
390 profile_name_ = "testing_profile"; | 393 profile_name_ = "testing_profile"; |
391 } | 394 } |
392 | 395 |
393 void TestingProfile::FinishInit() { | 396 void TestingProfile::FinishInit() { |
394 DCHECK(content::NotificationService::current()); | 397 DCHECK(content::NotificationService::current()); |
395 content::NotificationService::current()->Notify( | 398 content::NotificationService::current()->Notify( |
396 chrome::NOTIFICATION_PROFILE_CREATED, | 399 chrome::NOTIFICATION_PROFILE_CREATED, |
397 content::Source<Profile>(static_cast<Profile*>(this)), | 400 content::Source<Profile>(static_cast<Profile*>(this)), |
398 content::NotificationService::NoDetails()); | 401 content::NotificationService::NoDetails()); |
399 | 402 |
400 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 403 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
401 if (profile_manager) | 404 if (profile_manager) |
402 profile_manager->InitProfileUserPrefs(this); | 405 profile_manager->InitProfileUserPrefs(this); |
403 | 406 |
404 if (delegate_) | 407 if (delegate_) |
405 delegate_->OnProfileCreated(this, true, false); | 408 delegate_->OnProfileCreated(this, true, false); |
406 } | 409 } |
407 | 410 |
408 TestingProfile::~TestingProfile() { | 411 TestingProfile::~TestingProfile() { |
409 // Revert to non-incognito mode before shutdown. | 412 // Revert to non-incognito mode before shutdown. |
410 force_incognito_ = false; | 413 force_incognito_ = false; |
411 | 414 |
415 // If this profile owns an incognito profile, tear it down first. | |
416 incognito_profile_.reset(); | |
tapted
2014/09/12 07:54:09
This was needed to resolve a lifetime issue in the
| |
417 | |
412 // Any objects holding live URLFetchers should be deleted before teardown. | 418 // Any objects holding live URLFetchers should be deleted before teardown. |
413 TemplateURLFetcherFactory::ShutdownForProfile(this); | 419 TemplateURLFetcherFactory::ShutdownForProfile(this); |
414 | 420 |
415 MaybeSendDestroyedNotification(); | 421 MaybeSendDestroyedNotification(); |
416 | 422 |
417 browser_context_dependency_manager_->DestroyBrowserContextServices(this); | 423 browser_context_dependency_manager_->DestroyBrowserContextServices(this); |
418 | 424 |
419 if (host_content_settings_map_.get()) | 425 if (host_content_settings_map_.get()) |
420 host_content_settings_map_->ShutdownOnUIThread(); | 426 host_content_settings_map_->ShutdownOnUIThread(); |
421 | 427 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
594 | 600 |
595 base::FilePath TestingProfile::GetPath() const { | 601 base::FilePath TestingProfile::GetPath() const { |
596 return profile_path_; | 602 return profile_path_; |
597 } | 603 } |
598 | 604 |
599 scoped_refptr<base::SequencedTaskRunner> TestingProfile::GetIOTaskRunner() { | 605 scoped_refptr<base::SequencedTaskRunner> TestingProfile::GetIOTaskRunner() { |
600 return base::MessageLoop::current()->message_loop_proxy(); | 606 return base::MessageLoop::current()->message_loop_proxy(); |
601 } | 607 } |
602 | 608 |
603 TestingPrefServiceSyncable* TestingProfile::GetTestingPrefService() { | 609 TestingPrefServiceSyncable* TestingProfile::GetTestingPrefService() { |
604 if (!prefs_.get()) | 610 DCHECK(prefs_); |
605 CreateTestingPrefService(); | |
606 DCHECK(testing_prefs_); | 611 DCHECK(testing_prefs_); |
607 return testing_prefs_; | 612 return testing_prefs_; |
608 } | 613 } |
609 | 614 |
610 TestingProfile* TestingProfile::AsTestingProfile() { | 615 TestingProfile* TestingProfile::AsTestingProfile() { |
611 return this; | 616 return this; |
612 } | 617 } |
613 | 618 |
614 std::string TestingProfile::GetProfileName() { | 619 std::string TestingProfile::GetProfileName() { |
615 return profile_name_; | 620 return profile_name_; |
616 } | 621 } |
617 | 622 |
618 Profile::ProfileType TestingProfile::GetProfileType() const { | 623 Profile::ProfileType TestingProfile::GetProfileType() const { |
619 if (guest_session_) | 624 if (guest_session_) |
620 return GUEST_PROFILE; | 625 return GUEST_PROFILE; |
621 if (force_incognito_ || incognito_) | 626 if (force_incognito_ || original_profile_) |
622 return INCOGNITO_PROFILE; | 627 return INCOGNITO_PROFILE; |
623 return REGULAR_PROFILE; | 628 return REGULAR_PROFILE; |
624 } | 629 } |
625 | 630 |
626 bool TestingProfile::IsOffTheRecord() const { | 631 bool TestingProfile::IsOffTheRecord() const { |
627 return force_incognito_ || incognito_; | 632 return force_incognito_ || original_profile_; |
628 } | 633 } |
629 | 634 |
630 void TestingProfile::SetOffTheRecordProfile(scoped_ptr<Profile> profile) { | 635 void TestingProfile::SetOffTheRecordProfile(scoped_ptr<Profile> profile) { |
sky
2014/09/12 15:33:29
Can this be changed to take a TestingProfile? It w
tapted
2014/09/15 05:05:16
Not easily - that was actually my first attempt, b
| |
631 DCHECK(!IsOffTheRecord()); | 636 DCHECK(!IsOffTheRecord()); |
632 incognito_profile_ = profile.Pass(); | 637 incognito_profile_ = profile.Pass(); |
633 } | 638 } |
634 | 639 |
635 void TestingProfile::SetOriginalProfile(Profile* profile) { | |
636 DCHECK(IsOffTheRecord()); | |
637 original_profile_ = profile; | |
638 } | |
639 | |
640 Profile* TestingProfile::GetOffTheRecordProfile() { | 640 Profile* TestingProfile::GetOffTheRecordProfile() { |
641 if (IsOffTheRecord()) | 641 if (IsOffTheRecord()) |
642 return this; | 642 return this; |
643 if (!incognito_profile_) { | 643 if (!incognito_profile_) |
644 TestingProfile::Builder builder; | 644 TestingProfile::Builder().BuildIncognito(this); |
645 builder.SetIncognito(); | |
646 scoped_ptr<TestingProfile> incognito_test_profile(builder.Build()); | |
647 incognito_test_profile->SetOriginalProfile(this); | |
648 SetOffTheRecordProfile(incognito_test_profile.PassAs<Profile>()); | |
649 } | |
650 return incognito_profile_.get(); | 645 return incognito_profile_.get(); |
651 } | 646 } |
652 | 647 |
653 bool TestingProfile::HasOffTheRecordProfile() { | 648 bool TestingProfile::HasOffTheRecordProfile() { |
654 return incognito_profile_.get() != NULL; | 649 return incognito_profile_.get() != NULL; |
655 } | 650 } |
656 | 651 |
657 Profile* TestingProfile::GetOriginalProfile() { | 652 Profile* TestingProfile::GetOriginalProfile() { |
658 if (original_profile_) | 653 if (original_profile_) |
659 return original_profile_; | 654 return original_profile_; |
(...skipping 30 matching lines...) Expand all Loading... | |
690 } | 685 } |
691 | 686 |
692 void TestingProfile::CreateTestingPrefService() { | 687 void TestingProfile::CreateTestingPrefService() { |
693 DCHECK(!prefs_.get()); | 688 DCHECK(!prefs_.get()); |
694 testing_prefs_ = new TestingPrefServiceSyncable(); | 689 testing_prefs_ = new TestingPrefServiceSyncable(); |
695 prefs_.reset(testing_prefs_); | 690 prefs_.reset(testing_prefs_); |
696 user_prefs::UserPrefs::Set(this, prefs_.get()); | 691 user_prefs::UserPrefs::Set(this, prefs_.get()); |
697 chrome::RegisterUserProfilePrefs(testing_prefs_->registry()); | 692 chrome::RegisterUserProfilePrefs(testing_prefs_->registry()); |
698 } | 693 } |
699 | 694 |
695 void TestingProfile::CreateIncognitoPrefService() { | |
696 DCHECK(original_profile_); | |
697 DCHECK(!testing_prefs_); | |
698 // Simplified version of ProfileImpl::GetOffTheRecordPrefs(). Note this | |
699 // leaves testing_prefs_ unset. | |
700 prefs_.reset(original_profile_->prefs_->CreateIncognitoPrefService(NULL)); | |
701 user_prefs::UserPrefs::Set(this, prefs_.get()); | |
702 } | |
703 | |
700 void TestingProfile::CreateProfilePolicyConnector() { | 704 void TestingProfile::CreateProfilePolicyConnector() { |
701 #if defined(ENABLE_CONFIGURATION_POLICY) | 705 #if defined(ENABLE_CONFIGURATION_POLICY) |
702 schema_registry_service_ = | 706 schema_registry_service_ = |
703 policy::SchemaRegistryServiceFactory::CreateForContext( | 707 policy::SchemaRegistryServiceFactory::CreateForContext( |
704 this, policy::Schema(), NULL); | 708 this, policy::Schema(), NULL); |
705 CHECK_EQ(schema_registry_service_.get(), | 709 CHECK_EQ(schema_registry_service_.get(), |
706 policy::SchemaRegistryServiceFactory::GetForContext(this)); | 710 policy::SchemaRegistryServiceFactory::GetForContext(this)); |
707 #endif // defined(ENABLE_CONFIGURATION_POLICY) | 711 #endif // defined(ENABLE_CONFIGURATION_POLICY) |
708 | 712 |
709 if (!policy_service_) { | 713 if (!policy_service_) { |
710 #if defined(ENABLE_CONFIGURATION_POLICY) | 714 #if defined(ENABLE_CONFIGURATION_POLICY) |
711 std::vector<policy::ConfigurationPolicyProvider*> providers; | 715 std::vector<policy::ConfigurationPolicyProvider*> providers; |
712 policy_service_.reset(new policy::PolicyServiceImpl(providers)); | 716 policy_service_.reset(new policy::PolicyServiceImpl(providers)); |
713 #else | 717 #else |
714 policy_service_.reset(new policy::PolicyServiceStub()); | 718 policy_service_.reset(new policy::PolicyServiceStub()); |
715 #endif | 719 #endif |
716 } | 720 } |
717 profile_policy_connector_.reset(new policy::ProfilePolicyConnector()); | 721 profile_policy_connector_.reset(new policy::ProfilePolicyConnector()); |
718 profile_policy_connector_->InitForTesting(policy_service_.Pass()); | 722 profile_policy_connector_->InitForTesting(policy_service_.Pass()); |
719 policy::ProfilePolicyConnectorFactory::GetInstance()->SetServiceForTesting( | 723 policy::ProfilePolicyConnectorFactory::GetInstance()->SetServiceForTesting( |
720 this, profile_policy_connector_.get()); | 724 this, profile_policy_connector_.get()); |
721 CHECK_EQ(profile_policy_connector_.get(), | 725 CHECK_EQ(profile_policy_connector_.get(), |
722 policy::ProfilePolicyConnectorFactory::GetForProfile(this)); | 726 policy::ProfilePolicyConnectorFactory::GetForProfile(this)); |
723 } | 727 } |
724 | 728 |
729 void TestingProfile::SetTestingOffTheRecordProfile(Profile* incognito_profile) { | |
sky
2014/09/12 15:33:29
Is there a reason we need this? Why not have the c
tapted
2014/09/15 05:05:16
Nope! Removed. I think I had this taking a Testing
| |
730 DCHECK(!IsOffTheRecord()); | |
731 DCHECK(!incognito_profile_); | |
732 SetOffTheRecordProfile(make_scoped_ptr(incognito_profile)); | |
733 } | |
734 | |
725 PrefService* TestingProfile::GetPrefs() { | 735 PrefService* TestingProfile::GetPrefs() { |
726 if (!prefs_.get()) { | 736 DCHECK(prefs_); |
727 CreateTestingPrefService(); | |
728 } | |
729 return prefs_.get(); | 737 return prefs_.get(); |
730 } | 738 } |
731 | 739 |
732 history::TopSites* TestingProfile::GetTopSites() { | 740 history::TopSites* TestingProfile::GetTopSites() { |
733 return top_sites_.get(); | 741 return top_sites_.get(); |
734 } | 742 } |
735 | 743 |
736 history::TopSites* TestingProfile::GetTopSitesWithoutCreating() { | 744 history::TopSites* TestingProfile::GetTopSitesWithoutCreating() { |
737 return top_sites_.get(); | 745 return top_sites_.get(); |
738 } | 746 } |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
914 return guest_session_; | 922 return guest_session_; |
915 } | 923 } |
916 | 924 |
917 Profile::ExitType TestingProfile::GetLastSessionExitType() { | 925 Profile::ExitType TestingProfile::GetLastSessionExitType() { |
918 return last_session_exited_cleanly_ ? EXIT_NORMAL : EXIT_CRASHED; | 926 return last_session_exited_cleanly_ ? EXIT_NORMAL : EXIT_CRASHED; |
919 } | 927 } |
920 | 928 |
921 TestingProfile::Builder::Builder() | 929 TestingProfile::Builder::Builder() |
922 : build_called_(false), | 930 : build_called_(false), |
923 delegate_(NULL), | 931 delegate_(NULL), |
924 incognito_(false), | |
925 guest_session_(false) { | 932 guest_session_(false) { |
926 } | 933 } |
927 | 934 |
928 TestingProfile::Builder::~Builder() { | 935 TestingProfile::Builder::~Builder() { |
929 } | 936 } |
930 | 937 |
931 void TestingProfile::Builder::SetPath(const base::FilePath& path) { | 938 void TestingProfile::Builder::SetPath(const base::FilePath& path) { |
932 path_ = path; | 939 path_ = path; |
933 } | 940 } |
934 | 941 |
935 void TestingProfile::Builder::SetDelegate(Delegate* delegate) { | 942 void TestingProfile::Builder::SetDelegate(Delegate* delegate) { |
936 delegate_ = delegate; | 943 delegate_ = delegate; |
937 } | 944 } |
938 | 945 |
939 #if defined(ENABLE_EXTENSIONS) | 946 #if defined(ENABLE_EXTENSIONS) |
940 void TestingProfile::Builder::SetExtensionSpecialStoragePolicy( | 947 void TestingProfile::Builder::SetExtensionSpecialStoragePolicy( |
941 scoped_refptr<ExtensionSpecialStoragePolicy> policy) { | 948 scoped_refptr<ExtensionSpecialStoragePolicy> policy) { |
942 extension_policy_ = policy; | 949 extension_policy_ = policy; |
943 } | 950 } |
944 #endif | 951 #endif |
945 | 952 |
946 void TestingProfile::Builder::SetPrefService( | 953 void TestingProfile::Builder::SetPrefService( |
947 scoped_ptr<PrefServiceSyncable> prefs) { | 954 scoped_ptr<PrefServiceSyncable> prefs) { |
948 pref_service_ = prefs.Pass(); | 955 pref_service_ = prefs.Pass(); |
949 } | 956 } |
950 | 957 |
951 void TestingProfile::Builder::SetIncognito() { | |
952 incognito_ = true; | |
953 } | |
954 | |
955 void TestingProfile::Builder::SetGuestSession() { | 958 void TestingProfile::Builder::SetGuestSession() { |
956 guest_session_ = true; | 959 guest_session_ = true; |
957 } | 960 } |
958 | 961 |
959 void TestingProfile::Builder::SetSupervisedUserId( | 962 void TestingProfile::Builder::SetSupervisedUserId( |
960 const std::string& supervised_user_id) { | 963 const std::string& supervised_user_id) { |
961 supervised_user_id_ = supervised_user_id; | 964 supervised_user_id_ = supervised_user_id; |
962 } | 965 } |
963 | 966 |
964 void TestingProfile::Builder::SetPolicyService( | 967 void TestingProfile::Builder::SetPolicyService( |
965 scoped_ptr<policy::PolicyService> policy_service) { | 968 scoped_ptr<policy::PolicyService> policy_service) { |
966 policy_service_ = policy_service.Pass(); | 969 policy_service_ = policy_service.Pass(); |
967 } | 970 } |
968 | 971 |
969 void TestingProfile::Builder::AddTestingFactory( | 972 void TestingProfile::Builder::AddTestingFactory( |
970 BrowserContextKeyedServiceFactory* service_factory, | 973 BrowserContextKeyedServiceFactory* service_factory, |
971 BrowserContextKeyedServiceFactory::TestingFactoryFunction callback) { | 974 BrowserContextKeyedServiceFactory::TestingFactoryFunction callback) { |
972 testing_factories_.push_back(std::make_pair(service_factory, callback)); | 975 testing_factories_.push_back(std::make_pair(service_factory, callback)); |
973 } | 976 } |
974 | 977 |
975 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() { | 978 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() { |
976 DCHECK(!build_called_); | 979 DCHECK(!build_called_); |
977 build_called_ = true; | 980 build_called_ = true; |
978 | 981 |
979 return scoped_ptr<TestingProfile>(new TestingProfile( | 982 return scoped_ptr<TestingProfile>(new TestingProfile(path_, |
980 path_, | 983 delegate_, |
981 delegate_, | |
982 #if defined(ENABLE_EXTENSIONS) | 984 #if defined(ENABLE_EXTENSIONS) |
983 extension_policy_, | 985 extension_policy_, |
984 #endif | 986 #endif |
985 pref_service_.Pass(), | 987 pref_service_.Pass(), |
986 incognito_, | 988 NULL, |
987 guest_session_, | 989 guest_session_, |
988 supervised_user_id_, | 990 supervised_user_id_, |
989 policy_service_.Pass(), | 991 policy_service_.Pass(), |
990 testing_factories_)); | 992 testing_factories_)); |
991 } | 993 } |
994 | |
995 TestingProfile* TestingProfile::Builder::BuildIncognito( | |
996 TestingProfile* original_profile) { | |
997 DCHECK(!build_called_); | |
998 DCHECK(original_profile); | |
999 build_called_ = true; | |
1000 | |
1001 // Note: Owned by |original_profile|. | |
1002 return new TestingProfile(path_, | |
1003 delegate_, | |
1004 #if defined(ENABLE_EXTENSIONS) | |
1005 extension_policy_, | |
1006 #endif | |
1007 pref_service_.Pass(), | |
1008 original_profile, | |
1009 guest_session_, | |
1010 supervised_user_id_, | |
1011 policy_service_.Pass(), | |
1012 testing_factories_); | |
1013 } | |
OLD | NEW |