OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/device_token_fetcher.h" | 5 #include "chrome/browser/policy/device_token_fetcher.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "chrome/browser/policy/cloud_policy_cache.h" | 10 #include "chrome/browser/policy/cloud_policy_cache_base.h" |
11 #include "chrome/browser/policy/device_management_service.h" | 11 #include "chrome/browser/policy/device_management_service.h" |
12 #include "chrome/browser/policy/proto/device_management_constants.h" | 12 #include "chrome/browser/policy/proto/device_management_constants.h" |
13 #include "chrome/browser/policy/proto/device_management_local.pb.h" | 13 #include "chrome/browser/policy/proto/device_management_local.pb.h" |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 // Retry after 3 seconds (with exponential backoff) after token fetch errors. | 17 // Retry after 3 seconds (with exponential backoff) after token fetch errors. |
18 const int64 kTokenFetchErrorDelayMilliseconds = 3 * 1000; | 18 const int64 kTokenFetchErrorDelayMilliseconds = 3 * 1000; |
19 // For unmanaged devices, check once per day whether they're still unmanaged. | 19 // For unmanaged devices, check once per day whether they're still unmanaged. |
20 const int64 kUnmanagedDeviceRefreshRateMilliseconds = 24 * 60 * 60 * 1000; | 20 const int64 kUnmanagedDeviceRefreshRateMilliseconds = 24 * 60 * 60 * 1000; |
21 | 21 |
22 } // namespace | 22 } // namespace |
23 | 23 |
24 namespace policy { | 24 namespace policy { |
25 | 25 |
26 namespace em = enterprise_management; | 26 namespace em = enterprise_management; |
27 | 27 |
28 DeviceTokenFetcher::DeviceTokenFetcher( | 28 DeviceTokenFetcher::DeviceTokenFetcher( |
29 DeviceManagementService* service, | 29 DeviceManagementService* service, |
30 CloudPolicyCache* cache) | 30 CloudPolicyCacheBase* cache) |
31 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 31 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
32 Initialize(service, | 32 Initialize(service, |
33 cache, | 33 cache, |
34 kTokenFetchErrorDelayMilliseconds, | 34 kTokenFetchErrorDelayMilliseconds, |
35 kUnmanagedDeviceRefreshRateMilliseconds); | 35 kUnmanagedDeviceRefreshRateMilliseconds); |
36 } | 36 } |
37 | 37 |
38 DeviceTokenFetcher::DeviceTokenFetcher( | 38 DeviceTokenFetcher::DeviceTokenFetcher( |
39 DeviceManagementService* service, | 39 DeviceManagementService* service, |
40 CloudPolicyCache* cache, | 40 CloudPolicyCacheBase* cache, |
41 int64 token_fetch_error_delay_ms, | 41 int64 token_fetch_error_delay_ms, |
42 int64 unmanaged_device_refresh_rate_ms) | 42 int64 unmanaged_device_refresh_rate_ms) |
43 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 43 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
44 Initialize(service, | 44 Initialize(service, |
45 cache, | 45 cache, |
46 token_fetch_error_delay_ms, | 46 token_fetch_error_delay_ms, |
47 unmanaged_device_refresh_rate_ms); | 47 unmanaged_device_refresh_rate_ms); |
48 } | 48 } |
49 | 49 |
50 DeviceTokenFetcher::~DeviceTokenFetcher() { | 50 DeviceTokenFetcher::~DeviceTokenFetcher() { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 107 |
108 void DeviceTokenFetcher::OnError(DeviceManagementBackend::ErrorCode code) { | 108 void DeviceTokenFetcher::OnError(DeviceManagementBackend::ErrorCode code) { |
109 if (code == DeviceManagementBackend::kErrorServiceManagementNotSupported) { | 109 if (code == DeviceManagementBackend::kErrorServiceManagementNotSupported) { |
110 cache_->SetUnmanaged(); | 110 cache_->SetUnmanaged(); |
111 SetState(STATE_UNMANAGED); | 111 SetState(STATE_UNMANAGED); |
112 } | 112 } |
113 SetState(STATE_ERROR); | 113 SetState(STATE_ERROR); |
114 } | 114 } |
115 | 115 |
116 void DeviceTokenFetcher::Initialize(DeviceManagementService* service, | 116 void DeviceTokenFetcher::Initialize(DeviceManagementService* service, |
117 CloudPolicyCache* cache, | 117 CloudPolicyCacheBase* cache, |
118 int64 token_fetch_error_delay_ms, | 118 int64 token_fetch_error_delay_ms, |
119 int64 unmanaged_device_refresh_rate_ms) { | 119 int64 unmanaged_device_refresh_rate_ms) { |
120 service_ = service; | 120 service_ = service; |
121 cache_ = cache; | 121 cache_ = cache; |
122 token_fetch_error_delay_ms_ = token_fetch_error_delay_ms; | 122 token_fetch_error_delay_ms_ = token_fetch_error_delay_ms; |
123 effective_token_fetch_error_delay_ms_ = token_fetch_error_delay_ms; | 123 effective_token_fetch_error_delay_ms_ = token_fetch_error_delay_ms; |
124 unmanaged_device_refresh_rate_ms_ = unmanaged_device_refresh_rate_ms; | 124 unmanaged_device_refresh_rate_ms_ = unmanaged_device_refresh_rate_ms; |
125 state_ = STATE_INACTIVE; | 125 state_ = STATE_INACTIVE; |
126 retry_task_ = NULL; | 126 retry_task_ = NULL; |
127 | 127 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 } | 183 } |
184 | 184 |
185 void DeviceTokenFetcher::CancelRetryTask() { | 185 void DeviceTokenFetcher::CancelRetryTask() { |
186 if (retry_task_) { | 186 if (retry_task_) { |
187 retry_task_->Cancel(); | 187 retry_task_->Cancel(); |
188 retry_task_ = NULL; | 188 retry_task_ = NULL; |
189 } | 189 } |
190 } | 190 } |
191 | 191 |
192 } // namespace policy | 192 } // namespace policy |
OLD | NEW |