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 "chrome/browser/chromeos/login/screens/controller_pairing_screen.h" | 5 #include "chrome/browser/chromeos/login/screens/controller_pairing_screen.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/chromeos/login/wizard_controller.h" | 10 #include "chrome/browser/chromeos/login/wizard_controller.h" |
11 #include "google_apis/gaia/gaia_auth_util.h" | 11 #include "google_apis/gaia/gaia_auth_util.h" |
12 | 12 |
13 using namespace chromeos::controller_pairing; | 13 using namespace chromeos::controller_pairing; |
14 using namespace pairing_chromeos; | 14 using namespace pairing_chromeos; |
15 | 15 |
16 namespace chromeos { | 16 namespace chromeos { |
17 | 17 |
18 ControllerPairingScreen::ControllerPairingScreen( | 18 ControllerPairingScreen::ControllerPairingScreen( |
19 BaseScreenDelegate* base_screen_delegate, | 19 BaseScreenDelegate* base_screen_delegate, |
20 Delegate* delegate, | 20 Delegate* delegate, |
21 ControllerPairingScreenActor* actor, | 21 ControllerPairingScreenView* view, |
22 ControllerPairingController* shark_controller) | 22 ControllerPairingController* shark_controller) |
23 : BaseScreen(base_screen_delegate, | 23 : BaseScreen(base_screen_delegate, |
24 OobeScreen::SCREEN_OOBE_CONTROLLER_PAIRING), | 24 OobeScreen::SCREEN_OOBE_CONTROLLER_PAIRING), |
25 delegate_(delegate), | 25 delegate_(delegate), |
26 actor_(actor), | 26 view_(view), |
27 shark_controller_(shark_controller), | 27 shark_controller_(shark_controller), |
28 current_stage_(ControllerPairingController::STAGE_NONE), | 28 current_stage_(ControllerPairingController::STAGE_NONE), |
29 device_preselected_(false) { | 29 device_preselected_(false) { |
30 actor_->SetDelegate(this); | 30 view_->SetDelegate(this); |
31 shark_controller_->AddObserver(this); | 31 shark_controller_->AddObserver(this); |
32 } | 32 } |
33 | 33 |
34 ControllerPairingScreen::~ControllerPairingScreen() { | 34 ControllerPairingScreen::~ControllerPairingScreen() { |
35 if (actor_) | 35 if (view_) |
36 actor_->SetDelegate(NULL); | 36 view_->SetDelegate(nullptr); |
37 shark_controller_->RemoveObserver(this); | 37 shark_controller_->RemoveObserver(this); |
38 } | 38 } |
39 | 39 |
40 void ControllerPairingScreen::CommitContextChanges() { | 40 void ControllerPairingScreen::CommitContextChanges() { |
41 if (!context_.HasChanges()) | 41 if (!context_.HasChanges()) |
42 return; | 42 return; |
43 base::DictionaryValue diff; | 43 base::DictionaryValue diff; |
44 context_.GetChangesAndReset(&diff); | 44 context_.GetChangesAndReset(&diff); |
45 if (actor_) | 45 if (view_) |
46 actor_->OnContextChanged(diff); | 46 view_->OnContextChanged(diff); |
47 } | 47 } |
48 | 48 |
49 bool ControllerPairingScreen::ExpectStageIs(Stage stage) const { | 49 bool ControllerPairingScreen::ExpectStageIs(Stage stage) const { |
50 DCHECK(stage == current_stage_); | 50 DCHECK(stage == current_stage_); |
51 if (current_stage_ != stage) | 51 if (current_stage_ != stage) |
52 LOG(ERROR) << "Incorrect stage. Expected: " << stage | 52 LOG(ERROR) << "Incorrect stage. Expected: " << stage |
53 << ", current stage: " << current_stage_; | 53 << ", current stage: " << current_stage_; |
54 return stage == current_stage_; | 54 return stage == current_stage_; |
55 } | 55 } |
56 | 56 |
57 void ControllerPairingScreen::Show() { | 57 void ControllerPairingScreen::Show() { |
58 if (actor_) | 58 if (view_) |
59 actor_->Show(); | 59 view_->Show(); |
60 shark_controller_->StartPairing(); | 60 shark_controller_->StartPairing(); |
61 } | 61 } |
62 | 62 |
63 void ControllerPairingScreen::Hide() { | 63 void ControllerPairingScreen::Hide() { |
64 if (actor_) | 64 if (view_) |
65 actor_->Hide(); | 65 view_->Hide(); |
66 } | 66 } |
67 | 67 |
68 void ControllerPairingScreen::PairingStageChanged(Stage new_stage) { | 68 void ControllerPairingScreen::PairingStageChanged(Stage new_stage) { |
69 DCHECK(new_stage != current_stage_); | 69 DCHECK(new_stage != current_stage_); |
70 | 70 |
71 std::string desired_page; | 71 std::string desired_page; |
72 switch (new_stage) { | 72 switch (new_stage) { |
73 case ControllerPairingController::STAGE_DEVICES_DISCOVERY: { | 73 case ControllerPairingController::STAGE_DEVICES_DISCOVERY: { |
74 desired_page = kPageDevicesDiscovery; | 74 desired_page = kPageDevicesDiscovery; |
75 context_.SetStringList(kContextKeyDevices, ::login::StringList()); | 75 context_.SetStringList(kContextKeyDevices, ::login::StringList()); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 device_preselected_ = false; | 153 device_preselected_ = false; |
154 } else if (!device_preselected_) { | 154 } else if (!device_preselected_) { |
155 selected_device = devices.front(); | 155 selected_device = devices.front(); |
156 device_preselected_ = true; | 156 device_preselected_ = true; |
157 } | 157 } |
158 context_.SetString(kContextKeySelectedDevice, selected_device); | 158 context_.SetString(kContextKeySelectedDevice, selected_device); |
159 context_.SetBoolean(kContextKeyControlsDisabled, selected_device.empty()); | 159 context_.SetBoolean(kContextKeyControlsDisabled, selected_device.empty()); |
160 CommitContextChanges(); | 160 CommitContextChanges(); |
161 } | 161 } |
162 | 162 |
163 void ControllerPairingScreen::OnActorDestroyed( | 163 void ControllerPairingScreen::OnViewDestroyed( |
164 ControllerPairingScreenActor* actor) { | 164 ControllerPairingScreenView* view) { |
165 if (actor_ == actor) | 165 if (view_ == view) |
166 actor_ = NULL; | 166 view_ = nullptr; |
167 } | 167 } |
168 | 168 |
169 // Overridden from ControllerPairingView::Delegate: | 169 // Overridden from ControllerPairingView::Delegate: |
170 void ControllerPairingScreen::OnUserActed(const std::string& action) { | 170 void ControllerPairingScreen::OnUserActed(const std::string& action) { |
171 if (context_.GetBoolean(kContextKeyControlsDisabled)) { | 171 if (context_.GetBoolean(kContextKeyControlsDisabled)) { |
172 LOG(WARNING) << "User acted, but controls are disabled. Ignoring."; | 172 LOG(WARNING) << "User acted, but controls are disabled. Ignoring."; |
173 return; | 173 return; |
174 } | 174 } |
175 bool disable_controls = true; | 175 bool disable_controls = true; |
176 if (action == kActionChooseDevice) { | 176 if (action == kActionChooseDevice) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 ++key) { | 209 ++key) { |
210 if (*key == kContextKeySelectedDevice) { | 210 if (*key == kContextKeySelectedDevice) { |
211 context_.SetBoolean(kContextKeyControlsDisabled, | 211 context_.SetBoolean(kContextKeyControlsDisabled, |
212 context_.GetString(*key).empty()); | 212 context_.GetString(*key).empty()); |
213 CommitContextChanges(); | 213 CommitContextChanges(); |
214 } | 214 } |
215 } | 215 } |
216 } | 216 } |
217 | 217 |
218 } // namespace chromeos | 218 } // namespace chromeos |
OLD | NEW |