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