| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/policy/core/common/cloud/user_cloud_policy_manager.h" | 5 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 9 #include "base/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" |
| 10 #include "components/policy/core/common/cloud/cloud_external_data_manager.h" | 12 #include "components/policy/core/common/cloud/cloud_external_data_manager.h" |
| 11 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 13 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 12 #include "components/policy/core/common/cloud/cloud_policy_service.h" | 14 #include "components/policy/core/common/cloud/cloud_policy_service.h" |
| 13 #include "components/policy/core/common/cloud/user_cloud_policy_store.h" | 15 #include "components/policy/core/common/cloud/user_cloud_policy_store.h" |
| 14 #include "components/policy/core/common/policy_pref_names.h" | 16 #include "components/policy/core/common/policy_pref_names.h" |
| 15 #include "components/policy/core/common/policy_types.h" | 17 #include "components/policy/core/common/policy_types.h" |
| 16 #include "net/url_request/url_request_context_getter.h" | 18 #include "net/url_request/url_request_context_getter.h" |
| 17 | 19 |
| 18 namespace em = enterprise_management; | 20 namespace em = enterprise_management; |
| 19 | 21 |
| 20 namespace policy { | 22 namespace policy { |
| 21 | 23 |
| 22 UserCloudPolicyManager::UserCloudPolicyManager( | 24 UserCloudPolicyManager::UserCloudPolicyManager( |
| 23 scoped_ptr<UserCloudPolicyStore> store, | 25 scoped_ptr<UserCloudPolicyStore> store, |
| 24 const base::FilePath& component_policy_cache_path, | 26 const base::FilePath& component_policy_cache_path, |
| 25 scoped_ptr<CloudExternalDataManager> external_data_manager, | 27 scoped_ptr<CloudExternalDataManager> external_data_manager, |
| 26 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 28 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
| 27 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner, | 29 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner, |
| 28 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner) | 30 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner) |
| 29 : CloudPolicyManager(dm_protocol::kChromeUserPolicyType, | 31 : CloudPolicyManager(dm_protocol::kChromeUserPolicyType, |
| 30 std::string(), | 32 std::string(), |
| 31 store.get(), | 33 store.get(), |
| 32 task_runner, | 34 task_runner, |
| 33 file_task_runner, | 35 file_task_runner, |
| 34 io_task_runner), | 36 io_task_runner), |
| 35 store_(store.Pass()), | 37 store_(std::move(store)), |
| 36 component_policy_cache_path_(component_policy_cache_path), | 38 component_policy_cache_path_(component_policy_cache_path), |
| 37 external_data_manager_(external_data_manager.Pass()) { | 39 external_data_manager_(std::move(external_data_manager)) {} |
| 38 } | |
| 39 | 40 |
| 40 UserCloudPolicyManager::~UserCloudPolicyManager() {} | 41 UserCloudPolicyManager::~UserCloudPolicyManager() {} |
| 41 | 42 |
| 42 void UserCloudPolicyManager::Shutdown() { | 43 void UserCloudPolicyManager::Shutdown() { |
| 43 if (external_data_manager_) | 44 if (external_data_manager_) |
| 44 external_data_manager_->Disconnect(); | 45 external_data_manager_->Disconnect(); |
| 45 CloudPolicyManager::Shutdown(); | 46 CloudPolicyManager::Shutdown(); |
| 46 } | 47 } |
| 47 | 48 |
| 48 void UserCloudPolicyManager::SetSigninUsername(const std::string& username) { | 49 void UserCloudPolicyManager::SetSigninUsername(const std::string& username) { |
| 49 store_->SetSigninUsername(username); | 50 store_->SetSigninUsername(username); |
| 50 } | 51 } |
| 51 | 52 |
| 52 void UserCloudPolicyManager::Connect( | 53 void UserCloudPolicyManager::Connect( |
| 53 PrefService* local_state, | 54 PrefService* local_state, |
| 54 scoped_refptr<net::URLRequestContextGetter> request_context, | 55 scoped_refptr<net::URLRequestContextGetter> request_context, |
| 55 scoped_ptr<CloudPolicyClient> client) { | 56 scoped_ptr<CloudPolicyClient> client) { |
| 56 CreateComponentCloudPolicyService(component_policy_cache_path_, | 57 CreateComponentCloudPolicyService(component_policy_cache_path_, |
| 57 request_context, client.get()); | 58 request_context, client.get()); |
| 58 core()->Connect(client.Pass()); | 59 core()->Connect(std::move(client)); |
| 59 core()->StartRefreshScheduler(); | 60 core()->StartRefreshScheduler(); |
| 60 core()->TrackRefreshDelayPref(local_state, | 61 core()->TrackRefreshDelayPref(local_state, |
| 61 policy_prefs::kUserPolicyRefreshRate); | 62 policy_prefs::kUserPolicyRefreshRate); |
| 62 if (external_data_manager_) | 63 if (external_data_manager_) |
| 63 external_data_manager_->Connect(request_context); | 64 external_data_manager_->Connect(request_context); |
| 64 } | 65 } |
| 65 | 66 |
| 66 // static | 67 // static |
| 67 scoped_ptr<CloudPolicyClient> | 68 scoped_ptr<CloudPolicyClient> |
| 68 UserCloudPolicyManager::CreateCloudPolicyClient( | 69 UserCloudPolicyManager::CreateCloudPolicyClient( |
| 69 DeviceManagementService* device_management_service, | 70 DeviceManagementService* device_management_service, |
| 70 scoped_refptr<net::URLRequestContextGetter> request_context) { | 71 scoped_refptr<net::URLRequestContextGetter> request_context) { |
| 71 return make_scoped_ptr( | 72 return make_scoped_ptr(new CloudPolicyClient( |
| 72 new CloudPolicyClient( | 73 std::string(), std::string(), kPolicyVerificationKeyHash, |
| 73 std::string(), | 74 device_management_service, request_context)); |
| 74 std::string(), | |
| 75 kPolicyVerificationKeyHash, | |
| 76 device_management_service, | |
| 77 request_context)).Pass(); | |
| 78 } | 75 } |
| 79 | 76 |
| 80 void UserCloudPolicyManager::DisconnectAndRemovePolicy() { | 77 void UserCloudPolicyManager::DisconnectAndRemovePolicy() { |
| 81 if (external_data_manager_) | 78 if (external_data_manager_) |
| 82 external_data_manager_->Disconnect(); | 79 external_data_manager_->Disconnect(); |
| 83 core()->Disconnect(); | 80 core()->Disconnect(); |
| 84 | 81 |
| 85 // store_->Clear() will publish the updated, empty policy. The component | 82 // store_->Clear() will publish the updated, empty policy. The component |
| 86 // policy service must be cleared before OnStoreLoaded() is issued, so that | 83 // policy service must be cleared before OnStoreLoaded() is issued, so that |
| 87 // component policies are also empty at CheckAndPublishPolicy(). | 84 // component policies are also empty at CheckAndPublishPolicy(). |
| 88 ClearAndDestroyComponentCloudPolicyService(); | 85 ClearAndDestroyComponentCloudPolicyService(); |
| 89 | 86 |
| 90 // When the |store_| is cleared, it informs the |external_data_manager_| that | 87 // When the |store_| is cleared, it informs the |external_data_manager_| that |
| 91 // all external data references have been removed, causing the | 88 // all external data references have been removed, causing the |
| 92 // |external_data_manager_| to clear its cache as well. | 89 // |external_data_manager_| to clear its cache as well. |
| 93 store_->Clear(); | 90 store_->Clear(); |
| 94 } | 91 } |
| 95 | 92 |
| 96 bool UserCloudPolicyManager::IsClientRegistered() const { | 93 bool UserCloudPolicyManager::IsClientRegistered() const { |
| 97 return client() && client()->is_registered(); | 94 return client() && client()->is_registered(); |
| 98 } | 95 } |
| 99 | 96 |
| 100 } // namespace policy | 97 } // namespace policy |
| OLD | NEW |