Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: chrome/browser/policy/cloud/cloud_policy_manager.cc

Issue 79023002: Support cloud policy for extensions on the desktop platforms. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/cloud_policy_manager.h" 5 #include "chrome/browser/policy/cloud/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/command_line.h"
10 #include "base/files/file_path.h"
9 #include "base/logging.h" 11 #include "base/logging.h"
10 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
11 #include "chrome/browser/policy/cloud/cloud_policy_service.h" 13 #include "chrome/browser/policy/cloud/cloud_policy_service.h"
12 #include "components/policy/core/common/policy_bundle.h" 14 #include "components/policy/core/common/policy_bundle.h"
13 #include "components/policy/core/common/policy_map.h" 15 #include "components/policy/core/common/policy_map.h"
16 #include "components/policy/core/common/policy_switches.h"
17 #include "net/url_request/url_request_context_getter.h"
18
19 #if !defined(OS_ANDROID) && !defined(OS_IOS)
20 #include "chrome/browser/policy/cloud/resource_cache.h"
21 #endif
14 22
15 namespace policy { 23 namespace policy {
16 24
17 CloudPolicyManager::CloudPolicyManager( 25 CloudPolicyManager::CloudPolicyManager(
18 const PolicyNamespaceKey& policy_ns_key, 26 const PolicyNamespaceKey& policy_ns_key,
19 CloudPolicyStore* cloud_policy_store, 27 CloudPolicyStore* cloud_policy_store,
20 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)
21 : core_(policy_ns_key, cloud_policy_store, task_runner), 31 : core_(policy_ns_key, cloud_policy_store, task_runner),
22 waiting_for_policy_refresh_(false) { 32 waiting_for_policy_refresh_(false),
33 file_task_runner_(file_task_runner),
34 io_task_runner_(io_task_runner) {
23 store()->AddObserver(this); 35 store()->AddObserver(this);
24 36
25 // If the underlying store is already initialized, publish the loaded 37 // If the underlying store is already initialized, publish the loaded
26 // policy. Otherwise, request a load now. 38 // policy. Otherwise, request a load now.
27 if (store()->is_initialized()) 39 if (store()->is_initialized())
28 CheckAndPublishPolicy(); 40 CheckAndPublishPolicy();
29 else 41 else
30 store()->Load(); 42 store()->Load();
31 } 43 }
32 44
33 CloudPolicyManager::~CloudPolicyManager() {} 45 CloudPolicyManager::~CloudPolicyManager() {}
34 46
35 void CloudPolicyManager::Shutdown() { 47 void CloudPolicyManager::Shutdown() {
48 component_policy_service_.reset();
36 core_.Disconnect(); 49 core_.Disconnect();
37 store()->RemoveObserver(this); 50 store()->RemoveObserver(this);
38 ConfigurationPolicyProvider::Shutdown(); 51 ConfigurationPolicyProvider::Shutdown();
39 } 52 }
40 53
41 bool CloudPolicyManager::IsInitializationComplete(PolicyDomain domain) const { 54 bool CloudPolicyManager::IsInitializationComplete(PolicyDomain domain) const {
42 if (domain == POLICY_DOMAIN_CHROME) 55 if (domain == POLICY_DOMAIN_CHROME)
43 return store()->is_initialized(); 56 return store()->is_initialized();
57 if (ComponentCloudPolicyService::SupportsDomain(domain) &&
58 component_policy_service_) {
59 return component_policy_service_->is_initialized();
60 }
44 return true; 61 return true;
45 } 62 }
46 63
47 void CloudPolicyManager::RefreshPolicies() { 64 void CloudPolicyManager::RefreshPolicies() {
48 if (service()) { 65 if (service()) {
49 waiting_for_policy_refresh_ = true; 66 waiting_for_policy_refresh_ = true;
50 service()->RefreshPolicy( 67 service()->RefreshPolicy(
51 base::Bind(&CloudPolicyManager::OnRefreshComplete, 68 base::Bind(&CloudPolicyManager::OnRefreshComplete,
52 base::Unretained(this))); 69 base::Unretained(this)));
53 } else { 70 } else {
54 OnRefreshComplete(false); 71 OnRefreshComplete(false);
55 } 72 }
56 } 73 }
57 74
58 void CloudPolicyManager::OnStoreLoaded(CloudPolicyStore* cloud_policy_store) { 75 void CloudPolicyManager::OnStoreLoaded(CloudPolicyStore* cloud_policy_store) {
59 DCHECK_EQ(store(), cloud_policy_store); 76 DCHECK_EQ(store(), cloud_policy_store);
60 CheckAndPublishPolicy(); 77 CheckAndPublishPolicy();
61 } 78 }
62 79
63 void CloudPolicyManager::OnStoreError(CloudPolicyStore* cloud_policy_store) { 80 void CloudPolicyManager::OnStoreError(CloudPolicyStore* cloud_policy_store) {
64 DCHECK_EQ(store(), cloud_policy_store); 81 DCHECK_EQ(store(), cloud_policy_store);
65 // Publish policy (even though it hasn't changed) in order to signal load 82 // Publish policy (even though it hasn't changed) in order to signal load
66 // complete on the ConfigurationPolicyProvider interface. Technically, this 83 // complete on the ConfigurationPolicyProvider interface. Technically, this
67 // is only required on the first load, but doesn't hurt in any case. 84 // is only required on the first load, but doesn't hurt in any case.
68 CheckAndPublishPolicy(); 85 CheckAndPublishPolicy();
69 } 86 }
70 87
88 void CloudPolicyManager::OnComponentCloudPolicyUpdated() {
89 CheckAndPublishPolicy();
90 }
91
71 void CloudPolicyManager::CheckAndPublishPolicy() { 92 void CloudPolicyManager::CheckAndPublishPolicy() {
72 if (IsInitializationComplete(POLICY_DOMAIN_CHROME) && 93 if (IsInitializationComplete(POLICY_DOMAIN_CHROME) &&
73 !waiting_for_policy_refresh_) { 94 !waiting_for_policy_refresh_) {
74 UpdatePolicy(CreatePolicyBundle()); 95 scoped_ptr<PolicyBundle> bundle(new PolicyBundle);
96 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
97 .CopyFrom(store()->policy_map());
98 if (component_policy_service_)
99 bundle->MergeFrom(component_policy_service_->policy());
100 UpdatePolicy(bundle.Pass());
75 } 101 }
76 } 102 }
77 103
78 scoped_ptr<PolicyBundle> CloudPolicyManager::CreatePolicyBundle() { 104 void CloudPolicyManager::CreateComponentCloudPolicyService(
79 scoped_ptr<PolicyBundle> bundle(new PolicyBundle); 105 const base::FilePath& policy_cache_path,
80 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 106 const scoped_refptr<net::URLRequestContextGetter>& request_context) {
81 .CopyFrom(store()->policy_map()); 107 #if !defined(OS_ANDROID) && !defined(OS_IOS)
82 return bundle.Pass(); 108 // Init() must have been called.
109 DCHECK(schema_registry());
110 // Called at most once.
111 DCHECK(!component_policy_service_);
112
113 if (!CommandLine::ForCurrentProcess()->HasSwitch(
114 switches::kEnableComponentCloudPolicy) ||
115 policy_cache_path.empty()) {
116 return;
117 }
118
119 // TODO(joaodasilva): Move the |file_task_runner_| to the blocking pool.
120 // Currently it's not possible because the ComponentCloudPolicyStore is
121 // NonThreadSafe and doesn't support getting calls from different threads.
122 scoped_ptr<ResourceCache> resource_cache(
123 new ResourceCache(policy_cache_path, file_task_runner_));
124 component_policy_service_.reset(new ComponentCloudPolicyService(
125 this,
126 schema_registry(),
127 core(),
128 resource_cache.Pass(),
129 request_context,
130 file_task_runner_,
131 io_task_runner_));
132 #endif // !defined(OS_ANDROID) && !defined(OS_IOS)
83 } 133 }
84 134
85 void CloudPolicyManager::OnRefreshComplete(bool success) { 135 void CloudPolicyManager::OnRefreshComplete(bool success) {
86 waiting_for_policy_refresh_ = false; 136 waiting_for_policy_refresh_ = false;
87 CheckAndPublishPolicy(); 137 CheckAndPublishPolicy();
88 } 138 }
89 139
90 } // namespace policy 140 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/cloud/cloud_policy_manager.h ('k') | chrome/browser/policy/cloud/cloud_policy_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698