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