| 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/browser/chromeos/policy/device_local_account_policy_provider.h" | 5 #include "chrome/browser/chromeos/policy/device_local_account_policy_provider.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/chromeos/policy/device_local_account.h" | 11 #include "chrome/browser/chromeos/policy/device_local_account.h" |
| 12 #include "chrome/browser/chromeos/policy/device_local_account_external_data_mana
ger.h" | 12 #include "chrome/browser/chromeos/policy/device_local_account_external_data_mana
ger.h" |
| 13 #include "chromeos/dbus/power_policy_controller.h" | 13 #include "chromeos/dbus/power_policy_controller.h" |
| 14 #include "components/policy/core/common/cloud/cloud_policy_core.h" | 14 #include "components/policy/core/common/cloud/cloud_policy_core.h" |
| 15 #include "components/policy/core/common/cloud/cloud_policy_service.h" | 15 #include "components/policy/core/common/cloud/cloud_policy_service.h" |
| 16 #include "components/policy/core/common/cloud/component_cloud_policy_service.h" | 16 #include "components/policy/core/common/cloud/component_cloud_policy_service.h" |
| 17 #include "components/policy/core/common/policy_bundle.h" | 17 #include "components/policy/core/common/policy_bundle.h" |
| 18 #include "components/policy/core/common/policy_map.h" | 18 #include "components/policy/core/common/policy_map.h" |
| 19 #include "components/policy/core/common/policy_namespace.h" | 19 #include "components/policy/core/common/policy_namespace.h" |
| 20 #include "components/policy/core/common/policy_types.h" | 20 #include "components/policy/core/common/policy_types.h" |
| 21 #include "policy/policy_constants.h" | 21 #include "policy/policy_constants.h" |
| 22 | 22 |
| 23 namespace policy { | 23 namespace policy { |
| 24 | 24 |
| 25 DeviceLocalAccountPolicyProvider::DeviceLocalAccountPolicyProvider( | 25 DeviceLocalAccountPolicyProvider::DeviceLocalAccountPolicyProvider( |
| 26 const std::string& user_id, | 26 const std::string& user_id, |
| 27 DeviceLocalAccountPolicyService* service, | 27 DeviceLocalAccountPolicyService* service, |
| 28 scoped_ptr<PolicyMap> chrome_policy_overrides) | 28 std::unique_ptr<PolicyMap> chrome_policy_overrides) |
| 29 : user_id_(user_id), | 29 : user_id_(user_id), |
| 30 service_(service), | 30 service_(service), |
| 31 chrome_policy_overrides_(std::move(chrome_policy_overrides)), | 31 chrome_policy_overrides_(std::move(chrome_policy_overrides)), |
| 32 store_initialized_(false), | 32 store_initialized_(false), |
| 33 waiting_for_policy_refresh_(false), | 33 waiting_for_policy_refresh_(false), |
| 34 weak_factory_(this) { | 34 weak_factory_(this) { |
| 35 service_->AddObserver(this); | 35 service_->AddObserver(this); |
| 36 UpdateFromBroker(); | 36 UpdateFromBroker(); |
| 37 } | 37 } |
| 38 | 38 |
| 39 DeviceLocalAccountPolicyProvider::~DeviceLocalAccountPolicyProvider() { | 39 DeviceLocalAccountPolicyProvider::~DeviceLocalAccountPolicyProvider() { |
| 40 service_->RemoveObserver(this); | 40 service_->RemoveObserver(this); |
| 41 } | 41 } |
| 42 | 42 |
| 43 // static | 43 // static |
| 44 scoped_ptr<DeviceLocalAccountPolicyProvider> | 44 std::unique_ptr<DeviceLocalAccountPolicyProvider> |
| 45 DeviceLocalAccountPolicyProvider::Create( | 45 DeviceLocalAccountPolicyProvider::Create( |
| 46 const std::string& user_id, | 46 const std::string& user_id, |
| 47 DeviceLocalAccountPolicyService* device_local_account_policy_service) { | 47 DeviceLocalAccountPolicyService* device_local_account_policy_service) { |
| 48 DeviceLocalAccount::Type type; | 48 DeviceLocalAccount::Type type; |
| 49 if (!device_local_account_policy_service || | 49 if (!device_local_account_policy_service || |
| 50 !IsDeviceLocalAccountUser(user_id, &type)) { | 50 !IsDeviceLocalAccountUser(user_id, &type)) { |
| 51 return scoped_ptr<DeviceLocalAccountPolicyProvider>(); | 51 return std::unique_ptr<DeviceLocalAccountPolicyProvider>(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 scoped_ptr<PolicyMap> chrome_policy_overrides; | 54 std::unique_ptr<PolicyMap> chrome_policy_overrides; |
| 55 if (type == DeviceLocalAccount::TYPE_PUBLIC_SESSION) { | 55 if (type == DeviceLocalAccount::TYPE_PUBLIC_SESSION) { |
| 56 chrome_policy_overrides.reset(new PolicyMap()); | 56 chrome_policy_overrides.reset(new PolicyMap()); |
| 57 | 57 |
| 58 // Exit the session when the lid is closed. The default behavior is to | 58 // Exit the session when the lid is closed. The default behavior is to |
| 59 // suspend while leaving the session running, which is not desirable for | 59 // suspend while leaving the session running, which is not desirable for |
| 60 // public sessions. | 60 // public sessions. |
| 61 chrome_policy_overrides->Set( | 61 chrome_policy_overrides->Set( |
| 62 key::kLidCloseAction, | 62 key::kLidCloseAction, |
| 63 POLICY_LEVEL_MANDATORY, | 63 POLICY_LEVEL_MANDATORY, |
| 64 POLICY_SCOPE_MACHINE, | 64 POLICY_SCOPE_MACHINE, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 88 // shelf cannot be hidden by entering fullscreen mode. | 88 // shelf cannot be hidden by entering fullscreen mode. |
| 89 chrome_policy_overrides->Set( | 89 chrome_policy_overrides->Set( |
| 90 key::kFullscreenAllowed, | 90 key::kFullscreenAllowed, |
| 91 POLICY_LEVEL_MANDATORY, | 91 POLICY_LEVEL_MANDATORY, |
| 92 POLICY_SCOPE_MACHINE, | 92 POLICY_SCOPE_MACHINE, |
| 93 POLICY_SOURCE_PUBLIC_SESSION_OVERRIDE, | 93 POLICY_SOURCE_PUBLIC_SESSION_OVERRIDE, |
| 94 new base::FundamentalValue(false), | 94 new base::FundamentalValue(false), |
| 95 NULL); | 95 NULL); |
| 96 } | 96 } |
| 97 | 97 |
| 98 scoped_ptr<DeviceLocalAccountPolicyProvider> provider( | 98 std::unique_ptr<DeviceLocalAccountPolicyProvider> provider( |
| 99 new DeviceLocalAccountPolicyProvider(user_id, | 99 new DeviceLocalAccountPolicyProvider(user_id, |
| 100 device_local_account_policy_service, | 100 device_local_account_policy_service, |
| 101 std::move(chrome_policy_overrides))); | 101 std::move(chrome_policy_overrides))); |
| 102 return provider; | 102 return provider; |
| 103 } | 103 } |
| 104 | 104 |
| 105 bool DeviceLocalAccountPolicyProvider::IsInitializationComplete( | 105 bool DeviceLocalAccountPolicyProvider::IsInitializationComplete( |
| 106 PolicyDomain domain) const { | 106 PolicyDomain domain) const { |
| 107 if (domain == POLICY_DOMAIN_CHROME) | 107 if (domain == POLICY_DOMAIN_CHROME) |
| 108 return store_initialized_; | 108 return store_initialized_; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 return service_->GetBrokerForUser(user_id_); | 140 return service_->GetBrokerForUser(user_id_); |
| 141 } | 141 } |
| 142 | 142 |
| 143 void DeviceLocalAccountPolicyProvider::ReportPolicyRefresh(bool success) { | 143 void DeviceLocalAccountPolicyProvider::ReportPolicyRefresh(bool success) { |
| 144 waiting_for_policy_refresh_ = false; | 144 waiting_for_policy_refresh_ = false; |
| 145 UpdateFromBroker(); | 145 UpdateFromBroker(); |
| 146 } | 146 } |
| 147 | 147 |
| 148 void DeviceLocalAccountPolicyProvider::UpdateFromBroker() { | 148 void DeviceLocalAccountPolicyProvider::UpdateFromBroker() { |
| 149 DeviceLocalAccountPolicyBroker* broker = GetBroker(); | 149 DeviceLocalAccountPolicyBroker* broker = GetBroker(); |
| 150 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); | 150 std::unique_ptr<PolicyBundle> bundle(new PolicyBundle()); |
| 151 if (broker) { | 151 if (broker) { |
| 152 store_initialized_ |= broker->core()->store()->is_initialized(); | 152 store_initialized_ |= broker->core()->store()->is_initialized(); |
| 153 if (!waiting_for_policy_refresh_) { | 153 if (!waiting_for_policy_refresh_) { |
| 154 // Copy policy from the broker. | 154 // Copy policy from the broker. |
| 155 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 155 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
| 156 .CopyFrom(broker->core()->store()->policy_map()); | 156 .CopyFrom(broker->core()->store()->policy_map()); |
| 157 external_data_manager_ = broker->external_data_manager(); | 157 external_data_manager_ = broker->external_data_manager(); |
| 158 | 158 |
| 159 if (broker->component_policy_service()) | 159 if (broker->component_policy_service()) |
| 160 bundle->MergeFrom(broker->component_policy_service()->policy()); | 160 bundle->MergeFrom(broker->component_policy_service()->policy()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 183 entry.source, | 183 entry.source, |
| 184 entry.value->DeepCopy(), | 184 entry.value->DeepCopy(), |
| 185 nullptr); | 185 nullptr); |
| 186 } | 186 } |
| 187 } | 187 } |
| 188 | 188 |
| 189 UpdatePolicy(std::move(bundle)); | 189 UpdatePolicy(std::move(bundle)); |
| 190 } | 190 } |
| 191 | 191 |
| 192 } // namespace policy | 192 } // namespace policy |
| OLD | NEW |