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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 return i; | 48 return i; |
49 } | 49 } |
50 // No other value can be represented in an int64_t. | 50 // No other value can be represented in an int64_t. |
51 return AutoEnrollmentClient::kMaximumPower + 1; | 51 return AutoEnrollmentClient::kMaximumPower + 1; |
52 } | 52 } |
53 | 53 |
54 // Sets or clears a value in a dictionary. | 54 // Sets or clears a value in a dictionary. |
55 void UpdateDict(base::DictionaryValue* dict, | 55 void UpdateDict(base::DictionaryValue* dict, |
56 const char* pref_path, | 56 const char* pref_path, |
57 bool set_or_clear, | 57 bool set_or_clear, |
58 base::Value* value) { | 58 std::unique_ptr<base::Value> value) { |
59 std::unique_ptr<base::Value> scoped_value(value); | |
60 if (set_or_clear) | 59 if (set_or_clear) |
61 dict->Set(pref_path, scoped_value.release()); | 60 dict->Set(pref_path, std::move(value)); |
62 else | 61 else |
63 dict->Remove(pref_path, NULL); | 62 dict->Remove(pref_path, NULL); |
64 } | 63 } |
65 | 64 |
66 // Converts a restore mode enum value from the DM protocol into the | 65 // Converts a restore mode enum value from the DM protocol into the |
67 // corresponding prefs string constant. | 66 // corresponding prefs string constant. |
68 std::string ConvertRestoreMode( | 67 std::string ConvertRestoreMode( |
69 em::DeviceStateRetrievalResponse::RestoreMode restore_mode) { | 68 em::DeviceStateRetrievalResponse::RestoreMode restore_mode) { |
70 switch (restore_mode) { | 69 switch (restore_mode) { |
71 case em::DeviceStateRetrievalResponse::RESTORE_MODE_NONE: | 70 case em::DeviceStateRetrievalResponse::RESTORE_MODE_NONE: |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 int net_error, | 368 int net_error, |
370 const enterprise_management::DeviceManagementResponse& response) { | 369 const enterprise_management::DeviceManagementResponse& response) { |
371 bool progress = false; | 370 bool progress = false; |
372 if (!response.has_device_state_retrieval_response()) { | 371 if (!response.has_device_state_retrieval_response()) { |
373 LOG(ERROR) << "Server failed to provide auto-enrollment response."; | 372 LOG(ERROR) << "Server failed to provide auto-enrollment response."; |
374 } else { | 373 } else { |
375 const em::DeviceStateRetrievalResponse& state_response = | 374 const em::DeviceStateRetrievalResponse& state_response = |
376 response.device_state_retrieval_response(); | 375 response.device_state_retrieval_response(); |
377 { | 376 { |
378 DictionaryPrefUpdate dict(local_state_, prefs::kServerBackedDeviceState); | 377 DictionaryPrefUpdate dict(local_state_, prefs::kServerBackedDeviceState); |
379 UpdateDict(dict.Get(), kDeviceStateManagementDomain, | 378 UpdateDict( |
380 state_response.has_management_domain(), | 379 dict.Get(), kDeviceStateManagementDomain, |
381 new base::Value(state_response.management_domain())); | 380 state_response.has_management_domain(), |
| 381 base::MakeUnique<base::Value>(state_response.management_domain())); |
382 | 382 |
383 std::string restore_mode = | 383 std::string restore_mode = |
384 ConvertRestoreMode(state_response.restore_mode()); | 384 ConvertRestoreMode(state_response.restore_mode()); |
385 UpdateDict(dict.Get(), kDeviceStateRestoreMode, !restore_mode.empty(), | 385 UpdateDict(dict.Get(), kDeviceStateRestoreMode, !restore_mode.empty(), |
386 new base::Value(restore_mode)); | 386 base::MakeUnique<base::Value>(restore_mode)); |
387 | 387 |
388 UpdateDict(dict.Get(), kDeviceStateDisabledMessage, | 388 UpdateDict(dict.Get(), kDeviceStateDisabledMessage, |
389 state_response.has_disabled_state(), | 389 state_response.has_disabled_state(), |
390 new base::Value(state_response.disabled_state().message())); | 390 base::MakeUnique<base::Value>( |
| 391 state_response.disabled_state().message())); |
391 | 392 |
392 // Logging as "WARNING" to make sure it's preserved in the logs. | 393 // Logging as "WARNING" to make sure it's preserved in the logs. |
393 LOG(WARNING) << "Restore mode: " << restore_mode; | 394 LOG(WARNING) << "Restore mode: " << restore_mode; |
394 } | 395 } |
395 local_state_->CommitPendingWrite(); | 396 local_state_->CommitPendingWrite(); |
396 device_state_available_ = true; | 397 device_state_available_ = true; |
397 progress = true; | 398 progress = true; |
398 } | 399 } |
399 | 400 |
400 return progress; | 401 return progress; |
(...skipping 24 matching lines...) Expand all Loading... |
425 base::TimeDelta delta = kZero; | 426 base::TimeDelta delta = kZero; |
426 if (!time_extra_start_.is_null()) | 427 if (!time_extra_start_.is_null()) |
427 delta = now - time_extra_start_; | 428 delta = now - time_extra_start_; |
428 // This samples |kZero| when there was no need for extra time, so that we can | 429 // This samples |kZero| when there was no need for extra time, so that we can |
429 // measure the ratio of users that succeeded without needing a delay to the | 430 // measure the ratio of users that succeeded without needing a delay to the |
430 // total users going through OOBE. | 431 // total users going through OOBE. |
431 UMA_HISTOGRAM_CUSTOM_TIMES(kUMAExtraTime, delta, kMin, kMax, kBuckets); | 432 UMA_HISTOGRAM_CUSTOM_TIMES(kUMAExtraTime, delta, kMin, kMax, kBuckets); |
432 } | 433 } |
433 | 434 |
434 } // namespace policy | 435 } // namespace policy |
OLD | NEW |