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/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" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 const char kUMAInitialFetchOAuth2Error[] = | 44 const char kUMAInitialFetchOAuth2Error[] = |
45 "Enterprise.UserPolicyChromeOS.InitialFetch.OAuth2Error"; | 45 "Enterprise.UserPolicyChromeOS.InitialFetch.OAuth2Error"; |
46 const char kUMAInitialFetchOAuth2NetworkError[] = | 46 const char kUMAInitialFetchOAuth2NetworkError[] = |
47 "Enterprise.UserPolicyChromeOS.InitialFetch.OAuth2NetworkError"; | 47 "Enterprise.UserPolicyChromeOS.InitialFetch.OAuth2NetworkError"; |
48 | 48 |
49 } // namespace | 49 } // namespace |
50 | 50 |
51 UserCloudPolicyManagerChromeOS::UserCloudPolicyManagerChromeOS( | 51 UserCloudPolicyManagerChromeOS::UserCloudPolicyManagerChromeOS( |
52 scoped_ptr<CloudPolicyStore> store, | 52 scoped_ptr<CloudPolicyStore> store, |
53 scoped_ptr<ResourceCache> resource_cache, | 53 scoped_ptr<ResourceCache> resource_cache, |
54 bool wait_for_policy_fetch) | 54 bool wait_for_policy_fetch, |
| 55 base::TimeDelta initial_policy_fetch_timeout) |
55 : CloudPolicyManager( | 56 : CloudPolicyManager( |
56 PolicyNamespaceKey(dm_protocol::kChromeUserPolicyType, std::string()), | 57 PolicyNamespaceKey(dm_protocol::kChromeUserPolicyType, std::string()), |
57 store.get()), | 58 store.get()), |
58 store_(store.Pass()), | 59 store_(store.Pass()), |
59 wait_for_policy_fetch_(wait_for_policy_fetch) { | 60 wait_for_policy_fetch_(wait_for_policy_fetch), |
| 61 policy_fetch_timeout_(false, false) { |
60 time_init_started_ = base::Time::Now(); | 62 time_init_started_ = base::Time::Now(); |
| 63 if (wait_for_policy_fetch_) { |
| 64 policy_fetch_timeout_.Start( |
| 65 FROM_HERE, |
| 66 initial_policy_fetch_timeout, |
| 67 base::Bind(&UserCloudPolicyManagerChromeOS::CancelWaitForPolicyFetch, |
| 68 base::Unretained(this))); |
| 69 } |
61 if (resource_cache) { | 70 if (resource_cache) { |
62 // TODO(joaodasilva): Move the backend from the FILE thread to the blocking | 71 // TODO(joaodasilva): Move the backend from the FILE thread to the blocking |
63 // pool. | 72 // pool. |
64 component_policy_service_.reset(new ComponentCloudPolicyService( | 73 component_policy_service_.reset(new ComponentCloudPolicyService( |
65 this, | 74 this, |
66 store_.get(), | 75 store_.get(), |
67 resource_cache.Pass(), | 76 resource_cache.Pass(), |
68 content::BrowserThread::GetMessageLoopProxyForThread( | 77 content::BrowserThread::GetMessageLoopProxyForThread( |
69 content::BrowserThread::FILE), | 78 content::BrowserThread::FILE), |
70 content::BrowserThread::GetMessageLoopProxyForThread( | 79 content::BrowserThread::GetMessageLoopProxyForThread( |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 bool success) { | 308 bool success) { |
300 | 309 |
301 const base::Time now = base::Time::Now(); | 310 const base::Time now = base::Time::Now(); |
302 UMA_HISTOGRAM_TIMES(kUMAInitialFetchDelayPolicyFetch, | 311 UMA_HISTOGRAM_TIMES(kUMAInitialFetchDelayPolicyFetch, |
303 now - time_client_registered_); | 312 now - time_client_registered_); |
304 UMA_HISTOGRAM_TIMES(kUMAInitialFetchDelayTotal, now - time_init_started_); | 313 UMA_HISTOGRAM_TIMES(kUMAInitialFetchDelayTotal, now - time_init_started_); |
305 CancelWaitForPolicyFetch(); | 314 CancelWaitForPolicyFetch(); |
306 } | 315 } |
307 | 316 |
308 void UserCloudPolicyManagerChromeOS::CancelWaitForPolicyFetch() { | 317 void UserCloudPolicyManagerChromeOS::CancelWaitForPolicyFetch() { |
| 318 if (!wait_for_policy_fetch_) |
| 319 return; |
| 320 |
309 wait_for_policy_fetch_ = false; | 321 wait_for_policy_fetch_ = false; |
310 CheckAndPublishPolicy(); | 322 CheckAndPublishPolicy(); |
311 // Now that |wait_for_policy_fetch_| is guaranteed to be false, the scheduler | 323 // Now that |wait_for_policy_fetch_| is guaranteed to be false, the scheduler |
312 // can be started. | 324 // can be started. |
313 StartRefreshSchedulerIfReady(); | 325 StartRefreshSchedulerIfReady(); |
314 } | 326 } |
315 | 327 |
316 void UserCloudPolicyManagerChromeOS::StartRefreshSchedulerIfReady() { | 328 void UserCloudPolicyManagerChromeOS::StartRefreshSchedulerIfReady() { |
317 if (core()->refresh_scheduler()) | 329 if (core()->refresh_scheduler()) |
318 return; // Already started. | 330 return; // Already started. |
(...skipping 10 matching lines...) Expand all Loading... |
329 // start the scheduler. The |component_policy_service_| will call back into | 341 // start the scheduler. The |component_policy_service_| will call back into |
330 // OnComponentCloudPolicyUpdated() once it's ready. | 342 // OnComponentCloudPolicyUpdated() once it's ready. |
331 return; | 343 return; |
332 } | 344 } |
333 | 345 |
334 StartRefreshScheduler(); | 346 StartRefreshScheduler(); |
335 core()->TrackRefreshDelayPref(local_state_, prefs::kUserPolicyRefreshRate); | 347 core()->TrackRefreshDelayPref(local_state_, prefs::kUserPolicyRefreshRate); |
336 } | 348 } |
337 | 349 |
338 } // namespace policy | 350 } // namespace policy |
OLD | NEW |