| OLD | NEW |
| 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 ActiveDirectoryPolicyManager* |
| 23 ActiveDirectoryPolicyManager::CreateForDevicePolicy( |
| 24 std::unique_ptr<CloudPolicyStore> store) { |
| 25 return new ActiveDirectoryPolicyManager(EmptyAccountId(), std::move(store)); |
| 26 } |
| 27 |
| 28 // static |
| 29 ActiveDirectoryPolicyManager* ActiveDirectoryPolicyManager::CreateForUserPolicy( |
| 20 const AccountId& account_id, | 30 const AccountId& account_id, |
| 21 std::unique_ptr<CloudPolicyStore> store) | 31 std::unique_ptr<CloudPolicyStore> store) { |
| 22 : account_id_(account_id), | 32 return new ActiveDirectoryPolicyManager(account_id, std::move(store)); |
| 23 store_(std::move(store)), | 33 } |
| 24 weak_ptr_factory_(this) {} | |
| 25 | 34 |
| 26 UserActiveDirectoryPolicyManager::~UserActiveDirectoryPolicyManager() {} | 35 void ActiveDirectoryPolicyManager::Init(SchemaRegistry* registry) { |
| 27 | |
| 28 void UserActiveDirectoryPolicyManager::Init(SchemaRegistry* registry) { | |
| 29 ConfigurationPolicyProvider::Init(registry); | 36 ConfigurationPolicyProvider::Init(registry); |
| 30 | 37 |
| 31 store_->AddObserver(this); | 38 store_->AddObserver(this); |
| 32 if (!store_->is_initialized()) { | 39 if (!store_->is_initialized()) { |
| 33 store_->Load(); | 40 store_->Load(); |
| 34 } | 41 } |
| 35 | 42 |
| 36 // Does nothing if |store_| hasn't yet initialized. | 43 // Does nothing if |store_| hasn't yet initialized. |
| 37 PublishPolicy(); | 44 PublishPolicy(); |
| 38 | 45 |
| 39 RefreshPolicies(); | 46 RefreshPolicies(); |
| 40 } | 47 } |
| 41 | 48 |
| 42 void UserActiveDirectoryPolicyManager::Shutdown() { | 49 void ActiveDirectoryPolicyManager::Shutdown() { |
| 43 store_->RemoveObserver(this); | 50 store_->RemoveObserver(this); |
| 44 ConfigurationPolicyProvider::Shutdown(); | 51 ConfigurationPolicyProvider::Shutdown(); |
| 45 } | 52 } |
| 46 | 53 |
| 47 bool UserActiveDirectoryPolicyManager::IsInitializationComplete( | 54 bool ActiveDirectoryPolicyManager::IsInitializationComplete( |
| 48 PolicyDomain domain) const { | 55 PolicyDomain domain) const { |
| 49 if (domain == POLICY_DOMAIN_CHROME) | 56 if (domain == POLICY_DOMAIN_CHROME) |
| 50 return store_->is_initialized(); | 57 return store_->is_initialized(); |
| 51 return true; | 58 return true; |
| 52 } | 59 } |
| 53 | 60 |
| 54 void UserActiveDirectoryPolicyManager::RefreshPolicies() { | 61 void ActiveDirectoryPolicyManager::RefreshPolicies() { |
| 55 chromeos::DBusThreadManager* thread_manager = | 62 chromeos::DBusThreadManager* thread_manager = |
| 56 chromeos::DBusThreadManager::Get(); | 63 chromeos::DBusThreadManager::Get(); |
| 57 DCHECK(thread_manager); | 64 DCHECK(thread_manager); |
| 58 chromeos::AuthPolicyClient* auth_policy_client = | 65 chromeos::AuthPolicyClient* auth_policy_client = |
| 59 thread_manager->GetAuthPolicyClient(); | 66 thread_manager->GetAuthPolicyClient(); |
| 60 DCHECK(auth_policy_client); | 67 DCHECK(auth_policy_client); |
| 61 auth_policy_client->RefreshUserPolicy( | 68 if (account_id_ == EmptyAccountId()) { |
| 62 account_id_, | 69 auth_policy_client->RefreshDevicePolicy( |
| 63 base::Bind(&UserActiveDirectoryPolicyManager::OnPolicyRefreshed, | 70 base::Bind(&ActiveDirectoryPolicyManager::OnPolicyRefreshed, |
| 64 weak_ptr_factory_.GetWeakPtr())); | 71 weak_ptr_factory_.GetWeakPtr())); |
| 72 } else { |
| 73 auth_policy_client->RefreshUserPolicy( |
| 74 account_id_, |
| 75 base::Bind(&ActiveDirectoryPolicyManager::OnPolicyRefreshed, |
| 76 weak_ptr_factory_.GetWeakPtr())); |
| 77 } |
| 65 } | 78 } |
| 66 | 79 |
| 67 void UserActiveDirectoryPolicyManager::OnStoreLoaded( | 80 void ActiveDirectoryPolicyManager::OnStoreLoaded( |
| 68 CloudPolicyStore* cloud_policy_store) { | 81 CloudPolicyStore* cloud_policy_store) { |
| 69 DCHECK_EQ(store_.get(), cloud_policy_store); | 82 DCHECK_EQ(store_.get(), cloud_policy_store); |
| 70 PublishPolicy(); | 83 PublishPolicy(); |
| 71 } | 84 } |
| 72 | 85 |
| 73 void UserActiveDirectoryPolicyManager::OnStoreError( | 86 void ActiveDirectoryPolicyManager::OnStoreError( |
| 74 CloudPolicyStore* cloud_policy_store) { | 87 CloudPolicyStore* cloud_policy_store) { |
| 75 DCHECK_EQ(store_.get(), cloud_policy_store); | 88 DCHECK_EQ(store_.get(), cloud_policy_store); |
| 76 // Publish policy (even though it hasn't changed) in order to signal load | 89 // Publish policy (even though it hasn't changed) in order to signal load |
| 77 // complete on the ConfigurationPolicyProvider interface. Technically, this is | 90 // complete on the ConfigurationPolicyProvider interface. Technically, this is |
| 78 // only required on the first load, but doesn't hurt in any case. | 91 // only required on the first load, but doesn't hurt in any case. |
| 79 PublishPolicy(); | 92 PublishPolicy(); |
| 80 } | 93 } |
| 81 | 94 |
| 82 void UserActiveDirectoryPolicyManager::PublishPolicy() { | 95 ActiveDirectoryPolicyManager::ActiveDirectoryPolicyManager( |
| 96 const AccountId& account_id, |
| 97 std::unique_ptr<CloudPolicyStore> store) |
| 98 : account_id_(account_id), |
| 99 store_(std::move(store)), |
| 100 weak_ptr_factory_(this) {} |
| 101 |
| 102 void ActiveDirectoryPolicyManager::PublishPolicy() { |
| 83 if (!store_->is_initialized()) { | 103 if (!store_->is_initialized()) { |
| 84 return; | 104 return; |
| 85 } | 105 } |
| 86 std::unique_ptr<PolicyBundle> bundle = base::MakeUnique<PolicyBundle>(); | 106 std::unique_ptr<PolicyBundle> bundle = base::MakeUnique<PolicyBundle>(); |
| 87 PolicyMap& policy_map = | 107 PolicyMap& policy_map = |
| 88 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); | 108 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); |
| 89 policy_map.CopyFrom(store_->policy_map()); | 109 policy_map.CopyFrom(store_->policy_map()); |
| 90 | 110 |
| 91 // Overwrite the source which is POLICY_SOURCE_CLOUD by default. | 111 // Overwrite the source which is POLICY_SOURCE_CLOUD by default. |
| 92 // TODO(tnagel): Rename CloudPolicyStore to PolicyStore and make the source | 112 // TODO(tnagel): Rename CloudPolicyStore to PolicyStore and make the source |
| 93 // configurable, then drop PolicyMap::SetSourceForAll(). | 113 // configurable, then drop PolicyMap::SetSourceForAll(). |
| 94 policy_map.SetSourceForAll(POLICY_SOURCE_ACTIVE_DIRECTORY); | 114 policy_map.SetSourceForAll(POLICY_SOURCE_ACTIVE_DIRECTORY); |
| 95 UpdatePolicy(std::move(bundle)); | 115 UpdatePolicy(std::move(bundle)); |
| 96 } | 116 } |
| 97 | 117 |
| 98 void UserActiveDirectoryPolicyManager::OnPolicyRefreshed(bool success) { | 118 void ActiveDirectoryPolicyManager::OnPolicyRefreshed(bool success) { |
| 99 if (!success) { | 119 if (!success) { |
| 100 LOG(ERROR) << "Active Directory policy refresh failed."; | 120 LOG(ERROR) << "Active Directory policy refresh failed."; |
| 101 } | 121 } |
| 102 // Load independently of success or failure to keep up to date with whatever | 122 // Load independently of success or failure to keep up to date with whatever |
| 103 // has happened on the authpolicyd / session manager side. | 123 // has happened on the authpolicyd / session manager side. |
| 104 store_->Load(); | 124 store_->Load(); |
| 105 } | 125 } |
| 106 | 126 |
| 107 } // namespace policy | 127 } // namespace policy |
| OLD | NEW |