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

Unified Diff: chromeos/pairing/fake_host_pairing_controller.cc

Issue 387163002: Move Chrome OS pairing interface to chrome/browser/chromeos (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Leave chromeos/pairing intact for try jobs Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chromeos/pairing/fake_host_pairing_controller.cc
diff --git a/chromeos/pairing/fake_host_pairing_controller.cc b/chromeos/pairing/fake_host_pairing_controller.cc
deleted file mode 100644
index f98c2d179d6721077c64bfaa305a34ce2a7fa96e..0000000000000000000000000000000000000000
--- a/chromeos/pairing/fake_host_pairing_controller.cc
+++ /dev/null
@@ -1,192 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chromeos/pairing/fake_host_pairing_controller.h"
-
-#include <map>
-#include <vector>
-
-#include "base/bind.h"
-#include "base/logging.h"
-#include "base/message_loop/message_loop.h"
-#include "base/rand_util.h"
-#include "base/strings/string_number_conversions.h"
-#include "base/strings/string_split.h"
-
-namespace {
-
-const int kUpdateStepsNumber = 10;
-const int kDefaultAsyncDurationMs = 3000;
-const size_t kCodeLength = 6;
-
-} // namespace
-
-namespace chromeos {
-
-FakeHostPairingController::FakeHostPairingController(const std::string& config)
- : current_stage_(STAGE_NONE),
- enrollment_should_fail_(false),
- start_after_update_(false) {
- ApplyConfig(config);
- AddObserver(this);
-}
-
-FakeHostPairingController::~FakeHostPairingController() {
- RemoveObserver(this);
-}
-
-void FakeHostPairingController::ApplyConfig(const std::string& config) {
- typedef std::vector<std::string> Tokens;
-
- base::StringPairs kv_pairs;
- CHECK(base::SplitStringIntoKeyValuePairs(config, ':', ',', &kv_pairs))
- << "Wrong config format.";
- std::map<std::string, std::string> dict(kv_pairs.begin(), kv_pairs.end());
-
- if (dict.count("async_duration")) {
- int ms = 0;
- CHECK(base::StringToInt(dict["async_duration"], &ms))
- << "Wrong 'async_duration' format.";
- async_duration_ = base::TimeDelta::FromMilliseconds(ms);
- } else {
- async_duration_ =
- base::TimeDelta::FromMilliseconds(kDefaultAsyncDurationMs);
- }
-
- start_after_update_ = dict["start_after_update"] == "1";
-
- enrollment_should_fail_ = dict["fail_enrollment"] == "1";
-
- if (dict.count("code")) {
- confirmation_code_ = dict["code"];
- } else {
- confirmation_code_.clear();
- for (size_t i = 0; i < kCodeLength; ++i)
- confirmation_code_.push_back(base::RandInt('0', '9'));
- }
- CHECK(confirmation_code_.length() == kCodeLength &&
- confirmation_code_.find_first_not_of("0123456789") == std::string::npos)
- << "Wrong 'code' format.";
-
- device_name_ =
- dict.count("device_name") ? dict["device_name"] : "Chromebox-01";
-
- enrollment_domain_ = dict.count("domain") ? dict["domain"] : "example.com";
-}
-
-void FakeHostPairingController::ChangeStage(Stage new_stage) {
- if (current_stage_ == new_stage)
- return;
- current_stage_ = new_stage;
- FOR_EACH_OBSERVER(Observer, observers_, PairingStageChanged(new_stage));
-}
-
-void FakeHostPairingController::ChangeStageLater(Stage new_stage) {
- base::MessageLoop::current()->PostDelayedTask(
- FROM_HERE,
- base::Bind(&FakeHostPairingController::ChangeStage,
- base::Unretained(this),
- new_stage),
- async_duration_);
-}
-
-void FakeHostPairingController::SetUpdateProgress(int step) {
- UpdateProgress progress;
- progress.progress = double(step) / kUpdateStepsNumber;
- FOR_EACH_OBSERVER(Observer, observers_, UpdateAdvanced(progress));
- base::Closure task;
- if (step >= kUpdateStepsNumber) {
- task = base::Bind(&FakeHostPairingController::ChangeStage,
- base::Unretained(this),
- STAGE_WAITING_FOR_CONTROLLER_AFTER_UPDATE);
- } else {
- task = base::Bind(&FakeHostPairingController::SetUpdateProgress,
- base::Unretained(this),
- step + 1);
- }
- base::MessageLoop::current()->PostDelayedTask(
- FROM_HERE, task, async_duration_ / kUpdateStepsNumber);
-}
-
-void FakeHostPairingController::AddObserver(Observer* observer) {
- observers_.AddObserver(observer);
-}
-
-void FakeHostPairingController::RemoveObserver(Observer* observer) {
- observers_.RemoveObserver(observer);
-}
-
-HostPairingController::Stage FakeHostPairingController::GetCurrentStage() {
- return current_stage_;
-}
-
-void FakeHostPairingController::StartPairing() {
- CHECK(current_stage_ == STAGE_NONE);
- if (start_after_update_) {
- ChangeStage(STAGE_WAITING_FOR_CONTROLLER_AFTER_UPDATE);
- } else {
- ChangeStage(STAGE_WAITING_FOR_CONTROLLER);
- }
-}
-
-std::string FakeHostPairingController::GetDeviceName() {
- return device_name_;
-}
-
-std::string FakeHostPairingController::GetConfirmationCode() {
- CHECK(current_stage_ == STAGE_WAITING_FOR_CODE_CONFIRMATION);
- return confirmation_code_;
-}
-
-std::string FakeHostPairingController::GetEnrollmentDomain() {
- return enrollment_domain_;
-}
-
-void FakeHostPairingController::PairingStageChanged(Stage new_stage) {
- switch (new_stage) {
- case STAGE_WAITING_FOR_CONTROLLER: {
- ChangeStageLater(STAGE_WAITING_FOR_CODE_CONFIRMATION);
- break;
- }
- case STAGE_WAITING_FOR_CODE_CONFIRMATION: {
- ChangeStageLater(STAGE_UPDATING);
- break;
- }
- case STAGE_UPDATING: {
- SetUpdateProgress(0);
- break;
- }
- case STAGE_WAITING_FOR_CONTROLLER_AFTER_UPDATE: {
- ChangeStageLater(STAGE_WAITING_FOR_CREDENTIALS);
- break;
- }
- case STAGE_WAITING_FOR_CREDENTIALS: {
- ChangeStageLater(STAGE_ENROLLING);
- break;
- }
- case STAGE_ENROLLING: {
- if (enrollment_should_fail_) {
- enrollment_should_fail_ = false;
- ChangeStageLater(STAGE_ENROLLMENT_ERROR);
- } else {
- ChangeStageLater(STAGE_PAIRING_DONE);
- }
- break;
- }
- case STAGE_ENROLLMENT_ERROR: {
- ChangeStageLater(STAGE_WAITING_FOR_CONTROLLER_AFTER_UPDATE);
- break;
- }
- case STAGE_PAIRING_DONE: {
- ChangeStageLater(STAGE_FINISHED);
- break;
- }
- default: { break; }
- }
-}
-
-void FakeHostPairingController::UpdateAdvanced(const UpdateProgress& progress) {
-}
-
-} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698