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

Side by Side Diff: chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.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/chromeos/policy/user_cloud_policy_manager_chromeos.h" 5 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.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/logging.h" 9 #include "base/logging.h"
11 #include "base/message_loop/message_loop_proxy.h"
12 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
13 #include "base/metrics/sparse_histogram.h" 11 #include "base/metrics/sparse_histogram.h"
14 #include "base/sequenced_task_runner.h" 12 #include "base/sequenced_task_runner.h"
15 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h" 14 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h"
17 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom eos.h" 15 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom eos.h"
18 #include "chrome/browser/chromeos/profiles/profile_helper.h" 16 #include "chrome/browser/chromeos/profiles/profile_helper.h"
19 #include "chrome/browser/policy/cloud/cloud_external_data_manager.h" 17 #include "chrome/browser/policy/cloud/cloud_external_data_manager.h"
20 #include "chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.h" 18 #include "chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.h"
21 #include "chrome/browser/policy/cloud/resource_cache.h"
22 #include "components/policy/core/common/policy_bundle.h"
23 #include "components/policy/core/common/policy_pref_names.h" 19 #include "components/policy/core/common/policy_pref_names.h"
24 #include "components/policy/core/common/policy_switches.h"
25 #include "content/public/browser/browser_thread.h"
26 #include "net/url_request/url_request_context_getter.h" 20 #include "net/url_request/url_request_context_getter.h"
27 21
28 namespace em = enterprise_management; 22 namespace em = enterprise_management;
29 23
30 namespace policy { 24 namespace policy {
31 25
32 namespace { 26 namespace {
33 27
34 // UMA histogram names. 28 // UMA histogram names.
35 const char kUMADelayInitialization[] = 29 const char kUMADelayInitialization[] =
(...skipping 11 matching lines...) Expand all
47 const char kUMAInitialFetchOAuth2Error[] = 41 const char kUMAInitialFetchOAuth2Error[] =
48 "Enterprise.UserPolicyChromeOS.InitialFetch.OAuth2Error"; 42 "Enterprise.UserPolicyChromeOS.InitialFetch.OAuth2Error";
49 const char kUMAInitialFetchOAuth2NetworkError[] = 43 const char kUMAInitialFetchOAuth2NetworkError[] =
50 "Enterprise.UserPolicyChromeOS.InitialFetch.OAuth2NetworkError"; 44 "Enterprise.UserPolicyChromeOS.InitialFetch.OAuth2NetworkError";
51 45
52 } // namespace 46 } // namespace
53 47
54 UserCloudPolicyManagerChromeOS::UserCloudPolicyManagerChromeOS( 48 UserCloudPolicyManagerChromeOS::UserCloudPolicyManagerChromeOS(
55 scoped_ptr<CloudPolicyStore> store, 49 scoped_ptr<CloudPolicyStore> store,
56 scoped_ptr<CloudExternalDataManager> external_data_manager, 50 scoped_ptr<CloudExternalDataManager> external_data_manager,
51 const base::FilePath& component_policy_cache_path,
52 bool wait_for_policy_fetch,
53 base::TimeDelta initial_policy_fetch_timeout,
57 const scoped_refptr<base::SequencedTaskRunner>& task_runner, 54 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
58 const base::FilePath& resource_cache_dir, 55 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner,
59 bool wait_for_policy_fetch, 56 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner)
60 base::TimeDelta initial_policy_fetch_timeout)
61 : CloudPolicyManager( 57 : CloudPolicyManager(
62 PolicyNamespaceKey(dm_protocol::kChromeUserPolicyType, std::string()), 58 PolicyNamespaceKey(dm_protocol::kChromeUserPolicyType, std::string()),
63 store.get(), 59 store.get(),
64 task_runner), 60 task_runner,
61 file_task_runner,
62 io_task_runner),
65 store_(store.Pass()), 63 store_(store.Pass()),
66 external_data_manager_(external_data_manager.Pass()), 64 external_data_manager_(external_data_manager.Pass()),
67 resource_cache_dir_(resource_cache_dir), 65 component_policy_cache_path_(component_policy_cache_path),
68 wait_for_policy_fetch_(wait_for_policy_fetch), 66 wait_for_policy_fetch_(wait_for_policy_fetch),
69 policy_fetch_timeout_(false, false) { 67 policy_fetch_timeout_(false, false) {
70 time_init_started_ = base::Time::Now(); 68 time_init_started_ = base::Time::Now();
71 if (wait_for_policy_fetch_) { 69 if (wait_for_policy_fetch_) {
72 policy_fetch_timeout_.Start( 70 policy_fetch_timeout_.Start(
73 FROM_HERE, 71 FROM_HERE,
74 initial_policy_fetch_timeout, 72 initial_policy_fetch_timeout,
75 base::Bind(&UserCloudPolicyManagerChromeOS::CancelWaitForPolicyFetch, 73 base::Bind(&UserCloudPolicyManagerChromeOS::CancelWaitForPolicyFetch,
76 base::Unretained(this))); 74 base::Unretained(this)));
77 } 75 }
(...skipping 10 matching lines...) Expand all
88 DCHECK(local_state); 86 DCHECK(local_state);
89 local_state_ = local_state; 87 local_state_ = local_state;
90 scoped_ptr<CloudPolicyClient> cloud_policy_client( 88 scoped_ptr<CloudPolicyClient> cloud_policy_client(
91 new CloudPolicyClient(std::string(), std::string(), user_affiliation, 89 new CloudPolicyClient(std::string(), std::string(), user_affiliation,
92 NULL, device_management_service)); 90 NULL, device_management_service));
93 core()->Connect(cloud_policy_client.Pass()); 91 core()->Connect(cloud_policy_client.Pass());
94 client()->AddObserver(this); 92 client()->AddObserver(this);
95 93
96 external_data_manager_->Connect(request_context); 94 external_data_manager_->Connect(request_context);
97 95
98 CreateComponentCloudPolicyService(request_context); 96 CreateComponentCloudPolicyService(component_policy_cache_path_,
97 request_context);
99 98
100 // Determine the next step after the CloudPolicyService initializes. 99 // Determine the next step after the CloudPolicyService initializes.
101 if (service()->IsInitializationComplete()) { 100 if (service()->IsInitializationComplete()) {
102 OnInitializationCompleted(service()); 101 OnInitializationCompleted(service());
103 } else { 102 } else {
104 service()->AddObserver(this); 103 service()->AddObserver(this);
105 } 104 }
106 } 105 }
107 106
108 void UserCloudPolicyManagerChromeOS::OnAccessTokenAvailable( 107 void UserCloudPolicyManagerChromeOS::OnAccessTokenAvailable(
109 const std::string& access_token) { 108 const std::string& access_token) {
110 access_token_ = access_token; 109 access_token_ = access_token;
111 if (service() && service()->IsInitializationComplete() && 110 if (service() && service()->IsInitializationComplete() &&
112 client() && !client()->is_registered()) { 111 client() && !client()->is_registered()) {
113 OnOAuth2PolicyTokenFetched( 112 OnOAuth2PolicyTokenFetched(
114 access_token, GoogleServiceAuthError(GoogleServiceAuthError::NONE)); 113 access_token, GoogleServiceAuthError(GoogleServiceAuthError::NONE));
115 } 114 }
116 } 115 }
117 116
118 bool UserCloudPolicyManagerChromeOS::IsClientRegistered() const { 117 bool UserCloudPolicyManagerChromeOS::IsClientRegistered() const {
119 return client() && client()->is_registered(); 118 return client() && client()->is_registered();
120 } 119 }
121 120
122 void UserCloudPolicyManagerChromeOS::Shutdown() { 121 void UserCloudPolicyManagerChromeOS::Shutdown() {
123 if (client()) 122 if (client())
124 client()->RemoveObserver(this); 123 client()->RemoveObserver(this);
125 if (service()) 124 if (service())
126 service()->RemoveObserver(this); 125 service()->RemoveObserver(this);
127 token_fetcher_.reset(); 126 token_fetcher_.reset();
128 component_policy_service_.reset();
129 external_data_manager_->Disconnect(); 127 external_data_manager_->Disconnect();
130 CloudPolicyManager::Shutdown(); 128 CloudPolicyManager::Shutdown();
131 } 129 }
132 130
133 bool UserCloudPolicyManagerChromeOS::IsInitializationComplete( 131 bool UserCloudPolicyManagerChromeOS::IsInitializationComplete(
134 PolicyDomain domain) const { 132 PolicyDomain domain) const {
135 if (!CloudPolicyManager::IsInitializationComplete(domain)) 133 if (!CloudPolicyManager::IsInitializationComplete(domain))
136 return false; 134 return false;
137 if (domain == POLICY_DOMAIN_CHROME) 135 if (domain == POLICY_DOMAIN_CHROME)
138 return !wait_for_policy_fetch_; 136 return !wait_for_policy_fetch_;
139 if (ComponentCloudPolicyService::SupportsDomain(domain) &&
140 component_policy_service_) {
141 return component_policy_service_->is_initialized();
142 }
143 return true; 137 return true;
144 } 138 }
145 139
146 scoped_ptr<PolicyBundle> UserCloudPolicyManagerChromeOS::CreatePolicyBundle() {
147 scoped_ptr<PolicyBundle> bundle = CloudPolicyManager::CreatePolicyBundle();
148 if (component_policy_service_)
149 bundle->MergeFrom(component_policy_service_->policy());
150 return bundle.Pass();
151 }
152
153 void UserCloudPolicyManagerChromeOS::OnInitializationCompleted( 140 void UserCloudPolicyManagerChromeOS::OnInitializationCompleted(
154 CloudPolicyService* cloud_policy_service) { 141 CloudPolicyService* cloud_policy_service) {
155 DCHECK_EQ(service(), cloud_policy_service); 142 DCHECK_EQ(service(), cloud_policy_service);
156 cloud_policy_service->RemoveObserver(this); 143 cloud_policy_service->RemoveObserver(this);
157 144
158 time_init_completed_ = base::Time::Now(); 145 time_init_completed_ = base::Time::Now();
159 UMA_HISTOGRAM_TIMES(kUMADelayInitialization, 146 UMA_HISTOGRAM_TIMES(kUMADelayInitialization,
160 time_init_completed_ - time_init_started_); 147 time_init_completed_ - time_init_started_);
161 148
162 // If the CloudPolicyClient isn't registered at this stage then it needs an 149 // If the CloudPolicyClient isn't registered at this stage then it needs an
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 CloudPolicyClient* cloud_policy_client) { 213 CloudPolicyClient* cloud_policy_client) {
227 DCHECK_EQ(client(), cloud_policy_client); 214 DCHECK_EQ(client(), cloud_policy_client);
228 if (wait_for_policy_fetch_) { 215 if (wait_for_policy_fetch_) {
229 UMA_HISTOGRAM_SPARSE_SLOWLY(kUMAInitialFetchClientError, 216 UMA_HISTOGRAM_SPARSE_SLOWLY(kUMAInitialFetchClientError,
230 cloud_policy_client->status()); 217 cloud_policy_client->status());
231 } 218 }
232 CancelWaitForPolicyFetch(); 219 CancelWaitForPolicyFetch();
233 } 220 }
234 221
235 void UserCloudPolicyManagerChromeOS::OnComponentCloudPolicyUpdated() { 222 void UserCloudPolicyManagerChromeOS::OnComponentCloudPolicyUpdated() {
236 CheckAndPublishPolicy(); 223 CloudPolicyManager::OnComponentCloudPolicyUpdated();
237 StartRefreshSchedulerIfReady(); 224 StartRefreshSchedulerIfReady();
238 } 225 }
239 226
240 void UserCloudPolicyManagerChromeOS::CreateComponentCloudPolicyService(
241 const scoped_refptr<net::URLRequestContextGetter>& request_context) {
242 // Init() must have been called.
243 DCHECK(schema_registry());
244 // Called at most once.
245 DCHECK(!component_policy_service_);
246
247 if (!CommandLine::ForCurrentProcess()->HasSwitch(
248 switches::kEnableComponentCloudPolicy)) {
249 return;
250 }
251
252 // TODO(joaodasilva): Move the |backend_task_runner| to the blocking pool.
253 // Currently it's not possible because the ComponentCloudPolicyStore is
254 // NonThreadSafe and doesn't support getting calls from different threads.
255 scoped_refptr<base::SequencedTaskRunner> backend_task_runner =
256 content::BrowserThread::GetMessageLoopProxyForThread(
257 content::BrowserThread::FILE);
258 scoped_ptr<ResourceCache> resource_cache(
259 new ResourceCache(resource_cache_dir_, backend_task_runner));
260 component_policy_service_.reset(new ComponentCloudPolicyService(
261 this,
262 schema_registry(),
263 core(),
264 resource_cache.Pass(),
265 request_context,
266 backend_task_runner,
267 content::BrowserThread::GetMessageLoopProxyForThread(
268 content::BrowserThread::IO)));
269 }
270
271 void UserCloudPolicyManagerChromeOS::FetchPolicyOAuthTokenUsingSigninProfile() { 227 void UserCloudPolicyManagerChromeOS::FetchPolicyOAuthTokenUsingSigninProfile() {
272 scoped_refptr<net::URLRequestContextGetter> signin_context; 228 scoped_refptr<net::URLRequestContextGetter> signin_context;
273 Profile* signin_profile = chromeos::ProfileHelper::GetSigninProfile(); 229 Profile* signin_profile = chromeos::ProfileHelper::GetSigninProfile();
274 if (signin_profile) 230 if (signin_profile)
275 signin_context = signin_profile->GetRequestContext(); 231 signin_context = signin_profile->GetRequestContext();
276 if (!signin_context.get()) { 232 if (!signin_context.get()) {
277 LOG(ERROR) << "No signin Profile for policy oauth token fetch!"; 233 LOG(ERROR) << "No signin Profile for policy oauth token fetch!";
278 OnOAuth2PolicyTokenFetched( 234 OnOAuth2PolicyTokenFetched(
279 std::string(), GoogleServiceAuthError(GoogleServiceAuthError::NONE)); 235 std::string(), GoogleServiceAuthError(GoogleServiceAuthError::NONE));
280 return; 236 return;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 void UserCloudPolicyManagerChromeOS::StartRefreshSchedulerIfReady() { 299 void UserCloudPolicyManagerChromeOS::StartRefreshSchedulerIfReady() {
344 if (core()->refresh_scheduler()) 300 if (core()->refresh_scheduler())
345 return; // Already started. 301 return; // Already started.
346 302
347 if (wait_for_policy_fetch_) 303 if (wait_for_policy_fetch_)
348 return; // Still waiting for the initial, blocking fetch. 304 return; // Still waiting for the initial, blocking fetch.
349 305
350 if (!service() || !local_state_) 306 if (!service() || !local_state_)
351 return; // Not connected. 307 return; // Not connected.
352 308
353 if (component_policy_service_ && 309 if (component_policy_service() &&
354 !component_policy_service_->is_initialized()) { 310 !component_policy_service()->is_initialized()) {
355 // If the client doesn't have the list of components to fetch yet then don't 311 // If the client doesn't have the list of components to fetch yet then don't
356 // start the scheduler. The |component_policy_service_| will call back into 312 // start the scheduler. The |component_policy_service_| will call back into
357 // OnComponentCloudPolicyUpdated() once it's ready. 313 // OnComponentCloudPolicyUpdated() once it's ready.
358 return; 314 return;
359 } 315 }
360 316
361 core()->StartRefreshScheduler(); 317 core()->StartRefreshScheduler();
362 core()->TrackRefreshDelayPref(local_state_, 318 core()->TrackRefreshDelayPref(local_state_,
363 policy_prefs::kUserPolicyRefreshRate); 319 policy_prefs::kUserPolicyRefreshRate);
364 } 320 }
365 321
366 } // namespace policy 322 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698