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