| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/browser/policy/profile_policy_connector_factory.h" | 5 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "chrome/browser/policy/profile_policy_connector.h" | 12 #include "chrome/browser/policy/profile_policy_connector.h" |
| 13 #include "chrome/browser/policy/schema_registry_service.h" |
| 14 #include "chrome/browser/policy/schema_registry_service_factory.h" |
| 13 #include "chrome/browser/profiles/incognito_helpers.h" | 15 #include "chrome/browser/profiles/incognito_helpers.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 15 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 17 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 16 #include "components/policy/core/common/policy_service.h" | 18 #include "components/policy/core/common/policy_service.h" |
| 19 #include "components/policy/core/common/policy_service_impl.h" |
| 17 | 20 |
| 18 #if defined(ENABLE_CONFIGURATION_POLICY) | |
| 19 #include "chrome/browser/policy/schema_registry_service.h" | |
| 20 #include "chrome/browser/policy/schema_registry_service_factory.h" | |
| 21 #include "components/policy/core/common/policy_service_impl.h" | |
| 22 #if defined(OS_CHROMEOS) | 21 #if defined(OS_CHROMEOS) |
| 23 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" | 22 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" |
| 24 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" | 23 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" |
| 25 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 24 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 26 #include "components/user_manager/user.h" | 25 #include "components/user_manager/user.h" |
| 27 #else | 26 #else // Non-ChromeOS. |
| 28 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" | 27 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" |
| 29 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h" | 28 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h" |
| 30 #endif | 29 #endif |
| 31 #endif | |
| 32 | 30 |
| 33 namespace policy { | 31 namespace policy { |
| 34 | 32 |
| 35 // static | 33 // static |
| 36 ProfilePolicyConnectorFactory* ProfilePolicyConnectorFactory::GetInstance() { | 34 ProfilePolicyConnectorFactory* ProfilePolicyConnectorFactory::GetInstance() { |
| 37 return base::Singleton<ProfilePolicyConnectorFactory>::get(); | 35 return base::Singleton<ProfilePolicyConnectorFactory>::get(); |
| 38 } | 36 } |
| 39 | 37 |
| 40 // static | 38 // static |
| 41 ProfilePolicyConnector* ProfilePolicyConnectorFactory::GetForBrowserContext( | 39 ProfilePolicyConnector* ProfilePolicyConnectorFactory::GetForBrowserContext( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 53 } | 51 } |
| 54 | 52 |
| 55 void ProfilePolicyConnectorFactory::SetServiceForTesting( | 53 void ProfilePolicyConnectorFactory::SetServiceForTesting( |
| 56 content::BrowserContext* context, | 54 content::BrowserContext* context, |
| 57 ProfilePolicyConnector* connector) { | 55 ProfilePolicyConnector* connector) { |
| 58 ProfilePolicyConnector*& map_entry = connectors_[context]; | 56 ProfilePolicyConnector*& map_entry = connectors_[context]; |
| 59 CHECK(!map_entry); | 57 CHECK(!map_entry); |
| 60 map_entry = connector; | 58 map_entry = connector; |
| 61 } | 59 } |
| 62 | 60 |
| 63 #if defined(ENABLE_CONFIGURATION_POLICY) | |
| 64 void ProfilePolicyConnectorFactory::PushProviderForTesting( | 61 void ProfilePolicyConnectorFactory::PushProviderForTesting( |
| 65 ConfigurationPolicyProvider* provider) { | 62 ConfigurationPolicyProvider* provider) { |
| 66 test_providers_.push_back(provider); | 63 test_providers_.push_back(provider); |
| 67 } | 64 } |
| 68 #endif | |
| 69 | 65 |
| 70 ProfilePolicyConnectorFactory::ProfilePolicyConnectorFactory() | 66 ProfilePolicyConnectorFactory::ProfilePolicyConnectorFactory() |
| 71 : BrowserContextKeyedBaseFactory( | 67 : BrowserContextKeyedBaseFactory( |
| 72 "ProfilePolicyConnector", | 68 "ProfilePolicyConnector", |
| 73 BrowserContextDependencyManager::GetInstance()) { | 69 BrowserContextDependencyManager::GetInstance()) { |
| 74 #if defined(ENABLE_CONFIGURATION_POLICY) | |
| 75 DependsOn(SchemaRegistryServiceFactory::GetInstance()); | 70 DependsOn(SchemaRegistryServiceFactory::GetInstance()); |
| 76 #if defined(OS_CHROMEOS) | 71 #if defined(OS_CHROMEOS) |
| 77 DependsOn(UserCloudPolicyManagerFactoryChromeOS::GetInstance()); | 72 DependsOn(UserCloudPolicyManagerFactoryChromeOS::GetInstance()); |
| 78 #else | 73 #else |
| 79 DependsOn(UserCloudPolicyManagerFactory::GetInstance()); | 74 DependsOn(UserCloudPolicyManagerFactory::GetInstance()); |
| 80 #endif | 75 #endif |
| 81 #endif | |
| 82 } | 76 } |
| 83 | 77 |
| 84 ProfilePolicyConnectorFactory::~ProfilePolicyConnectorFactory() { | 78 ProfilePolicyConnectorFactory::~ProfilePolicyConnectorFactory() { |
| 85 DCHECK(connectors_.empty()); | 79 DCHECK(connectors_.empty()); |
| 86 } | 80 } |
| 87 | 81 |
| 88 ProfilePolicyConnector* | 82 ProfilePolicyConnector* |
| 89 ProfilePolicyConnectorFactory::GetForBrowserContextInternal( | 83 ProfilePolicyConnectorFactory::GetForBrowserContextInternal( |
| 90 content::BrowserContext* context) { | 84 content::BrowserContext* context) { |
| 91 // Get the connector for the original Profile, so that the incognito Profile | 85 // Get the connector for the original Profile, so that the incognito Profile |
| 92 // gets managed settings from the same PolicyService. | 86 // gets managed settings from the same PolicyService. |
| 93 content::BrowserContext* const original_context = | 87 content::BrowserContext* const original_context = |
| 94 chrome::GetBrowserContextRedirectedInIncognito(context); | 88 chrome::GetBrowserContextRedirectedInIncognito(context); |
| 95 const ConnectorMap::const_iterator it = connectors_.find(original_context); | 89 const ConnectorMap::const_iterator it = connectors_.find(original_context); |
| 96 CHECK(it != connectors_.end()); | 90 CHECK(it != connectors_.end()); |
| 97 return it->second; | 91 return it->second; |
| 98 } | 92 } |
| 99 | 93 |
| 100 scoped_ptr<ProfilePolicyConnector> | 94 scoped_ptr<ProfilePolicyConnector> |
| 101 ProfilePolicyConnectorFactory::CreateForBrowserContextInternal( | 95 ProfilePolicyConnectorFactory::CreateForBrowserContextInternal( |
| 102 content::BrowserContext* context, | 96 content::BrowserContext* context, |
| 103 bool force_immediate_load) { | 97 bool force_immediate_load) { |
| 104 DCHECK(connectors_.find(context) == connectors_.end()); | 98 DCHECK(connectors_.find(context) == connectors_.end()); |
| 105 | 99 |
| 106 #if defined(ENABLE_CONFIGURATION_POLICY) | |
| 107 SchemaRegistry* schema_registry = nullptr; | 100 SchemaRegistry* schema_registry = nullptr; |
| 108 CloudPolicyManager* user_cloud_policy_manager = nullptr; | 101 CloudPolicyManager* user_cloud_policy_manager = nullptr; |
| 109 | 102 |
| 110 schema_registry = | 103 schema_registry = |
| 111 SchemaRegistryServiceFactory::GetForContext(context)->registry(); | 104 SchemaRegistryServiceFactory::GetForContext(context)->registry(); |
| 112 | 105 |
| 113 #if defined(OS_CHROMEOS) | 106 #if defined(OS_CHROMEOS) |
| 114 Profile* const profile = Profile::FromBrowserContext(context); | 107 Profile* const profile = Profile::FromBrowserContext(context); |
| 115 const user_manager::User* user = nullptr; | 108 const user_manager::User* user = nullptr; |
| 116 if (!chromeos::ProfileHelper::IsSigninProfile(profile)) { | 109 if (!chromeos::ProfileHelper::IsSigninProfile(profile)) { |
| 117 user = chromeos::ProfileHelper::Get()->GetUserByProfile(profile); | 110 user = chromeos::ProfileHelper::Get()->GetUserByProfile(profile); |
| 118 CHECK(user); | 111 CHECK(user); |
| 119 } | 112 } |
| 120 user_cloud_policy_manager = | 113 user_cloud_policy_manager = |
| 121 UserCloudPolicyManagerFactoryChromeOS::GetForProfile(profile); | 114 UserCloudPolicyManagerFactoryChromeOS::GetForProfile(profile); |
| 122 #else | 115 #else |
| 123 user_cloud_policy_manager = | 116 user_cloud_policy_manager = |
| 124 UserCloudPolicyManagerFactory::GetForBrowserContext(context); | 117 UserCloudPolicyManagerFactory::GetForBrowserContext(context); |
| 125 #endif // defined(OS_CHROMEOS) | 118 #endif // defined(OS_CHROMEOS) |
| 126 #endif // defined(ENABLE_CONFIGURATION_POLICY) | |
| 127 | 119 |
| 128 scoped_ptr<ProfilePolicyConnector> connector(new ProfilePolicyConnector()); | 120 scoped_ptr<ProfilePolicyConnector> connector(new ProfilePolicyConnector()); |
| 129 | 121 |
| 130 #if defined(ENABLE_CONFIGURATION_POLICY) | |
| 131 if (test_providers_.empty()) { | 122 if (test_providers_.empty()) { |
| 132 connector->Init( | 123 connector->Init( |
| 133 #if defined(OS_CHROMEOS) | 124 #if defined(OS_CHROMEOS) |
| 134 user, | 125 user, |
| 135 #endif | 126 #endif |
| 136 schema_registry, user_cloud_policy_manager); | 127 schema_registry, user_cloud_policy_manager); |
| 137 } else { | 128 } else { |
| 138 PolicyServiceImpl::Providers providers; | 129 PolicyServiceImpl::Providers providers; |
| 139 providers.push_back(test_providers_.front()); | 130 providers.push_back(test_providers_.front()); |
| 140 test_providers_.pop_front(); | 131 test_providers_.pop_front(); |
| 141 scoped_ptr<PolicyService> service(new PolicyServiceImpl(providers)); | 132 scoped_ptr<PolicyService> service(new PolicyServiceImpl(providers)); |
| 142 connector->InitForTesting(std::move(service)); | 133 connector->InitForTesting(std::move(service)); |
| 143 } | 134 } |
| 144 #else | |
| 145 connector->Init(nullptr, nullptr); | |
| 146 #endif | |
| 147 | 135 |
| 148 connectors_[context] = connector.get(); | 136 connectors_[context] = connector.get(); |
| 149 return connector; | 137 return connector; |
| 150 } | 138 } |
| 151 | 139 |
| 152 void ProfilePolicyConnectorFactory::BrowserContextShutdown( | 140 void ProfilePolicyConnectorFactory::BrowserContextShutdown( |
| 153 content::BrowserContext* context) { | 141 content::BrowserContext* context) { |
| 154 if (Profile::FromBrowserContext(context)->IsOffTheRecord()) | 142 if (Profile::FromBrowserContext(context)->IsOffTheRecord()) |
| 155 return; | 143 return; |
| 156 const ConnectorMap::const_iterator it = connectors_.find(context); | 144 const ConnectorMap::const_iterator it = connectors_.find(context); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 171 | 159 |
| 172 bool ProfilePolicyConnectorFactory::HasTestingFactory( | 160 bool ProfilePolicyConnectorFactory::HasTestingFactory( |
| 173 content::BrowserContext* context) { | 161 content::BrowserContext* context) { |
| 174 return false; | 162 return false; |
| 175 } | 163 } |
| 176 | 164 |
| 177 void ProfilePolicyConnectorFactory::CreateServiceNow( | 165 void ProfilePolicyConnectorFactory::CreateServiceNow( |
| 178 content::BrowserContext* context) {} | 166 content::BrowserContext* context) {} |
| 179 | 167 |
| 180 } // namespace policy | 168 } // namespace policy |
| OLD | NEW |