Chromium Code Reviews| Index: chrome/browser/chromeos/policy/device_ad_policy_manager.cc |
| diff --git a/chrome/browser/chromeos/policy/device_ad_policy_manager.cc b/chrome/browser/chromeos/policy/device_ad_policy_manager.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..49912bf8da42cb44f5b320a20b903ca9576f6933 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/policy/device_ad_policy_manager.cc |
| @@ -0,0 +1,75 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/chromeos/policy/device_ad_policy_manager.h" |
| + |
| +#include <utility> |
| + |
| +#include "base/memory/ptr_util.h" |
| + |
| +namespace policy { |
| + |
| +DeviceADPolicyManager::DeviceADPolicyManager( |
| + std::unique_ptr<CloudPolicyStore> store) |
| + : store_(std::move(store)) {} |
| + |
| +DeviceADPolicyManager::~DeviceADPolicyManager() {} |
| + |
| +void DeviceADPolicyManager::Init(SchemaRegistry* registry) { |
| + ConfigurationPolicyProvider::Init(registry); |
| + |
| + store_->AddObserver(this); |
| + PublishPolicy(); |
| + if (!store_->is_initialized()) { |
| + store_->Load(); |
| + } |
| +} |
| + |
| +void DeviceADPolicyManager::Shutdown() { |
| + store_->RemoveObserver(this); |
| + ConfigurationPolicyProvider::Shutdown(); |
| +} |
| + |
| +bool DeviceADPolicyManager::IsInitializationComplete( |
| + PolicyDomain domain) const { |
| + if (domain == POLICY_DOMAIN_CHROME) |
| + return store_->is_initialized(); |
| + return true; |
| +} |
| + |
| +void DeviceADPolicyManager::RefreshPolicies() { |
| + store_->Load(); |
| +} |
| + |
| +void DeviceADPolicyManager::OnStoreLoaded( |
| + CloudPolicyStore* cloud_policy_store) { |
| + DCHECK_EQ(store_.get(), cloud_policy_store); |
|
emaxx
2016/11/11 15:25:08
nit: #include "base/logging.h"
Thiemo Nagel
2016/11/16 19:11:01
Done.
|
| + PublishPolicy(); |
| +} |
| + |
| +void DeviceADPolicyManager::OnStoreError(CloudPolicyStore* cloud_policy_store) { |
| + DCHECK_EQ(store_.get(), cloud_policy_store); |
| + // Publish policy (even though it hasn't changed) in order to signal load |
| + // complete on the ConfigurationPolicyProvider interface. Technically, this is |
| + // only required on the first load, but doesn't hurt in any case. |
| + PublishPolicy(); |
| +} |
| + |
| +void DeviceADPolicyManager::PublishPolicy() { |
| + if (!store_->is_initialized()) { |
| + return; |
| + } |
| + std::unique_ptr<PolicyBundle> bundle = base::MakeUnique<PolicyBundle>(); |
|
emaxx
2016/11/11 15:25:08
nit: #include "components/policy/core/common/polic
Thiemo Nagel
2016/11/16 19:11:01
Done.
|
| + PolicyMap& policy_map = |
| + bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); |
|
emaxx
2016/11/11 15:25:08
nit: #include <string>
Thiemo Nagel
2016/11/16 19:11:01
Done.
|
| + policy_map.CopyFrom(store_->policy_map()); |
| + |
| + // Overwrite the source which is POLICY_SOURCE_CLOUD by default. |
| + // TODO(tnagel): Rename CloudPolicyStore to PolicyStore and make the source |
|
emaxx
2016/11/11 15:25:08
Just a point from my perspective: there are other
Thiemo Nagel
2016/11/16 19:11:01
AD is not cloud, very often it's on-premise server
|
| + // configurable, then drop PolicyMap::SetSourceForAll(). |
| + policy_map.SetSourceForAll(POLICY_SOURCE_ACTIVE_DIRECTORY); |
|
emaxx
2016/11/11 15:25:08
nit: #include "components/policy/core/common/polic
Thiemo Nagel
2016/11/16 19:11:01
Done.
|
| + UpdatePolicy(std::move(bundle)); |
| +} |
| + |
| +} // namespace policy |