| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/pairing/fake_host_pairing_controller.h" | 5 #include "components/pairing/fake_host_pairing_controller.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 ApplyConfig(config); | 34 ApplyConfig(config); |
| 35 AddObserver(this); | 35 AddObserver(this); |
| 36 } | 36 } |
| 37 | 37 |
| 38 FakeHostPairingController::~FakeHostPairingController() { | 38 FakeHostPairingController::~FakeHostPairingController() { |
| 39 RemoveObserver(this); | 39 RemoveObserver(this); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void FakeHostPairingController::ApplyConfig(const std::string& config) { | 42 void FakeHostPairingController::ApplyConfig(const std::string& config) { |
| 43 base::StringPairs kv_pairs; | 43 base::StringPairs kv_pairs; |
| 44 CHECK(base::SplitStringIntoKeyValuePairs(config, ':', ',', &kv_pairs)) | 44 // Wrong config format. |
| 45 << "Wrong config format."; | 45 CHECK(base::SplitStringIntoKeyValuePairs(config, ':', ',', &kv_pairs)); |
| 46 std::map<std::string, std::string> dict(kv_pairs.begin(), kv_pairs.end()); | 46 std::map<std::string, std::string> dict(kv_pairs.begin(), kv_pairs.end()); |
| 47 | 47 |
| 48 if (dict.count("async_duration")) { | 48 if (dict.count("async_duration")) { |
| 49 int ms = 0; | 49 int ms = 0; |
| 50 CHECK(base::StringToInt(dict["async_duration"], &ms)) | 50 // Wrong 'async_duration' format. |
| 51 << "Wrong 'async_duration' format."; | 51 CHECK(base::StringToInt(dict["async_duration"], &ms)); |
| 52 async_duration_ = base::TimeDelta::FromMilliseconds(ms); | 52 async_duration_ = base::TimeDelta::FromMilliseconds(ms); |
| 53 } else { | 53 } else { |
| 54 async_duration_ = | 54 async_duration_ = |
| 55 base::TimeDelta::FromMilliseconds(kDefaultAsyncDurationMs); | 55 base::TimeDelta::FromMilliseconds(kDefaultAsyncDurationMs); |
| 56 } | 56 } |
| 57 | 57 |
| 58 start_after_update_ = dict["start_after_update"] == "1"; | 58 start_after_update_ = dict["start_after_update"] == "1"; |
| 59 | 59 |
| 60 enrollment_should_fail_ = dict["fail_enrollment"] == "1"; | 60 enrollment_should_fail_ = dict["fail_enrollment"] == "1"; |
| 61 | 61 |
| 62 if (dict.count("code")) { | 62 if (dict.count("code")) { |
| 63 confirmation_code_ = dict["code"]; | 63 confirmation_code_ = dict["code"]; |
| 64 } else { | 64 } else { |
| 65 confirmation_code_.clear(); | 65 confirmation_code_.clear(); |
| 66 for (size_t i = 0; i < kCodeLength; ++i) | 66 for (size_t i = 0; i < kCodeLength; ++i) |
| 67 confirmation_code_.push_back(base::RandInt('0', '9')); | 67 confirmation_code_.push_back(base::RandInt('0', '9')); |
| 68 } | 68 } |
| 69 // Wrong 'code' format. |
| 69 CHECK(confirmation_code_.length() == kCodeLength && | 70 CHECK(confirmation_code_.length() == kCodeLength && |
| 70 confirmation_code_.find_first_not_of("0123456789") == std::string::npos) | 71 confirmation_code_.find_first_not_of("0123456789") == |
| 71 << "Wrong 'code' format."; | 72 std::string::npos); |
| 72 | 73 |
| 73 device_name_ = | 74 device_name_ = |
| 74 dict.count("device_name") ? dict["device_name"] : "Chromebox-01"; | 75 dict.count("device_name") ? dict["device_name"] : "Chromebox-01"; |
| 75 | 76 |
| 76 enrollment_domain_ = dict.count("domain") ? dict["domain"] : "example.com"; | 77 enrollment_domain_ = dict.count("domain") ? dict["domain"] : "example.com"; |
| 77 } | 78 } |
| 78 | 79 |
| 79 void FakeHostPairingController::ChangeStage(Stage new_stage) { | 80 void FakeHostPairingController::ChangeStage(Stage new_stage) { |
| 80 if (current_stage_ == new_stage) | 81 if (current_stage_ == new_stage) |
| 81 return; | 82 return; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 } | 178 } |
| 178 case STAGE_ENROLLMENT_SUCCESS: { | 179 case STAGE_ENROLLMENT_SUCCESS: { |
| 179 ChangeStageLater(STAGE_FINISHED); | 180 ChangeStageLater(STAGE_FINISHED); |
| 180 break; | 181 break; |
| 181 } | 182 } |
| 182 default: { break; } | 183 default: { break; } |
| 183 } | 184 } |
| 184 } | 185 } |
| 185 | 186 |
| 186 } // namespace pairing_chromeos | 187 } // namespace pairing_chromeos |
| OLD | NEW |