| 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.h" | 5 #include "chrome/browser/policy/profile_policy_connector.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "components/policy/core/browser/browser_policy_connector.h" | 14 #include "components/policy/core/browser/browser_policy_connector.h" |
| 15 #include "components/policy/core/common/cloud/cloud_policy_core.h" | 15 #include "components/policy/core/common/cloud/cloud_policy_core.h" |
| 16 #include "components/policy/core/common/cloud/cloud_policy_manager.h" | 16 #include "components/policy/core/common/cloud/cloud_policy_manager.h" |
| 17 #include "components/policy/core/common/cloud/cloud_policy_store.h" | 17 #include "components/policy/core/common/cloud/cloud_policy_store.h" |
| 18 #include "components/policy/core/common/configuration_policy_provider.h" | 18 #include "components/policy/core/common/configuration_policy_provider.h" |
| 19 #include "components/policy/core/common/policy_bundle.h" | 19 #include "components/policy/core/common/policy_bundle.h" |
| 20 #include "components/policy/core/common/policy_map.h" | 20 #include "components/policy/core/common/policy_map.h" |
| 21 #include "components/policy/core/common/policy_namespace.h" | 21 #include "components/policy/core/common/policy_namespace.h" |
| 22 #include "components/policy/core/common/policy_service_impl.h" | 22 #include "components/policy/core/common/policy_service_impl.h" |
| 23 #include "components/policy/core/common/schema_registry_tracking_policy_provider
.h" | 23 #include "components/policy/core/common/schema_registry_tracking_policy_provider
.h" |
| 24 #include "components/policy/policy_constants.h" |
| 24 #include "google_apis/gaia/gaia_auth_util.h" | 25 #include "google_apis/gaia/gaia_auth_util.h" |
| 25 | 26 |
| 26 #if defined(OS_CHROMEOS) | 27 #if defined(OS_CHROMEOS) |
| 27 #include "chrome/browser/browser_process_platform_part.h" | 28 #include "chrome/browser/browser_process_platform_part.h" |
| 28 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 29 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 29 #include "chrome/browser/chromeos/policy/device_active_directory_policy_manager.
h" | 30 #include "chrome/browser/chromeos/policy/device_active_directory_policy_manager.
h" |
| 30 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" | 31 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" |
| 31 #include "chrome/browser/chromeos/policy/device_local_account.h" | 32 #include "chrome/browser/chromeos/policy/device_local_account.h" |
| 32 #include "chrome/browser/chromeos/policy/device_local_account_policy_provider.h" | 33 #include "chrome/browser/chromeos/policy/device_local_account_policy_provider.h" |
| 33 #include "chrome/browser/chromeos/policy/login_profile_policy_provider.h" | 34 #include "chrome/browser/chromeos/policy/login_profile_policy_provider.h" |
| 35 #include "chrome/browser/chromeos/policy/user_active_directory_policy_manager.h" |
| 34 #include "components/user_manager/user.h" | 36 #include "components/user_manager/user.h" |
| 35 #include "components/user_manager/user_manager.h" | 37 #include "components/user_manager/user_manager.h" |
| 36 #endif | 38 #endif |
| 37 | 39 |
| 38 namespace policy { | 40 namespace policy { |
| 39 | 41 |
| 40 namespace { | 42 namespace { |
| 41 | 43 |
| 42 std::string GetCloudPolicyManagementDomain( | 44 std::string GetStoreManagementDomain(const CloudPolicyStore* policy_store) { |
| 43 const CloudPolicyManager* cloud_policy_manager) { | 45 if (policy_store) { |
| 44 const CloudPolicyStore* const store = cloud_policy_manager->core()->store(); | 46 CHECK(policy_store->is_initialized()) |
| 45 if (store) { | |
| 46 CHECK(store->is_initialized()) | |
| 47 << "Cloud policy management domain must be " | 47 << "Cloud policy management domain must be " |
| 48 "requested only after the policy system is fully initialized"; | 48 "requested only after the policy system is fully initialized"; |
| 49 if (store->is_managed() && store->policy()->has_username()) | 49 if (policy_store->is_managed() && policy_store->policy()->has_username()) |
| 50 return gaia::ExtractDomainName(store->policy()->username()); | 50 return gaia::ExtractDomainName(policy_store->policy()->username()); |
| 51 } | 51 } |
| 52 return ""; | 52 return std::string(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 } // namespace | 55 } // namespace |
| 56 | 56 |
| 57 ProfilePolicyConnector::ProfilePolicyConnector() | 57 ProfilePolicyConnector::ProfilePolicyConnector() {} |
| 58 #if defined(OS_CHROMEOS) | |
| 59 : is_primary_user_(false), | |
| 60 user_cloud_policy_manager_(nullptr) | |
| 61 #else | |
| 62 : user_cloud_policy_manager_(nullptr) | |
| 63 #endif | |
| 64 { | |
| 65 } | |
| 66 | 58 |
| 67 ProfilePolicyConnector::~ProfilePolicyConnector() {} | 59 ProfilePolicyConnector::~ProfilePolicyConnector() {} |
| 68 | 60 |
| 69 void ProfilePolicyConnector::Init( | 61 void ProfilePolicyConnector::Init( |
| 70 #if defined(OS_CHROMEOS) | |
| 71 const user_manager::User* user, | 62 const user_manager::User* user, |
| 72 #endif | |
| 73 SchemaRegistry* schema_registry, | 63 SchemaRegistry* schema_registry, |
| 74 CloudPolicyManager* user_cloud_policy_manager) { | 64 ConfigurationPolicyProvider* configuration_policy_provider, |
| 75 user_cloud_policy_manager_ = user_cloud_policy_manager; | 65 const CloudPolicyStore* policy_store) { |
| 66 configuration_policy_provider_ = configuration_policy_provider; |
| 67 policy_store_ = policy_store; |
| 76 | 68 |
| 77 #if defined(OS_CHROMEOS) | 69 #if defined(OS_CHROMEOS) |
| 78 BrowserPolicyConnectorChromeOS* connector = | 70 BrowserPolicyConnectorChromeOS* connector = |
| 79 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 71 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 80 #else | 72 #else |
| 73 DCHECK_EQ(nullptr, user); |
| 81 BrowserPolicyConnector* connector = | 74 BrowserPolicyConnector* connector = |
| 82 g_browser_process->browser_policy_connector(); | 75 g_browser_process->browser_policy_connector(); |
| 83 #endif | 76 #endif |
| 84 | 77 |
| 85 if (connector->GetPlatformProvider()) { | 78 if (connector->GetPlatformProvider()) { |
| 86 wrapped_platform_policy_provider_.reset( | 79 wrapped_platform_policy_provider_.reset( |
| 87 new SchemaRegistryTrackingPolicyProvider( | 80 new SchemaRegistryTrackingPolicyProvider( |
| 88 connector->GetPlatformProvider())); | 81 connector->GetPlatformProvider())); |
| 89 wrapped_platform_policy_provider_->Init(schema_registry); | 82 wrapped_platform_policy_provider_->Init(schema_registry); |
| 90 policy_providers_.push_back(wrapped_platform_policy_provider_.get()); | 83 policy_providers_.push_back(wrapped_platform_policy_provider_.get()); |
| 91 } | 84 } |
| 92 | 85 |
| 93 #if defined(OS_CHROMEOS) | 86 #if defined(OS_CHROMEOS) |
| 94 if (connector->GetDeviceCloudPolicyManager()) { | 87 if (connector->GetDeviceCloudPolicyManager()) { |
| 95 policy_providers_.push_back(connector->GetDeviceCloudPolicyManager()); | 88 policy_providers_.push_back(connector->GetDeviceCloudPolicyManager()); |
| 96 } | 89 } |
| 97 if (connector->GetDeviceActiveDirectoryPolicyManager()) { | 90 if (connector->GetDeviceActiveDirectoryPolicyManager()) { |
| 98 policy_providers_.push_back( | 91 policy_providers_.push_back( |
| 99 connector->GetDeviceActiveDirectoryPolicyManager()); | 92 connector->GetDeviceActiveDirectoryPolicyManager()); |
| 100 } | 93 } |
| 101 #endif | 94 #endif |
| 102 | 95 |
| 103 if (user_cloud_policy_manager) | 96 if (configuration_policy_provider) |
| 104 policy_providers_.push_back(user_cloud_policy_manager); | 97 policy_providers_.push_back(configuration_policy_provider); |
| 105 | 98 |
| 106 #if defined(OS_CHROMEOS) | 99 #if defined(OS_CHROMEOS) |
| 107 if (!user) { | 100 if (!user) { |
| 108 DCHECK(schema_registry); | 101 DCHECK(schema_registry); |
| 109 // This case occurs for the signin profile. | 102 // This case occurs for the signin profile. |
| 110 special_user_policy_provider_.reset( | 103 special_user_policy_provider_.reset( |
| 111 new LoginProfilePolicyProvider(connector->GetPolicyService())); | 104 new LoginProfilePolicyProvider(connector->GetPolicyService())); |
| 112 } else { | 105 } else { |
| 113 // |user| should never be nullptr except for the signin profile. | 106 // |user| should never be nullptr except for the signin profile. |
| 114 is_primary_user_ = | 107 is_primary_user_ = |
| 115 user == user_manager::UserManager::Get()->GetPrimaryUser(); | 108 user == user_manager::UserManager::Get()->GetPrimaryUser(); |
| 116 // Note that |DeviceLocalAccountPolicyProvider::Create| returns nullptr when | 109 // Note that |DeviceLocalAccountPolicyProvider::Create| returns nullptr when |
| 117 // the user supplied is not a device-local account user. | 110 // the user supplied is not a device-local account user. |
| 118 special_user_policy_provider_ = DeviceLocalAccountPolicyProvider::Create( | 111 special_user_policy_provider_ = DeviceLocalAccountPolicyProvider::Create( |
| 119 user->GetAccountId().GetUserEmail(), | 112 user->GetAccountId().GetUserEmail(), |
| 120 connector->GetDeviceLocalAccountPolicyService()); | 113 connector->GetDeviceLocalAccountPolicyService()); |
| 121 } | 114 } |
| 122 if (special_user_policy_provider_) { | 115 if (special_user_policy_provider_) { |
| 123 special_user_policy_provider_->Init(schema_registry); | 116 special_user_policy_provider_->Init(schema_registry); |
| 124 policy_providers_.push_back(special_user_policy_provider_.get()); | 117 policy_providers_.push_back(special_user_policy_provider_.get()); |
| 125 } | 118 } |
| 126 #endif | 119 #endif |
| 127 | 120 |
| 128 policy_service_.reset(new PolicyServiceImpl(policy_providers_)); | 121 policy_service_.reset(new PolicyServiceImpl(policy_providers_)); |
| 129 | 122 |
| 130 #if defined(OS_CHROMEOS) | 123 #if defined(OS_CHROMEOS) |
| 131 if (is_primary_user_) { | 124 if (is_primary_user_) { |
| 132 if (user_cloud_policy_manager) | 125 if (configuration_policy_provider) |
| 133 connector->SetUserPolicyDelegate(user_cloud_policy_manager); | 126 connector->SetUserPolicyDelegate(configuration_policy_provider); |
| 134 else if (special_user_policy_provider_) | 127 else if (special_user_policy_provider_) |
| 135 connector->SetUserPolicyDelegate(special_user_policy_provider_.get()); | 128 connector->SetUserPolicyDelegate(special_user_policy_provider_.get()); |
| 136 } | 129 } |
| 137 #endif | 130 #endif |
| 138 } | 131 } |
| 139 | 132 |
| 140 void ProfilePolicyConnector::InitForTesting( | 133 void ProfilePolicyConnector::InitForTesting( |
| 141 std::unique_ptr<PolicyService> service) { | 134 std::unique_ptr<PolicyService> service) { |
| 142 policy_service_ = std::move(service); | 135 policy_service_ = std::move(service); |
| 143 } | 136 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 156 if (special_user_policy_provider_) | 149 if (special_user_policy_provider_) |
| 157 special_user_policy_provider_->Shutdown(); | 150 special_user_policy_provider_->Shutdown(); |
| 158 #endif | 151 #endif |
| 159 if (wrapped_platform_policy_provider_) | 152 if (wrapped_platform_policy_provider_) |
| 160 wrapped_platform_policy_provider_->Shutdown(); | 153 wrapped_platform_policy_provider_->Shutdown(); |
| 161 } | 154 } |
| 162 | 155 |
| 163 bool ProfilePolicyConnector::IsManaged() const { | 156 bool ProfilePolicyConnector::IsManaged() const { |
| 164 if (is_managed_override_) | 157 if (is_managed_override_) |
| 165 return *is_managed_override_; | 158 return *is_managed_override_; |
| 166 return !GetManagementDomain().empty(); | 159 return policy_store_ && policy_store_->is_managed(); |
| 160 } |
| 161 |
| 162 std::string ProfilePolicyConnector::GetDisplayDomainForManagedBookmarks() |
| 163 const { |
| 164 if (!IsProfilePolicy(policy::key::kManagedBookmarks)) |
| 165 return std::string(); |
| 166 return GetManagementDomain(); |
| 167 } | 167 } |
| 168 | 168 |
| 169 std::string ProfilePolicyConnector::GetManagementDomain() const { | 169 std::string ProfilePolicyConnector::GetManagementDomain() const { |
| 170 if (user_cloud_policy_manager_) | 170 if (policy_store_) |
| 171 return GetCloudPolicyManagementDomain(user_cloud_policy_manager_); | 171 return GetStoreManagementDomain(policy_store_); |
| 172 #if defined(OS_CHROMEOS) | 172 #if defined(OS_CHROMEOS) |
| 173 if (special_user_policy_provider_) { | 173 if (special_user_policy_provider_) { |
| 174 // |special_user_policy_provider_| is non-null for device-local accounts and | 174 // |special_user_policy_provider_| is non-null for device-local accounts and |
| 175 // for the login profile. | 175 // for the login profile. |
| 176 // They receive policy iff the device itself is managed. | 176 // They receive policy iff the device itself is managed. |
| 177 const DeviceCloudPolicyManagerChromeOS* const device_cloud_policy_manager = | 177 const DeviceCloudPolicyManagerChromeOS* const device_cloud_policy_manager = |
| 178 g_browser_process->platform_part() | 178 g_browser_process->platform_part() |
| 179 ->browser_policy_connector_chromeos() | 179 ->browser_policy_connector_chromeos() |
| 180 ->GetDeviceCloudPolicyManager(); | 180 ->GetDeviceCloudPolicyManager(); |
| 181 // The device_cloud_policy_manager can be a nullptr in unit tests. | 181 // The device_cloud_policy_manager can be a nullptr in unit tests. |
| 182 if (device_cloud_policy_manager) | 182 if (device_cloud_policy_manager) |
| 183 return GetCloudPolicyManagementDomain(device_cloud_policy_manager); | 183 return GetStoreManagementDomain( |
| 184 device_cloud_policy_manager->core()->store()); |
| 184 } | 185 } |
| 185 #endif | 186 #endif |
| 186 return ""; | 187 return std::string(); |
| 187 } | 188 } |
| 188 | 189 |
| 189 bool ProfilePolicyConnector::IsPolicyFromCloudPolicy(const char* name) const { | 190 bool ProfilePolicyConnector::IsProfilePolicy(const char* name) const { |
| 190 const ConfigurationPolicyProvider* const provider = | 191 const ConfigurationPolicyProvider* const provider = |
| 191 DeterminePolicyProviderForPolicy(name); | 192 DeterminePolicyProviderForPolicy(name); |
| 192 return provider == user_cloud_policy_manager_; | 193 return (provider == configuration_policy_provider_); |
| 193 } | 194 } |
| 194 | 195 |
| 195 const ConfigurationPolicyProvider* | 196 const ConfigurationPolicyProvider* |
| 196 ProfilePolicyConnector::DeterminePolicyProviderForPolicy( | 197 ProfilePolicyConnector::DeterminePolicyProviderForPolicy( |
| 197 const char* name) const { | 198 const char* name) const { |
| 198 const PolicyNamespace chrome_ns(POLICY_DOMAIN_CHROME, ""); | 199 const PolicyNamespace chrome_ns(POLICY_DOMAIN_CHROME, ""); |
| 199 for (const ConfigurationPolicyProvider* provider : policy_providers_) { | 200 for (const ConfigurationPolicyProvider* provider : policy_providers_) { |
| 200 if (provider->policies().Get(chrome_ns).Get(name)) | 201 if (provider->policies().Get(chrome_ns).Get(name)) |
| 201 return provider; | 202 return provider; |
| 202 } | 203 } |
| 203 return nullptr; | 204 return nullptr; |
| 204 } | 205 } |
| 205 | 206 |
| 206 } // namespace policy | 207 } // namespace policy |
| OLD | NEW |