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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/login/screens/host_pairing_screen.h"
7 #include "base/command_line.h"
8 #include "chrome/browser/chromeos/login/wizard_controller.h"
9 #include "components/pairing/host_pairing_controller.h"
13 using namespace host_pairing;
14 using namespace pairing_chromeos;
16 HostPairingScreen::HostPairingScreen(
17 ScreenObserver* observer,
18 HostPairingScreenActor* actor,
19 pairing_chromeos::HostPairingController* controller)
20 : WizardScreen(observer),
22 controller_(controller),
23 current_stage_(HostPairingController::STAGE_NONE) {
24 actor_->SetDelegate(this);
25 controller_->AddObserver(this);
28 HostPairingScreen::~HostPairingScreen() {
30 actor_->SetDelegate(NULL);
31 controller_->RemoveObserver(this);
34 void HostPairingScreen::CommitContextChanges() {
35 if (!context_.HasChanges())
37 base::DictionaryValue diff;
38 context_.GetChangesAndReset(&diff);
40 actor_->OnContextChanged(diff);
43 void HostPairingScreen::PrepareToShow() {
46 void HostPairingScreen::Show() {
49 PairingStageChanged(controller_->GetCurrentStage());
52 void HostPairingScreen::Hide() {
57 std::string HostPairingScreen::GetName() const {
58 return WizardController::kHostPairingScreenName;
61 void HostPairingScreen::PairingStageChanged(Stage new_stage) {
62 std::string desired_page;
64 case HostPairingController::STAGE_NONE:
65 case HostPairingController::STAGE_INITIALIZATION_ERROR: {
68 case HostPairingController::STAGE_WAITING_FOR_CONTROLLER:
69 case HostPairingController::STAGE_WAITING_FOR_CONTROLLER_AFTER_UPDATE: {
70 desired_page = kPageWelcome;
73 case HostPairingController::STAGE_WAITING_FOR_CODE_CONFIRMATION: {
74 desired_page = kPageCodeConfirmation;
75 context_.SetString(kContextKeyConfirmationCode,
76 controller_->GetConfirmationCode());
79 case HostPairingController::STAGE_UPDATING: {
80 desired_page = kPageUpdate;
81 context_.SetDouble(kContextKeyUpdateProgress, 0.0);
84 case HostPairingController::STAGE_WAITING_FOR_CREDENTIALS: {
85 desired_page = kPageEnrollmentIntroduction;
88 case HostPairingController::STAGE_ENROLLING: {
89 desired_page = kPageEnrollment;
90 context_.SetString(kContextKeyEnrollmentDomain,
91 controller_->GetEnrollmentDomain());
94 case HostPairingController::STAGE_ENROLLMENT_ERROR: {
95 desired_page = kPageEnrollmentError;
98 case HostPairingController::STAGE_PAIRING_DONE: {
99 desired_page = kPagePairingDone;
102 case HostPairingController::STAGE_FINISHED: {
103 // This page is closed in EnrollHost.
107 current_stage_ = new_stage;
108 context_.SetString(kContextKeyDeviceName, controller_->GetDeviceName());
109 context_.SetString(kContextKeyPage, desired_page);
110 CommitContextChanges();
113 void HostPairingScreen::ConfigureHost(bool accepted_eula,
114 const std::string& lang,
115 const std::string& timezone,
117 const std::string& keyboard_layout) {
118 // TODO(zork): Get configuration from UI and send to Host.
119 // (http://crbug.com/405744)
122 void HostPairingScreen::EnrollHost(const std::string& auth_token) {
123 controller_->RemoveObserver(this);
124 WizardController::default_controller()->OnEnrollmentAuthTokenReceived(
128 void HostPairingScreen::OnActorDestroyed(HostPairingScreenActor* actor) {
133 } // namespace chromeos