| Index: chrome/browser/chromeos/login/screens/controller_pairing_screen.cc
|
| diff --git a/chrome/browser/chromeos/login/screens/controller_pairing_screen.cc b/chrome/browser/chromeos/login/screens/controller_pairing_screen.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..4bf966d20f894215ff765454e0e46e1798862ec9
|
| --- /dev/null
|
| +++ b/chrome/browser/chromeos/login/screens/controller_pairing_screen.cc
|
| @@ -0,0 +1,197 @@
|
| +// 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 "chrome/browser/chromeos/login/screens/controller_pairing_screen.h"
|
| +
|
| +#include "base/values.h"
|
| +#include "base/strings/string_util.h"
|
| +#include "chrome/browser/chromeos/login/auth/user_context.h"
|
| +#include "chrome/browser/chromeos/login/wizard_controller.h"
|
| +#include "chromeos/pairing/fake_controller_pairing_flow.h"
|
| +
|
| +namespace chromeos {
|
| +
|
| +ControllerPairingScreen::ControllerPairingScreen(
|
| + ScreenObserver* observer,
|
| + ControllerPairingScreenActor* actor)
|
| + : WizardScreen(observer),
|
| + actor_(actor),
|
| + flow_(new FakeControllerPairingFlow()),
|
| + current_stage_(ControllerPairingFlow::STAGE_NONE),
|
| + device_preselected_(false) {
|
| + actor_->SetDelegate(this);
|
| + flow_->AddObserver(this);
|
| +}
|
| +
|
| +ControllerPairingScreen::~ControllerPairingScreen() {
|
| + if (actor_)
|
| + actor_->SetDelegate(NULL);
|
| + flow_->RemoveObserver(this);
|
| +}
|
| +
|
| +void ControllerPairingScreen::CommitContextChanges() {
|
| + base::DictionaryValue diff;
|
| + context_.GetChangesAndReset(&diff);
|
| + if (actor_)
|
| + actor_->OnContextChanged(diff);
|
| +}
|
| +
|
| +bool ControllerPairingScreen::ExpectStageIs(Stage stage) const {
|
| + DCHECK(stage == current_stage_);
|
| + if (current_stage_ != stage)
|
| + LOG(ERROR) << "Incorrect stage. Expected: " << stage
|
| + << ", current stage: " << current_stage_;
|
| + return stage == current_stage_;
|
| +}
|
| +
|
| +void ControllerPairingScreen::PrepareToShow() {
|
| +}
|
| +
|
| +void ControllerPairingScreen::Show() {
|
| + if (actor_)
|
| + actor_->Show();
|
| + flow_->StartFlow();
|
| +}
|
| +
|
| +void ControllerPairingScreen::Hide() {
|
| + if (actor_)
|
| + actor_->Hide();
|
| +}
|
| +
|
| +std::string ControllerPairingScreen::GetName() const {
|
| + return WizardController::kControllerPairingScreenName;
|
| +}
|
| +
|
| +// Overridden from ControllerPairingFlow::Observer:
|
| +void ControllerPairingScreen::PairingStageChanged(Stage new_stage) {
|
| + using namespace chromeos::controller_pairing;
|
| + DCHECK(new_stage != current_stage_);
|
| +
|
| + std::string desired_page;
|
| + switch (new_stage) {
|
| + case Stage::STAGE_DEVICES_DISCOVERY: {
|
| + desired_page = kPageDevicesDiscovery;
|
| + context_.SetString(kContextKeySelectedDevice, "");
|
| + device_preselected_ = false;
|
| + break;
|
| + }
|
| + case Stage::STAGE_DEVICE_NOT_FOUND: {
|
| + desired_page = kPageDeviceNotFound;
|
| + break;
|
| + }
|
| + case Stage::STAGE_ESTABLISHING_CONNECTION: {
|
| + desired_page = kPageEstablishingConnection;
|
| + break;
|
| + }
|
| + case Stage::STAGE_ESTABLISHING_CONNECTION_ERROR: {
|
| + desired_page = kPageEstablishingConnectionError;
|
| + break;
|
| + }
|
| + case Stage::STAGE_WAITING_FOR_CODE_CONFIRMATION: {
|
| + desired_page = kPageCodeConfirmation;
|
| + context_.SetString(kContextKeyConfirmationCode,
|
| + flow_->GetConfirmationCode());
|
| + break;
|
| + }
|
| + case Stage::STAGE_HOST_UPDATE_IN_PROGRESS: {
|
| + desired_page = kPageHostUpdate;
|
| + break;
|
| + }
|
| + case Stage::STAGE_HOST_CONNECTION_LOST: {
|
| + desired_page = kPageHostConnectionLost;
|
| + break;
|
| + }
|
| + case Stage::STAGE_WAITING_FOR_CREDENTIALS: {
|
| + desired_page = kPageEnrlollmentIntroduction;
|
| + break;
|
| + }
|
| + case Stage::STAGE_HOST_ENROLLMENT_IN_PROGRESS: {
|
| + desired_page = kPageHostEnrollment;
|
| + break;
|
| + }
|
| + case Stage::STAGE_HOST_ENROLLMENT_ERROR: {
|
| + desired_page = kPageHostEnrollmentError;
|
| + break;
|
| + }
|
| + case Stage::STAGE_PAIRING_DONE: {
|
| + desired_page = kPagePairingDone;
|
| + break;
|
| + }
|
| + case Stage::STAGE_STARTING_SESSION: {
|
| + // TODO(dzhioev): Is it needed?
|
| + break;
|
| + }
|
| + case Stage::STAGE_FINISHED: {
|
| + get_screen_observer()->OnExit(
|
| + WizardController::CONTROLLER_PAIRING_FINISHED);
|
| + break;
|
| + }
|
| + default:
|
| + NOTREACHED();
|
| + }
|
| + current_stage_ = new_stage;
|
| + context_.SetString(controller_pairing::kContextKeyPage, desired_page);
|
| + context_.SetBoolean(controller_pairing::kContextKeyControlsDisabled, false);
|
| + CommitContextChanges();
|
| +}
|
| +
|
| +void ControllerPairingScreen::DiscoveredDevicesListChanged() {
|
| + if (!ExpectStageIs(Stage::STAGE_DEVICES_DISCOVERY))
|
| + return;
|
| + ControllerPairingFlow::DeviceIdList devices = flow_->GetDiscoveredDevices();
|
| + std::sort(devices.begin(), devices.end());
|
| + std::string list = JoinString(devices, '\0');
|
| + context_.SetString(controller_pairing::kContextKeyDevices, list);
|
| + context_.SetString(controller_pairing::kContextKeyPage,
|
| + devices.empty() ? controller_pairing::kPageDevicesDiscovery
|
| + : controller_pairing::kPageDeviceSelect);
|
| + if (devices.empty()) {
|
| + device_preselected_ = false;
|
| + } else if (!device_preselected_) {
|
| + context_.SetString(controller_pairing::kContextKeySelectedDevice,
|
| + devices.front());
|
| + device_preselected_ = true;
|
| + }
|
| + CommitContextChanges();
|
| +}
|
| +
|
| +void ControllerPairingScreen::OnActorDestroyed(
|
| + ControllerPairingScreenActor* actor) {
|
| + if (actor_ == actor)
|
| + actor_ = NULL;
|
| +}
|
| +
|
| +// Overridden from ControllerPairingView::Delegate:
|
| +void ControllerPairingScreen::OnButtonClicked(const std::string& action) {
|
| + using namespace controller_pairing;
|
| +
|
| + bool disable_controls = true;
|
| + if (action == kActionChooseDevice) {
|
| + flow_->ChooseDeviceForPairing(
|
| + context_.GetString(kContextKeySelectedDevice));
|
| + } else if (action == kActionRepeatDiscovery) {
|
| + flow_->RepeatDiscovery();
|
| + } else if (action == kActionAcceptCode) {
|
| + flow_->SetConfirmationCodeIsCorrect(true);
|
| + } else if (action == kActionRejectCode) {
|
| + flow_->SetConfirmationCodeIsCorrect(false);
|
| + } else if (action == kActionProceedToAuthentication) {
|
| + context_.SetString(kContextKeyPage, kPageAuthentication);
|
| + disable_controls = false;
|
| + } else if (action == kActionEnroll) {
|
| + UserContext user_context(context_.GetString(kContextKeyAccountId));
|
| + flow_->OnAuthenticationDone(user_context, actor_->GetBrowserContext());
|
| + } else if (action == kActionStartSession) {
|
| + flow_->StartSession();
|
| + }
|
| + context_.SetBoolean(kContextKeyControlsDisabled, disable_controls);
|
| + CommitContextChanges();
|
| +}
|
| +
|
| +void ControllerPairingScreen::OnScreenContextChanged(
|
| + const base::DictionaryValue& diff) {
|
| + context_.ApplyChanges(diff, NULL);
|
| +}
|
| +
|
| +} // namespace chromeos
|
|
|