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

Side by Side Diff: chrome/browser/policy/device_token_fetcher.cc

Issue 9403010: Add support for kiosk mode on the client. Make sure the settings are written in the lockbox. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Made registration fail on missing enrollment type. Created 8 years, 10 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/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/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/time.h" 11 #include "base/time.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/cloud_policy_constants.h" 13 #include "chrome/browser/policy/cloud_policy_constants.h"
14 #include "chrome/browser/policy/cloud_policy_data_store.h" 14 #include "chrome/browser/policy/cloud_policy_data_store.h"
15 #include "chrome/browser/policy/delayed_work_scheduler.h" 15 #include "chrome/browser/policy/delayed_work_scheduler.h"
16 #include "chrome/browser/policy/device_management_service.h" 16 #include "chrome/browser/policy/device_management_service.h"
17 #include "chrome/browser/policy/enterprise_install_attributes.h"
17 #include "chrome/browser/policy/enterprise_metrics.h" 18 #include "chrome/browser/policy/enterprise_metrics.h"
18 #include "chrome/browser/policy/policy_notifier.h" 19 #include "chrome/browser/policy/policy_notifier.h"
19 #include "chrome/browser/policy/proto/device_management_local.pb.h" 20 #include "chrome/browser/policy/proto/device_management_local.pb.h"
20 21
22 namespace em = enterprise_management;
23
21 namespace policy { 24 namespace policy {
22 25
23 namespace { 26 namespace {
24 27
25 // Retry after 5 minutes (with exponential backoff) after token fetch errors. 28 // Retry after 5 minutes (with exponential backoff) after token fetch errors.
26 const int64 kTokenFetchErrorDelayMilliseconds = 5 * 60 * 1000; 29 const int64 kTokenFetchErrorDelayMilliseconds = 5 * 60 * 1000;
27 // Retry after max 3 hours after token fetch errors. 30 // Retry after max 3 hours after token fetch errors.
28 const int64 kTokenFetchErrorMaxDelayMilliseconds = 3 * 60 * 60 * 1000; 31 const int64 kTokenFetchErrorMaxDelayMilliseconds = 3 * 60 * 60 * 1000;
29 // For unmanaged devices, check once per day whether they're still unmanaged. 32 // For unmanaged devices, check once per day whether they're still unmanaged.
30 const int64 kUnmanagedDeviceRefreshRateMilliseconds = 24 * 60 * 60 * 1000; 33 const int64 kUnmanagedDeviceRefreshRateMilliseconds = 24 * 60 * 60 * 1000;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 case DM_STATUS_HTTP_STATUS_ERROR: 67 case DM_STATUS_HTTP_STATUS_ERROR:
65 sample = kMetricTokenFetchServerFailed; 68 sample = kMetricTokenFetchServerFailed;
66 break; 69 break;
67 } 70 }
68 if (sample != -1) 71 if (sample != -1)
69 UMA_HISTOGRAM_ENUMERATION(kMetricToken, sample, kMetricTokenSize); 72 UMA_HISTOGRAM_ENUMERATION(kMetricToken, sample, kMetricTokenSize);
70 else 73 else
71 NOTREACHED(); 74 NOTREACHED();
72 } 75 }
73 76
77 // Translates the DeviceRegisterResponse::DeviceMode |mode| to the enum used
78 // internally throughout ChromeOS to represent different device modes.
79 EnterpriseInstallAttributes::DeviceMode
80 TranslateProtobufDeviceMode(em::DeviceRegisterResponse::DeviceMode mode) {
81 switch (mode) {
82 case em::DeviceRegisterResponse::ENTERPRISE:
83 return EnterpriseInstallAttributes::DEVICE_MODE_ENTERPRISE;
84 case em::DeviceRegisterResponse::KIOSK:
85 return EnterpriseInstallAttributes::DEVICE_MODE_KIOSK;
86 }
87 LOG(ERROR) << "Unknown enrollment mode in registration response: " << mode;
88 return EnterpriseInstallAttributes::DEVICE_MODE_UNKNOWN;
89 }
90
74 } // namespace 91 } // namespace
75 92
76 namespace em = enterprise_management;
77
78 DeviceTokenFetcher::DeviceTokenFetcher( 93 DeviceTokenFetcher::DeviceTokenFetcher(
79 DeviceManagementService* service, 94 DeviceManagementService* service,
80 CloudPolicyCacheBase* cache, 95 CloudPolicyCacheBase* cache,
81 CloudPolicyDataStore* data_store, 96 CloudPolicyDataStore* data_store,
82 PolicyNotifier* notifier) 97 PolicyNotifier* notifier)
83 : effective_token_fetch_error_delay_ms_( 98 : effective_token_fetch_error_delay_ms_(
84 kTokenFetchErrorDelayMilliseconds) { 99 kTokenFetchErrorDelayMilliseconds) {
85 Initialize(service, 100 Initialize(service,
86 cache, 101 cache,
87 data_store, 102 data_store,
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 195
181 SampleErrorStatus(status); 196 SampleErrorStatus(status);
182 197
183 switch (status) { 198 switch (status) {
184 case DM_STATUS_SUCCESS: { 199 case DM_STATUS_SUCCESS: {
185 const em::DeviceRegisterResponse& register_response = 200 const em::DeviceRegisterResponse& register_response =
186 response.register_response(); 201 response.register_response();
187 if (register_response.has_device_management_token()) { 202 if (register_response.has_device_management_token()) {
188 UMA_HISTOGRAM_ENUMERATION(kMetricToken, kMetricTokenFetchOK, 203 UMA_HISTOGRAM_ENUMERATION(kMetricToken, kMetricTokenFetchOK,
189 kMetricTokenSize); 204 kMetricTokenSize);
205
206 EnterpriseInstallAttributes::DeviceMode mode =
207 EnterpriseInstallAttributes::DEVICE_MODE_UNKNOWN;
208 if (register_response.has_enrollment_type()) {
209 mode =
210 TranslateProtobufDeviceMode(register_response.enrollment_type());
211 }
212 if (mode == EnterpriseInstallAttributes::DEVICE_MODE_UNKNOWN) {
213 LOG(ERROR) << "Enrollment mode missing or unknown!";
214 SetState(STATE_BAD_ENROLLMENT_MODE);
215 return;
216 }
217 data_store_->set_device_mode(mode);
190 data_store_->SetDeviceToken(register_response.device_management_token(), 218 data_store_->SetDeviceToken(register_response.device_management_token(),
191 false); 219 false);
192 SetState(STATE_TOKEN_AVAILABLE); 220 SetState(STATE_TOKEN_AVAILABLE);
193 } else { 221 } else {
194 NOTREACHED(); 222 NOTREACHED();
195 UMA_HISTOGRAM_ENUMERATION(kMetricToken, kMetricTokenFetchBadResponse, 223 UMA_HISTOGRAM_ENUMERATION(kMetricToken, kMetricTokenFetchBadResponse,
196 kMetricTokenSize); 224 kMetricTokenSize);
197 SetState(STATE_ERROR); 225 SetState(STATE_ERROR);
198 } 226 }
199 return; 227 return;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 case STATE_TOKEN_AVAILABLE: 272 case STATE_TOKEN_AVAILABLE:
245 notifier_->Inform(CloudPolicySubsystem::SUCCESS, 273 notifier_->Inform(CloudPolicySubsystem::SUCCESS,
246 CloudPolicySubsystem::NO_DETAILS, 274 CloudPolicySubsystem::NO_DETAILS,
247 PolicyNotifier::TOKEN_FETCHER); 275 PolicyNotifier::TOKEN_FETCHER);
248 break; 276 break;
249 case STATE_BAD_SERIAL: 277 case STATE_BAD_SERIAL:
250 notifier_->Inform(CloudPolicySubsystem::UNENROLLED, 278 notifier_->Inform(CloudPolicySubsystem::UNENROLLED,
251 CloudPolicySubsystem::BAD_SERIAL_NUMBER, 279 CloudPolicySubsystem::BAD_SERIAL_NUMBER,
252 PolicyNotifier::TOKEN_FETCHER); 280 PolicyNotifier::TOKEN_FETCHER);
253 break; 281 break;
282 case STATE_BAD_ENROLLMENT_MODE:
283 notifier_->Inform(CloudPolicySubsystem::UNENROLLED,
284 CloudPolicySubsystem::BAD_ENROLLMENT_MODE,
285 PolicyNotifier::TOKEN_FETCHER);
286 break;
254 case STATE_UNMANAGED: 287 case STATE_UNMANAGED:
255 delayed_work_at = cache_->last_policy_refresh_time() + 288 delayed_work_at = cache_->last_policy_refresh_time() +
256 base::TimeDelta::FromMilliseconds( 289 base::TimeDelta::FromMilliseconds(
257 kUnmanagedDeviceRefreshRateMilliseconds); 290 kUnmanagedDeviceRefreshRateMilliseconds);
258 notifier_->Inform(CloudPolicySubsystem::UNMANAGED, 291 notifier_->Inform(CloudPolicySubsystem::UNMANAGED,
259 CloudPolicySubsystem::NO_DETAILS, 292 CloudPolicySubsystem::NO_DETAILS,
260 PolicyNotifier::TOKEN_FETCHER); 293 PolicyNotifier::TOKEN_FETCHER);
261 break; 294 break;
262 case STATE_TEMPORARY_ERROR: 295 case STATE_TEMPORARY_ERROR:
263 delayed_work_at = base::Time::Now() + 296 delayed_work_at = base::Time::Now() +
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 // Inform the cache if a token fetch attempt has failed. 332 // Inform the cache if a token fetch attempt has failed.
300 if (state_ != STATE_INACTIVE && state_ != STATE_TOKEN_AVAILABLE) 333 if (state_ != STATE_INACTIVE && state_ != STATE_TOKEN_AVAILABLE)
301 cache_->SetFetchingDone(); 334 cache_->SetFetchingDone();
302 } 335 }
303 336
304 void DeviceTokenFetcher::DoWork() { 337 void DeviceTokenFetcher::DoWork() {
305 switch (state_) { 338 switch (state_) {
306 case STATE_INACTIVE: 339 case STATE_INACTIVE:
307 case STATE_TOKEN_AVAILABLE: 340 case STATE_TOKEN_AVAILABLE:
308 case STATE_BAD_SERIAL: 341 case STATE_BAD_SERIAL:
342 case STATE_BAD_ENROLLMENT_MODE:
309 break; 343 break;
310 case STATE_UNMANAGED: 344 case STATE_UNMANAGED:
311 case STATE_ERROR: 345 case STATE_ERROR:
312 case STATE_TEMPORARY_ERROR: 346 case STATE_TEMPORARY_ERROR:
313 case STATE_BAD_AUTH: 347 case STATE_BAD_AUTH:
314 FetchTokenInternal(); 348 FetchTokenInternal();
315 break; 349 break;
316 } 350 }
317 } 351 }
318 352
319 } // namespace policy 353 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698