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/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "chrome/browser/policy/cloud_policy_cache_base.h" | 12 #include "chrome/browser/policy/cloud_policy_cache_base.h" |
13 #include "chrome/browser/policy/device_management_service.h" | 13 #include "chrome/browser/policy/device_management_service.h" |
| 14 #include "chrome/browser/policy/enterprise_metrics.h" |
14 #include "chrome/browser/policy/proto/device_management_constants.h" | 15 #include "chrome/browser/policy/proto/device_management_constants.h" |
15 #include "chrome/browser/policy/proto/device_management_local.pb.h" | 16 #include "chrome/browser/policy/proto/device_management_local.pb.h" |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 // Retry after 5 minutes (with exponential backoff) after token fetch errors. | 20 // Retry after 5 minutes (with exponential backoff) after token fetch errors. |
20 const int64 kTokenFetchErrorDelayMilliseconds = 5 * 60 * 1000; | 21 const int64 kTokenFetchErrorDelayMilliseconds = 5 * 60 * 1000; |
21 // Retry after max 3 hours after token fetch errors. | 22 // Retry after max 3 hours after token fetch errors. |
22 const int64 kTokenFetchErrorMaxDelayMilliseconds = 3 * 60 * 60 * 1000; | 23 const int64 kTokenFetchErrorMaxDelayMilliseconds = 3 * 60 * 60 * 1000; |
23 // For unmanaged devices, check once per day whether they're still unmanaged. | 24 // For unmanaged devices, check once per day whether they're still unmanaged. |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 } | 113 } |
113 | 114 |
114 void DeviceTokenFetcher::RemoveObserver( | 115 void DeviceTokenFetcher::RemoveObserver( |
115 DeviceTokenFetcher::Observer* observer) { | 116 DeviceTokenFetcher::Observer* observer) { |
116 observer_list_.RemoveObserver(observer); | 117 observer_list_.RemoveObserver(observer); |
117 } | 118 } |
118 | 119 |
119 void DeviceTokenFetcher::HandleRegisterResponse( | 120 void DeviceTokenFetcher::HandleRegisterResponse( |
120 const em::DeviceRegisterResponse& response) { | 121 const em::DeviceRegisterResponse& response) { |
121 if (response.has_device_management_token()) { | 122 if (response.has_device_management_token()) { |
| 123 em::LogTokenOperation(em::kTokenFetchOK); |
122 device_token_ = response.device_management_token(); | 124 device_token_ = response.device_management_token(); |
123 SetState(STATE_TOKEN_AVAILABLE); | 125 SetState(STATE_TOKEN_AVAILABLE); |
124 } else { | 126 } else { |
125 NOTREACHED(); | 127 NOTREACHED(); |
| 128 em::LogTokenOperation(em::kTokenFetchBadResponse); |
126 SetState(STATE_ERROR); | 129 SetState(STATE_ERROR); |
127 } | 130 } |
128 } | 131 } |
129 | 132 |
130 void DeviceTokenFetcher::OnError(DeviceManagementBackend::ErrorCode code) { | 133 void DeviceTokenFetcher::OnError(DeviceManagementBackend::ErrorCode code) { |
131 switch (code) { | 134 switch (code) { |
132 case DeviceManagementBackend::kErrorServiceManagementNotSupported: | 135 case DeviceManagementBackend::kErrorServiceManagementNotSupported: |
133 cache_->SetUnmanaged(); | 136 cache_->SetUnmanaged(); |
134 SetState(STATE_UNMANAGED); | 137 SetState(STATE_UNMANAGED); |
135 break; | 138 break; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 case STATE_UNMANAGED: | 241 case STATE_UNMANAGED: |
239 case STATE_ERROR: | 242 case STATE_ERROR: |
240 case STATE_TEMPORARY_ERROR: | 243 case STATE_TEMPORARY_ERROR: |
241 case STATE_BAD_AUTH: | 244 case STATE_BAD_AUTH: |
242 FetchTokenInternal(); | 245 FetchTokenInternal(); |
243 break; | 246 break; |
244 } | 247 } |
245 } | 248 } |
246 | 249 |
247 } // namespace policy | 250 } // namespace policy |
OLD | NEW |