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