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

Side by Side Diff: chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.cc

Issue 23450022: Put a hard limit on initial policy fetch wait time. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 7 years, 3 months 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/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h" 12 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h"
13 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom eos.h" 13 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom eos.h"
14 #include "chrome/browser/chromeos/profiles/profile_helper.h" 14 #include "chrome/browser/chromeos/profiles/profile_helper.h"
15 #include "chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.h" 15 #include "chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.h"
16 #include "chrome/browser/policy/cloud/resource_cache.h" 16 #include "chrome/browser/policy/cloud/resource_cache.h"
17 #include "chrome/browser/policy/policy_bundle.h" 17 #include "chrome/browser/policy/policy_bundle.h"
18 #include "chrome/browser/policy/policy_domain_descriptor.h" 18 #include "chrome/browser/policy/policy_domain_descriptor.h"
19 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
20 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
21 #include "net/url_request/url_request_context_getter.h" 21 #include "net/url_request/url_request_context_getter.h"
22 22
23 namespace em = enterprise_management; 23 namespace em = enterprise_management;
24 24
25 namespace policy { 25 namespace policy {
26 26
27 UserCloudPolicyManagerChromeOS::UserCloudPolicyManagerChromeOS( 27 UserCloudPolicyManagerChromeOS::UserCloudPolicyManagerChromeOS(
28 scoped_ptr<CloudPolicyStore> store, 28 scoped_ptr<CloudPolicyStore> store,
29 scoped_ptr<ResourceCache> resource_cache, 29 scoped_ptr<ResourceCache> resource_cache,
30 bool wait_for_policy_fetch) 30 bool wait_for_policy_fetch,
31 base::TimeDelta initial_policy_fetch_timeout)
31 : CloudPolicyManager( 32 : CloudPolicyManager(
32 PolicyNamespaceKey(dm_protocol::kChromeUserPolicyType, std::string()), 33 PolicyNamespaceKey(dm_protocol::kChromeUserPolicyType, std::string()),
33 store.get()), 34 store.get()),
34 store_(store.Pass()), 35 store_(store.Pass()),
35 wait_for_policy_fetch_(wait_for_policy_fetch) { 36 wait_for_policy_fetch_(wait_for_policy_fetch),
37 policy_fetch_timeout_(false, false) {
38 if (wait_for_policy_fetch_) {
39 policy_fetch_timeout_.Start(
40 FROM_HERE,
41 initial_policy_fetch_timeout,
42 base::Bind(&UserCloudPolicyManagerChromeOS::CancelWaitForPolicyFetch,
43 base::Unretained(this)));
44 }
36 if (resource_cache) { 45 if (resource_cache) {
37 // TODO(joaodasilva): Move the backend from the FILE thread to the blocking 46 // TODO(joaodasilva): Move the backend from the FILE thread to the blocking
38 // pool. 47 // pool.
39 component_policy_service_.reset(new ComponentCloudPolicyService( 48 component_policy_service_.reset(new ComponentCloudPolicyService(
40 this, 49 this,
41 store_.get(), 50 store_.get(),
42 resource_cache.Pass(), 51 resource_cache.Pass(),
43 content::BrowserThread::GetMessageLoopProxyForThread( 52 content::BrowserThread::GetMessageLoopProxyForThread(
44 content::BrowserThread::FILE), 53 content::BrowserThread::FILE),
45 content::BrowserThread::GetMessageLoopProxyForThread( 54 content::BrowserThread::GetMessageLoopProxyForThread(
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 246
238 token_fetcher_.reset(); 247 token_fetcher_.reset();
239 } 248 }
240 249
241 void UserCloudPolicyManagerChromeOS::OnInitialPolicyFetchComplete( 250 void UserCloudPolicyManagerChromeOS::OnInitialPolicyFetchComplete(
242 bool success) { 251 bool success) {
243 CancelWaitForPolicyFetch(); 252 CancelWaitForPolicyFetch();
244 } 253 }
245 254
246 void UserCloudPolicyManagerChromeOS::CancelWaitForPolicyFetch() { 255 void UserCloudPolicyManagerChromeOS::CancelWaitForPolicyFetch() {
256 if (!wait_for_policy_fetch_)
257 return;
Andrew T Wilson (Slow) 2013/09/06 12:33:45 This is fine as-is. Alternatively, you could also
Mattias Nissler (ping if slow) 2013/09/06 13:37:30 This is better, there are already other code paths
258
247 wait_for_policy_fetch_ = false; 259 wait_for_policy_fetch_ = false;
248 CheckAndPublishPolicy(); 260 CheckAndPublishPolicy();
249 // Now that |wait_for_policy_fetch_| is guaranteed to be false, the scheduler 261 // Now that |wait_for_policy_fetch_| is guaranteed to be false, the scheduler
250 // can be started. 262 // can be started.
251 StartRefreshSchedulerIfReady(); 263 StartRefreshSchedulerIfReady();
252 } 264 }
253 265
254 void UserCloudPolicyManagerChromeOS::StartRefreshSchedulerIfReady() { 266 void UserCloudPolicyManagerChromeOS::StartRefreshSchedulerIfReady() {
255 if (core()->refresh_scheduler()) 267 if (core()->refresh_scheduler())
256 return; // Already started. 268 return; // Already started.
(...skipping 10 matching lines...) Expand all
267 // start the scheduler. The |component_policy_service_| will call back into 279 // start the scheduler. The |component_policy_service_| will call back into
268 // OnComponentCloudPolicyUpdated() once it's ready. 280 // OnComponentCloudPolicyUpdated() once it's ready.
269 return; 281 return;
270 } 282 }
271 283
272 StartRefreshScheduler(); 284 StartRefreshScheduler();
273 core()->TrackRefreshDelayPref(local_state_, prefs::kUserPolicyRefreshRate); 285 core()->TrackRefreshDelayPref(local_state_, prefs::kUserPolicyRefreshRate);
274 } 286 }
275 287
276 } // namespace policy 288 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698