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

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

Issue 2638623006: Merge {Device,User}ActiveDirectoryPolicyManager into a single class (Closed)
Patch Set: Have factories return unique_ptr Created 3 years, 11 months 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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/user_active_directory_policy_manager.h" 5 #include "chrome/browser/chromeos/policy/active_directory_policy_manager.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "chromeos/dbus/auth_policy_client.h" 12 #include "chromeos/dbus/auth_policy_client.h"
13 #include "chromeos/dbus/dbus_thread_manager.h" 13 #include "chromeos/dbus/dbus_thread_manager.h"
14 #include "components/policy/core/common/policy_bundle.h" 14 #include "components/policy/core/common/policy_bundle.h"
15 #include "components/policy/core/common/policy_types.h" 15 #include "components/policy/core/common/policy_types.h"
16 16
17 namespace policy { 17 namespace policy {
18 18
19 UserActiveDirectoryPolicyManager::UserActiveDirectoryPolicyManager( 19 ActiveDirectoryPolicyManager::~ActiveDirectoryPolicyManager() {}
20
21 // static
22 std::unique_ptr<ActiveDirectoryPolicyManager>
23 ActiveDirectoryPolicyManager::CreateForDevicePolicy(
24 std::unique_ptr<CloudPolicyStore> store) {
25 return base::WrapUnique(
emaxx 2017/01/18 19:09:59 nit: base::MakeUnique?
Thiemo Nagel 2017/01/18 19:18:37 MakeUnique won't work because the constructor is p
26 new ActiveDirectoryPolicyManager(EmptyAccountId(), std::move(store)));
27 }
28
29 // static
30 std::unique_ptr<ActiveDirectoryPolicyManager>
31 ActiveDirectoryPolicyManager::CreateForUserPolicy(
20 const AccountId& account_id, 32 const AccountId& account_id,
21 std::unique_ptr<CloudPolicyStore> store) 33 std::unique_ptr<CloudPolicyStore> store) {
22 : account_id_(account_id), 34 return base::WrapUnique(
23 store_(std::move(store)), 35 new ActiveDirectoryPolicyManager(account_id, std::move(store)));
24 weak_ptr_factory_(this) {} 36 }
25 37
26 UserActiveDirectoryPolicyManager::~UserActiveDirectoryPolicyManager() {} 38 void ActiveDirectoryPolicyManager::Init(SchemaRegistry* registry) {
27
28 void UserActiveDirectoryPolicyManager::Init(SchemaRegistry* registry) {
29 ConfigurationPolicyProvider::Init(registry); 39 ConfigurationPolicyProvider::Init(registry);
30 40
31 store_->AddObserver(this); 41 store_->AddObserver(this);
32 if (!store_->is_initialized()) { 42 if (!store_->is_initialized()) {
33 store_->Load(); 43 store_->Load();
34 } 44 }
35 45
36 // Does nothing if |store_| hasn't yet initialized. 46 // Does nothing if |store_| hasn't yet initialized.
37 PublishPolicy(); 47 PublishPolicy();
38 48
39 RefreshPolicies(); 49 RefreshPolicies();
40 } 50 }
41 51
42 void UserActiveDirectoryPolicyManager::Shutdown() { 52 void ActiveDirectoryPolicyManager::Shutdown() {
43 store_->RemoveObserver(this); 53 store_->RemoveObserver(this);
44 ConfigurationPolicyProvider::Shutdown(); 54 ConfigurationPolicyProvider::Shutdown();
45 } 55 }
46 56
47 bool UserActiveDirectoryPolicyManager::IsInitializationComplete( 57 bool ActiveDirectoryPolicyManager::IsInitializationComplete(
48 PolicyDomain domain) const { 58 PolicyDomain domain) const {
49 if (domain == POLICY_DOMAIN_CHROME) 59 if (domain == POLICY_DOMAIN_CHROME)
50 return store_->is_initialized(); 60 return store_->is_initialized();
51 return true; 61 return true;
52 } 62 }
53 63
54 void UserActiveDirectoryPolicyManager::RefreshPolicies() { 64 void ActiveDirectoryPolicyManager::RefreshPolicies() {
55 chromeos::DBusThreadManager* thread_manager = 65 chromeos::DBusThreadManager* thread_manager =
56 chromeos::DBusThreadManager::Get(); 66 chromeos::DBusThreadManager::Get();
57 DCHECK(thread_manager); 67 DCHECK(thread_manager);
58 chromeos::AuthPolicyClient* auth_policy_client = 68 chromeos::AuthPolicyClient* auth_policy_client =
59 thread_manager->GetAuthPolicyClient(); 69 thread_manager->GetAuthPolicyClient();
60 DCHECK(auth_policy_client); 70 DCHECK(auth_policy_client);
61 auth_policy_client->RefreshUserPolicy( 71 if (account_id_ == EmptyAccountId()) {
62 account_id_, 72 auth_policy_client->RefreshDevicePolicy(
63 base::Bind(&UserActiveDirectoryPolicyManager::OnPolicyRefreshed, 73 base::Bind(&ActiveDirectoryPolicyManager::OnPolicyRefreshed,
64 weak_ptr_factory_.GetWeakPtr())); 74 weak_ptr_factory_.GetWeakPtr()));
75 } else {
76 auth_policy_client->RefreshUserPolicy(
77 account_id_,
78 base::Bind(&ActiveDirectoryPolicyManager::OnPolicyRefreshed,
79 weak_ptr_factory_.GetWeakPtr()));
80 }
65 } 81 }
66 82
67 void UserActiveDirectoryPolicyManager::OnStoreLoaded( 83 void ActiveDirectoryPolicyManager::OnStoreLoaded(
68 CloudPolicyStore* cloud_policy_store) { 84 CloudPolicyStore* cloud_policy_store) {
69 DCHECK_EQ(store_.get(), cloud_policy_store); 85 DCHECK_EQ(store_.get(), cloud_policy_store);
70 PublishPolicy(); 86 PublishPolicy();
71 } 87 }
72 88
73 void UserActiveDirectoryPolicyManager::OnStoreError( 89 void ActiveDirectoryPolicyManager::OnStoreError(
74 CloudPolicyStore* cloud_policy_store) { 90 CloudPolicyStore* cloud_policy_store) {
75 DCHECK_EQ(store_.get(), cloud_policy_store); 91 DCHECK_EQ(store_.get(), cloud_policy_store);
76 // Publish policy (even though it hasn't changed) in order to signal load 92 // Publish policy (even though it hasn't changed) in order to signal load
77 // complete on the ConfigurationPolicyProvider interface. Technically, this is 93 // complete on the ConfigurationPolicyProvider interface. Technically, this is
78 // only required on the first load, but doesn't hurt in any case. 94 // only required on the first load, but doesn't hurt in any case.
79 PublishPolicy(); 95 PublishPolicy();
80 } 96 }
81 97
82 void UserActiveDirectoryPolicyManager::PublishPolicy() { 98 ActiveDirectoryPolicyManager::ActiveDirectoryPolicyManager(
99 const AccountId& account_id,
100 std::unique_ptr<CloudPolicyStore> store)
101 : account_id_(account_id),
102 store_(std::move(store)),
103 weak_ptr_factory_(this) {}
104
105 void ActiveDirectoryPolicyManager::PublishPolicy() {
83 if (!store_->is_initialized()) { 106 if (!store_->is_initialized()) {
84 return; 107 return;
85 } 108 }
86 std::unique_ptr<PolicyBundle> bundle = base::MakeUnique<PolicyBundle>(); 109 std::unique_ptr<PolicyBundle> bundle = base::MakeUnique<PolicyBundle>();
87 PolicyMap& policy_map = 110 PolicyMap& policy_map =
88 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); 111 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()));
89 policy_map.CopyFrom(store_->policy_map()); 112 policy_map.CopyFrom(store_->policy_map());
90 113
91 // Overwrite the source which is POLICY_SOURCE_CLOUD by default. 114 // Overwrite the source which is POLICY_SOURCE_CLOUD by default.
92 // TODO(tnagel): Rename CloudPolicyStore to PolicyStore and make the source 115 // TODO(tnagel): Rename CloudPolicyStore to PolicyStore and make the source
93 // configurable, then drop PolicyMap::SetSourceForAll(). 116 // configurable, then drop PolicyMap::SetSourceForAll().
94 policy_map.SetSourceForAll(POLICY_SOURCE_ACTIVE_DIRECTORY); 117 policy_map.SetSourceForAll(POLICY_SOURCE_ACTIVE_DIRECTORY);
95 UpdatePolicy(std::move(bundle)); 118 UpdatePolicy(std::move(bundle));
96 } 119 }
97 120
98 void UserActiveDirectoryPolicyManager::OnPolicyRefreshed(bool success) { 121 void ActiveDirectoryPolicyManager::OnPolicyRefreshed(bool success) {
99 if (!success) { 122 if (!success) {
100 LOG(ERROR) << "Active Directory policy refresh failed."; 123 LOG(ERROR) << "Active Directory policy refresh failed.";
101 } 124 }
102 // Load independently of success or failure to keep up to date with whatever 125 // Load independently of success or failure to keep up to date with whatever
103 // has happened on the authpolicyd / session manager side. 126 // has happened on the authpolicyd / session manager side.
104 store_->Load(); 127 store_->Load();
105 } 128 }
106 129
107 } // namespace policy 130 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698