Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / login / screens / host_pairing_screen.cc
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.
4
5 #include "chrome/browser/chromeos/login/screens/host_pairing_screen.h"
6
7 #include "base/command_line.h"
8 #include "chrome/browser/chromeos/login/wizard_controller.h"
9 #include "components/pairing/host_pairing_controller.h"
10
11 namespace chromeos {
12
13 using namespace host_pairing;
14 using namespace pairing_chromeos;
15
16 HostPairingScreen::HostPairingScreen(
17     BaseScreenDelegate* base_screen_delegate,
18     Delegate* delegate,
19     HostPairingScreenActor* actor,
20     pairing_chromeos::HostPairingController* remora_controller)
21     : BaseScreen(base_screen_delegate),
22       delegate_(delegate),
23       actor_(actor),
24       remora_controller_(remora_controller),
25       current_stage_(HostPairingController::STAGE_NONE) {
26   actor_->SetDelegate(this);
27   remora_controller_->AddObserver(this);
28 }
29
30 HostPairingScreen::~HostPairingScreen() {
31   if (actor_)
32     actor_->SetDelegate(NULL);
33   remora_controller_->RemoveObserver(this);
34 }
35
36 void HostPairingScreen::CommitContextChanges() {
37   if (!context_.HasChanges())
38     return;
39   base::DictionaryValue diff;
40   context_.GetChangesAndReset(&diff);
41   if (actor_)
42     actor_->OnContextChanged(diff);
43 }
44
45 void HostPairingScreen::PrepareToShow() {
46 }
47
48 void HostPairingScreen::Show() {
49   if (actor_)
50     actor_->Show();
51   PairingStageChanged(remora_controller_->GetCurrentStage());
52 }
53
54 void HostPairingScreen::Hide() {
55   if (actor_)
56     actor_->Hide();
57 }
58
59 std::string HostPairingScreen::GetName() const {
60   return WizardController::kHostPairingScreenName;
61 }
62
63 void HostPairingScreen::PairingStageChanged(Stage new_stage) {
64   std::string desired_page;
65   switch (new_stage) {
66     case HostPairingController::STAGE_WAITING_FOR_CONTROLLER:
67     case HostPairingController::STAGE_WAITING_FOR_CONTROLLER_AFTER_UPDATE: {
68       desired_page = kPageWelcome;
69       break;
70     }
71     case HostPairingController::STAGE_WAITING_FOR_CODE_CONFIRMATION: {
72       desired_page = kPageCodeConfirmation;
73       context_.SetString(kContextKeyConfirmationCode,
74                          remora_controller_->GetConfirmationCode());
75       break;
76     }
77     default:
78       break;
79   }
80   current_stage_ = new_stage;
81   context_.SetString(kContextKeyDeviceName,
82                      remora_controller_->GetDeviceName());
83   context_.SetString(kContextKeyPage, desired_page);
84   CommitContextChanges();
85 }
86
87 void HostPairingScreen::ConfigureHost(bool accepted_eula,
88                                       const std::string& lang,
89                                       const std::string& timezone,
90                                       bool send_reports,
91                                       const std::string& keyboard_layout) {
92   VLOG(1) << "ConfigureHostMessage language=" << lang
93           << ", timezone=" << timezone
94           << ", keyboard_layout=" << keyboard_layout;
95
96   remora_controller_->RemoveObserver(this);
97   if (delegate_) {
98     delegate_->ConfigureHost(
99         accepted_eula, lang, timezone, send_reports, keyboard_layout);
100   }
101   get_base_screen_delegate()->OnExit(WizardController::HOST_PAIRING_FINISHED);
102 }
103
104 void HostPairingScreen::EnrollHost(const std::string& auth_token) {
105   NOTREACHED();
106 }
107
108 void HostPairingScreen::OnActorDestroyed(HostPairingScreenActor* actor) {
109   if (actor_ == actor)
110     actor_ = NULL;
111 }
112
113 }  // namespace chromeos