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