| 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/auto_enrollment_client.h" | 5 #include "chrome/browser/chromeos/policy/auto_enrollment_client.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/guid.h" | 10 #include "base/guid.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 // UMA histogram names. | 38 // UMA histogram names. |
| 39 const char kUMAProtocolTime[] = "Enterprise.AutoEnrollmentProtocolTime"; | 39 const char kUMAProtocolTime[] = "Enterprise.AutoEnrollmentProtocolTime"; |
| 40 const char kUMAExtraTime[] = "Enterprise.AutoEnrollmentExtraTime"; | 40 const char kUMAExtraTime[] = "Enterprise.AutoEnrollmentExtraTime"; |
| 41 const char kUMARequestStatus[] = "Enterprise.AutoEnrollmentRequestStatus"; | 41 const char kUMARequestStatus[] = "Enterprise.AutoEnrollmentRequestStatus"; |
| 42 const char kUMANetworkErrorCode[] = | 42 const char kUMANetworkErrorCode[] = |
| 43 "Enterprise.AutoEnrollmentRequestNetworkErrorCode"; | 43 "Enterprise.AutoEnrollmentRequestNetworkErrorCode"; |
| 44 | 44 |
| 45 // Returns the power of the next power-of-2 starting at |value|. | 45 // Returns the power of the next power-of-2 starting at |value|. |
| 46 int NextPowerOf2(int64 value) { | 46 int NextPowerOf2(int64_t value) { |
| 47 for (int i = 0; i <= AutoEnrollmentClient::kMaximumPower; ++i) { | 47 for (int i = 0; i <= AutoEnrollmentClient::kMaximumPower; ++i) { |
| 48 if ((INT64_C(1) << i) >= value) | 48 if ((INT64_C(1) << i) >= value) |
| 49 return i; | 49 return i; |
| 50 } | 50 } |
| 51 // No other value can be represented in an int64. | 51 // No other value can be represented in an int64_t. |
| 52 return AutoEnrollmentClient::kMaximumPower + 1; | 52 return AutoEnrollmentClient::kMaximumPower + 1; |
| 53 } | 53 } |
| 54 | 54 |
| 55 // Sets or clears a value in a dictionary. | 55 // Sets or clears a value in a dictionary. |
| 56 void UpdateDict(base::DictionaryValue* dict, | 56 void UpdateDict(base::DictionaryValue* dict, |
| 57 const char* pref_path, | 57 const char* pref_path, |
| 58 bool set_or_clear, | 58 bool set_or_clear, |
| 59 base::Value* value) { | 59 base::Value* value) { |
| 60 scoped_ptr<base::Value> scoped_value(value); | 60 scoped_ptr<base::Value> scoped_value(value); |
| 61 if (set_or_clear) | 61 if (set_or_clear) |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 restore_mode == RESTORE_MODE_REENROLLMENT_ENFORCED); | 229 restore_mode == RESTORE_MODE_REENROLLMENT_ENFORCED); |
| 230 | 230 |
| 231 ReportProgress(trigger_enrollment ? AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT | 231 ReportProgress(trigger_enrollment ? AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT |
| 232 : AUTO_ENROLLMENT_STATE_NO_ENROLLMENT); | 232 : AUTO_ENROLLMENT_STATE_NO_ENROLLMENT); |
| 233 } | 233 } |
| 234 } | 234 } |
| 235 | 235 |
| 236 void AutoEnrollmentClient::SendBucketDownloadRequest() { | 236 void AutoEnrollmentClient::SendBucketDownloadRequest() { |
| 237 // Only power-of-2 moduli are supported for now. These are computed by taking | 237 // Only power-of-2 moduli are supported for now. These are computed by taking |
| 238 // the lower |current_power_| bits of the hash. | 238 // the lower |current_power_| bits of the hash. |
| 239 uint64 remainder = 0; | 239 uint64_t remainder = 0; |
| 240 for (int i = 0; 8 * i < current_power_; ++i) { | 240 for (int i = 0; 8 * i < current_power_; ++i) { |
| 241 uint64 byte = server_backed_state_key_hash_[31 - i] & 0xff; | 241 uint64_t byte = server_backed_state_key_hash_[31 - i] & 0xff; |
| 242 remainder = remainder | (byte << (8 * i)); | 242 remainder = remainder | (byte << (8 * i)); |
| 243 } | 243 } |
| 244 remainder = remainder & ((UINT64_C(1) << current_power_) - 1); | 244 remainder = remainder & ((UINT64_C(1) << current_power_) - 1); |
| 245 | 245 |
| 246 ReportProgress(AUTO_ENROLLMENT_STATE_PENDING); | 246 ReportProgress(AUTO_ENROLLMENT_STATE_PENDING); |
| 247 | 247 |
| 248 request_job_.reset( | 248 request_job_.reset( |
| 249 device_management_service_->CreateJob( | 249 device_management_service_->CreateJob( |
| 250 DeviceManagementRequestJob::TYPE_AUTO_ENROLLMENT, | 250 DeviceManagementRequestJob::TYPE_AUTO_ENROLLMENT, |
| 251 request_context_.get())); | 251 request_context_.get())); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 const em::DeviceManagementResponse& response) { | 314 const em::DeviceManagementResponse& response) { |
| 315 bool progress = false; | 315 bool progress = false; |
| 316 const em::DeviceAutoEnrollmentResponse& enrollment_response = | 316 const em::DeviceAutoEnrollmentResponse& enrollment_response = |
| 317 response.auto_enrollment_response(); | 317 response.auto_enrollment_response(); |
| 318 if (!response.has_auto_enrollment_response()) { | 318 if (!response.has_auto_enrollment_response()) { |
| 319 LOG(ERROR) << "Server failed to provide auto-enrollment response."; | 319 LOG(ERROR) << "Server failed to provide auto-enrollment response."; |
| 320 } else if (enrollment_response.has_expected_modulus()) { | 320 } else if (enrollment_response.has_expected_modulus()) { |
| 321 // Server is asking us to retry with a different modulus. | 321 // Server is asking us to retry with a different modulus. |
| 322 modulus_updates_received_++; | 322 modulus_updates_received_++; |
| 323 | 323 |
| 324 int64 modulus = enrollment_response.expected_modulus(); | 324 int64_t modulus = enrollment_response.expected_modulus(); |
| 325 int power = NextPowerOf2(modulus); | 325 int power = NextPowerOf2(modulus); |
| 326 if ((INT64_C(1) << power) != modulus) { | 326 if ((INT64_C(1) << power) != modulus) { |
| 327 LOG(ERROR) << "Auto enrollment: the server didn't ask for a power-of-2 " | 327 LOG(ERROR) << "Auto enrollment: the server didn't ask for a power-of-2 " |
| 328 << "modulus. Using the closest power-of-2 instead " | 328 << "modulus. Using the closest power-of-2 instead " |
| 329 << "(" << modulus << " vs 2^" << power << ")"; | 329 << "(" << modulus << " vs 2^" << power << ")"; |
| 330 } | 330 } |
| 331 if (modulus_updates_received_ >= 2) { | 331 if (modulus_updates_received_ >= 2) { |
| 332 LOG(ERROR) << "Auto enrollment error: already retried with an updated " | 332 LOG(ERROR) << "Auto enrollment error: already retried with an updated " |
| 333 << "modulus but the server asked for a new one again: " | 333 << "modulus but the server asked for a new one again: " |
| 334 << power; | 334 << power; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 base::TimeDelta delta = kZero; | 429 base::TimeDelta delta = kZero; |
| 430 if (!time_extra_start_.is_null()) | 430 if (!time_extra_start_.is_null()) |
| 431 delta = now - time_extra_start_; | 431 delta = now - time_extra_start_; |
| 432 // This samples |kZero| when there was no need for extra time, so that we can | 432 // This samples |kZero| when there was no need for extra time, so that we can |
| 433 // measure the ratio of users that succeeded without needing a delay to the | 433 // measure the ratio of users that succeeded without needing a delay to the |
| 434 // total users going through OOBE. | 434 // total users going through OOBE. |
| 435 UMA_HISTOGRAM_CUSTOM_TIMES(kUMAExtraTime, delta, kMin, kMax, kBuckets); | 435 UMA_HISTOGRAM_CUSTOM_TIMES(kUMAExtraTime, delta, kMin, kMax, kBuckets); |
| 436 } | 436 } |
| 437 | 437 |
| 438 } // namespace policy | 438 } // namespace policy |
| OLD | NEW |