Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: chrome/browser/chromeos/policy/device_active_directory_policy_manager.cc

Issue 2486813002: Add DeviceADPolicyManager to provide AD policy. (Closed)
Patch Set: Address Bernhard's comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/policy/device_active_directory_policy_manager. h"
6
7 #include <string>
8 #include <utility>
9
10 #include "base/logging.h"
11 #include "base/memory/ptr_util.h"
12 #include "components/policy/core/common/policy_bundle.h"
13 #include "components/policy/core/common/policy_types.h"
14
15 namespace policy {
16
17 DeviceActiveDirectoryPolicyManager::DeviceActiveDirectoryPolicyManager(
18 std::unique_ptr<CloudPolicyStore> store)
19 : store_(std::move(store)) {}
20
21 DeviceActiveDirectoryPolicyManager::~DeviceActiveDirectoryPolicyManager() {}
22
23 void DeviceActiveDirectoryPolicyManager::Init(SchemaRegistry* registry) {
24 ConfigurationPolicyProvider::Init(registry);
25
26 store_->AddObserver(this);
27 PublishPolicy();
28 if (!store_->is_initialized()) {
29 store_->Load();
30 }
31 }
32
33 void DeviceActiveDirectoryPolicyManager::Shutdown() {
34 store_->RemoveObserver(this);
35 ConfigurationPolicyProvider::Shutdown();
36 }
37
38 bool DeviceActiveDirectoryPolicyManager::IsInitializationComplete(
39 PolicyDomain domain) const {
40 if (domain == POLICY_DOMAIN_CHROME)
41 return store_->is_initialized();
42 return true;
43 }
44
45 void DeviceActiveDirectoryPolicyManager::RefreshPolicies() {
46 store_->Load();
47 }
48
49 void DeviceActiveDirectoryPolicyManager::OnStoreLoaded(
50 CloudPolicyStore* cloud_policy_store) {
51 DCHECK_EQ(store_.get(), cloud_policy_store);
52 PublishPolicy();
53 }
54
55 void DeviceActiveDirectoryPolicyManager::OnStoreError(
56 CloudPolicyStore* cloud_policy_store) {
57 DCHECK_EQ(store_.get(), cloud_policy_store);
58 // Publish policy (even though it hasn't changed) in order to signal load
59 // complete on the ConfigurationPolicyProvider interface. Technically, this is
60 // only required on the first load, but doesn't hurt in any case.
61 PublishPolicy();
62 }
63
64 void DeviceActiveDirectoryPolicyManager::PublishPolicy() {
65 if (!store_->is_initialized()) {
66 return;
67 }
68 std::unique_ptr<PolicyBundle> bundle = base::MakeUnique<PolicyBundle>();
69 PolicyMap& policy_map =
70 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()));
71 policy_map.CopyFrom(store_->policy_map());
72
73 // Overwrite the source which is POLICY_SOURCE_CLOUD by default.
74 // TODO(tnagel): Rename CloudPolicyStore to PolicyStore and make the source
75 // configurable, then drop PolicyMap::SetSourceForAll().
76 policy_map.SetSourceForAll(POLICY_SOURCE_ACTIVE_DIRECTORY);
77 UpdatePolicy(std::move(bundle));
78 }
79
80 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698