| 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 23 matching lines...) Expand all Loading... |
| 34 #include "chrome/browser/history/history_service.h" | 34 #include "chrome/browser/history/history_service.h" |
| 35 #include "chrome/browser/history/history_service_factory.h" | 35 #include "chrome/browser/history/history_service_factory.h" |
| 36 #include "chrome/browser/history/shortcuts_backend.h" | 36 #include "chrome/browser/history/shortcuts_backend.h" |
| 37 #include "chrome/browser/history/shortcuts_backend_factory.h" | 37 #include "chrome/browser/history/shortcuts_backend_factory.h" |
| 38 #include "chrome/browser/history/top_sites.h" | 38 #include "chrome/browser/history/top_sites.h" |
| 39 #include "chrome/browser/history/web_history_service_factory.h" | 39 #include "chrome/browser/history/web_history_service_factory.h" |
| 40 #include "chrome/browser/net/pref_proxy_config_tracker.h" | 40 #include "chrome/browser/net/pref_proxy_config_tracker.h" |
| 41 #include "chrome/browser/net/proxy_service_factory.h" | 41 #include "chrome/browser/net/proxy_service_factory.h" |
| 42 #include "chrome/browser/notifications/desktop_notification_service.h" | 42 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 43 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 43 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 44 #include "chrome/browser/policy/policy_service.h" |
| 44 #include "chrome/browser/policy/profile_policy_connector.h" | 45 #include "chrome/browser/policy/profile_policy_connector.h" |
| 45 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 46 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 46 #include "chrome/browser/prefs/browser_prefs.h" | 47 #include "chrome/browser/prefs/browser_prefs.h" |
| 47 #include "chrome/browser/prefs/pref_service_syncable.h" | 48 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 48 #include "chrome/browser/prerender/prerender_manager.h" | 49 #include "chrome/browser/prerender/prerender_manager.h" |
| 49 #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h" | 50 #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h" |
| 50 #include "chrome/browser/profiles/profile_manager.h" | 51 #include "chrome/browser/profiles/profile_manager.h" |
| 51 #include "chrome/browser/profiles/storage_partition_descriptor.h" | 52 #include "chrome/browser/profiles/storage_partition_descriptor.h" |
| 52 #include "chrome/browser/search_engines/template_url_fetcher_factory.h" | 53 #include "chrome/browser/search_engines/template_url_fetcher_factory.h" |
| 53 #include "chrome/browser/webdata/web_data_service.h" | 54 #include "chrome/browser/webdata/web_data_service.h" |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 } | 227 } |
| 227 } | 228 } |
| 228 | 229 |
| 229 TestingProfile::TestingProfile( | 230 TestingProfile::TestingProfile( |
| 230 const base::FilePath& path, | 231 const base::FilePath& path, |
| 231 Delegate* delegate, | 232 Delegate* delegate, |
| 232 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy, | 233 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy, |
| 233 scoped_ptr<PrefServiceSyncable> prefs, | 234 scoped_ptr<PrefServiceSyncable> prefs, |
| 234 bool incognito, | 235 bool incognito, |
| 235 const std::string& managed_user_id, | 236 const std::string& managed_user_id, |
| 237 scoped_ptr<policy::PolicyService> policy_service, |
| 236 const TestingFactories& factories) | 238 const TestingFactories& factories) |
| 237 : start_time_(Time::Now()), | 239 : start_time_(Time::Now()), |
| 238 prefs_(prefs.release()), | 240 prefs_(prefs.release()), |
| 239 testing_prefs_(NULL), | 241 testing_prefs_(NULL), |
| 240 incognito_(incognito), | 242 incognito_(incognito), |
| 241 force_incognito_(false), | 243 force_incognito_(false), |
| 242 original_profile_(NULL), | 244 original_profile_(NULL), |
| 243 managed_user_id_(managed_user_id), | 245 managed_user_id_(managed_user_id), |
| 244 last_session_exited_cleanly_(true), | 246 last_session_exited_cleanly_(true), |
| 245 extension_special_storage_policy_(extension_policy), | 247 extension_special_storage_policy_(extension_policy), |
| 246 profile_path_(path), | 248 profile_path_(path), |
| 247 browser_context_dependency_manager_( | 249 browser_context_dependency_manager_( |
| 248 BrowserContextDependencyManager::GetInstance()), | 250 BrowserContextDependencyManager::GetInstance()), |
| 249 resource_context_(NULL), | 251 resource_context_(NULL), |
| 250 delegate_(delegate) { | 252 delegate_(delegate), |
| 253 policy_service_(policy_service.release()) { |
| 251 | 254 |
| 252 // If no profile path was supplied, create one. | 255 // If no profile path was supplied, create one. |
| 253 if (profile_path_.empty()) { | 256 if (profile_path_.empty()) { |
| 254 CreateTempProfileDir(); | 257 CreateTempProfileDir(); |
| 255 profile_path_ = temp_dir_.path(); | 258 profile_path_ = temp_dir_.path(); |
| 256 } | 259 } |
| 257 | 260 |
| 258 // Set any testing factories prior to initializing the services. | 261 // Set any testing factories prior to initializing the services. |
| 259 for (TestingFactories::const_iterator it = factories.begin(); | 262 for (TestingFactories::const_iterator it = factories.begin(); |
| 260 it != factories.end(); ++it) { | 263 it != factories.end(); ++it) { |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 | 624 |
| 622 void TestingProfile::CreateTestingPrefService() { | 625 void TestingProfile::CreateTestingPrefService() { |
| 623 DCHECK(!prefs_.get()); | 626 DCHECK(!prefs_.get()); |
| 624 testing_prefs_ = new TestingPrefServiceSyncable(); | 627 testing_prefs_ = new TestingPrefServiceSyncable(); |
| 625 prefs_.reset(testing_prefs_); | 628 prefs_.reset(testing_prefs_); |
| 626 user_prefs::UserPrefs::Set(this, prefs_.get()); | 629 user_prefs::UserPrefs::Set(this, prefs_.get()); |
| 627 chrome::RegisterUserProfilePrefs(testing_prefs_->registry()); | 630 chrome::RegisterUserProfilePrefs(testing_prefs_->registry()); |
| 628 } | 631 } |
| 629 | 632 |
| 630 void TestingProfile::CreateProfilePolicyConnector() { | 633 void TestingProfile::CreateProfilePolicyConnector() { |
| 631 scoped_ptr<policy::PolicyService> service; | |
| 632 #if defined(ENABLE_CONFIGURATION_POLICY) | 634 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 633 schema_registry_service_ = | 635 schema_registry_service_ = |
| 634 policy::SchemaRegistryServiceFactory::CreateForContext( | 636 policy::SchemaRegistryServiceFactory::CreateForContext( |
| 635 this, policy::Schema(), NULL); | 637 this, policy::Schema(), NULL); |
| 636 CHECK_EQ(schema_registry_service_.get(), | 638 CHECK_EQ(schema_registry_service_.get(), |
| 637 policy::SchemaRegistryServiceFactory::GetForContext(this)); | 639 policy::SchemaRegistryServiceFactory::GetForContext(this)); |
| 640 #endif // defined(ENABLE_CONFIGURATION_POLICY) |
| 638 | 641 |
| 639 std::vector<policy::ConfigurationPolicyProvider*> providers; | 642 if (!policy_service_) { |
| 640 service.reset(new policy::PolicyServiceImpl( | 643 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 641 providers, policy::PolicyServiceImpl::PreprocessCallback())); | 644 std::vector<policy::ConfigurationPolicyProvider*> providers; |
| 645 policy_service_.reset(new policy::PolicyServiceImpl( |
| 646 providers, policy::PolicyServiceImpl::PreprocessCallback())); |
| 642 #else | 647 #else |
| 643 service.reset(new policy::PolicyServiceStub()); | 648 policy_service_.reset(new policy::PolicyServiceStub()); |
| 644 #endif | 649 #endif |
| 650 } |
| 645 profile_policy_connector_.reset(new policy::ProfilePolicyConnector()); | 651 profile_policy_connector_.reset(new policy::ProfilePolicyConnector()); |
| 646 profile_policy_connector_->InitForTesting(service.Pass()); | 652 profile_policy_connector_->InitForTesting(policy_service_.Pass()); |
| 647 policy::ProfilePolicyConnectorFactory::GetInstance()->SetServiceForTesting( | 653 policy::ProfilePolicyConnectorFactory::GetInstance()->SetServiceForTesting( |
| 648 this, profile_policy_connector_.get()); | 654 this, profile_policy_connector_.get()); |
| 649 CHECK_EQ(profile_policy_connector_.get(), | 655 CHECK_EQ(profile_policy_connector_.get(), |
| 650 policy::ProfilePolicyConnectorFactory::GetForProfile(this)); | 656 policy::ProfilePolicyConnectorFactory::GetForProfile(this)); |
| 651 } | 657 } |
| 652 | 658 |
| 653 PrefService* TestingProfile::GetPrefs() { | 659 PrefService* TestingProfile::GetPrefs() { |
| 654 if (!prefs_.get()) { | 660 if (!prefs_.get()) { |
| 655 CreateTestingPrefService(); | 661 CreateTestingPrefService(); |
| 656 } | 662 } |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 879 | 885 |
| 880 void TestingProfile::Builder::SetIncognito() { | 886 void TestingProfile::Builder::SetIncognito() { |
| 881 incognito_ = true; | 887 incognito_ = true; |
| 882 } | 888 } |
| 883 | 889 |
| 884 void TestingProfile::Builder::SetManagedUserId( | 890 void TestingProfile::Builder::SetManagedUserId( |
| 885 const std::string& managed_user_id) { | 891 const std::string& managed_user_id) { |
| 886 managed_user_id_ = managed_user_id; | 892 managed_user_id_ = managed_user_id; |
| 887 } | 893 } |
| 888 | 894 |
| 895 void TestingProfile::Builder::SetPolicyService( |
| 896 scoped_ptr<policy::PolicyService> policy_service) { |
| 897 policy_service_ = policy_service.Pass(); |
| 898 } |
| 899 |
| 889 void TestingProfile::Builder::AddTestingFactory( | 900 void TestingProfile::Builder::AddTestingFactory( |
| 890 BrowserContextKeyedServiceFactory* service_factory, | 901 BrowserContextKeyedServiceFactory* service_factory, |
| 891 BrowserContextKeyedServiceFactory::FactoryFunction callback) { | 902 BrowserContextKeyedServiceFactory::FactoryFunction callback) { |
| 892 testing_factories_.push_back(std::make_pair(service_factory, callback)); | 903 testing_factories_.push_back(std::make_pair(service_factory, callback)); |
| 893 } | 904 } |
| 894 | 905 |
| 895 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() { | 906 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() { |
| 896 DCHECK(!build_called_); | 907 DCHECK(!build_called_); |
| 897 build_called_ = true; | 908 build_called_ = true; |
| 898 | 909 |
| 899 return scoped_ptr<TestingProfile>(new TestingProfile( | 910 return scoped_ptr<TestingProfile>(new TestingProfile( |
| 900 path_, | 911 path_, |
| 901 delegate_, | 912 delegate_, |
| 902 extension_policy_, | 913 extension_policy_, |
| 903 pref_service_.Pass(), | 914 pref_service_.Pass(), |
| 904 incognito_, | 915 incognito_, |
| 905 managed_user_id_, | 916 managed_user_id_, |
| 917 policy_service_.Pass(), |
| 906 testing_factories_)); | 918 testing_factories_)); |
| 907 } | 919 } |
| OLD | NEW |