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/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/chromeos/login/wizard_controller.h" | 9 #include "chrome/browser/chromeos/login/wizard_controller.h" |
10 #include "google_apis/gaia/gaia_auth_util.h" | 10 #include "google_apis/gaia/gaia_auth_util.h" |
11 | 11 |
12 using namespace chromeos::controller_pairing; | 12 using namespace chromeos::controller_pairing; |
13 using namespace pairing_chromeos; | 13 using namespace pairing_chromeos; |
14 | 14 |
15 namespace { | |
16 const char* kTestAuthToken = "TestAuthToken"; | |
17 }; | |
18 | |
19 namespace chromeos { | 15 namespace chromeos { |
20 | 16 |
21 ControllerPairingScreen::ControllerPairingScreen( | 17 ControllerPairingScreen::ControllerPairingScreen( |
22 ScreenObserver* observer, | 18 ScreenObserver* observer, |
23 ControllerPairingScreenActor* actor, | 19 ControllerPairingScreenActor* actor, |
24 ControllerPairingController* controller) | 20 ControllerPairingController* controller) |
25 : WizardScreen(observer), | 21 : WizardScreen(observer), |
26 actor_(actor), | 22 actor_(actor), |
27 controller_(controller), | 23 controller_(controller), |
24 observing_controller_(true), | |
28 current_stage_(ControllerPairingController::STAGE_NONE), | 25 current_stage_(ControllerPairingController::STAGE_NONE), |
29 device_preselected_(false) { | 26 device_preselected_(false) { |
30 actor_->SetDelegate(this); | 27 actor_->SetDelegate(this); |
31 controller_->AddObserver(this); | 28 controller_->AddObserver(this); |
32 } | 29 } |
33 | 30 |
34 ControllerPairingScreen::~ControllerPairingScreen() { | 31 ControllerPairingScreen::~ControllerPairingScreen() { |
35 if (actor_) | 32 if (actor_) |
36 actor_->SetDelegate(NULL); | 33 actor_->SetDelegate(NULL); |
37 controller_->RemoveObserver(this); | 34 if (observing_controller_) |
35 controller_->RemoveObserver(this); | |
dzhioev (left Google)
2014/09/09 02:46:51
nit: it is safe to try to remove observer, that is
Zachary Kuznia
2014/09/09 23:53:58
Done.
| |
38 } | 36 } |
39 | 37 |
40 void ControllerPairingScreen::CommitContextChanges() { | 38 void ControllerPairingScreen::CommitContextChanges() { |
41 if (!context_.HasChanges()) | 39 if (!context_.HasChanges()) |
42 return; | 40 return; |
43 base::DictionaryValue diff; | 41 base::DictionaryValue diff; |
44 context_.GetChangesAndReset(&diff); | 42 context_.GetChangesAndReset(&diff); |
45 if (actor_) | 43 if (actor_) |
46 actor_->OnContextChanged(diff); | 44 actor_->OnContextChanged(diff); |
47 } | 45 } |
(...skipping 20 matching lines...) Expand all Loading... | |
68 actor_->Hide(); | 66 actor_->Hide(); |
69 } | 67 } |
70 | 68 |
71 std::string ControllerPairingScreen::GetName() const { | 69 std::string ControllerPairingScreen::GetName() const { |
72 return WizardController::kControllerPairingScreenName; | 70 return WizardController::kControllerPairingScreenName; |
73 } | 71 } |
74 | 72 |
75 // Overridden from ControllerPairingController::Observer: | 73 // Overridden from ControllerPairingController::Observer: |
76 void ControllerPairingScreen::PairingStageChanged(Stage new_stage) { | 74 void ControllerPairingScreen::PairingStageChanged(Stage new_stage) { |
77 DCHECK(new_stage != current_stage_); | 75 DCHECK(new_stage != current_stage_); |
76 DCHECK(observing_controller_); | |
78 | 77 |
79 std::string desired_page; | 78 std::string desired_page; |
80 switch (new_stage) { | 79 switch (new_stage) { |
81 case ControllerPairingController::STAGE_DEVICES_DISCOVERY: { | 80 case ControllerPairingController::STAGE_DEVICES_DISCOVERY: { |
82 desired_page = kPageDevicesDiscovery; | 81 desired_page = kPageDevicesDiscovery; |
83 context_.SetStringList(kContextKeyDevices, StringList()); | 82 context_.SetStringList(kContextKeyDevices, StringList()); |
84 context_.SetString(kContextKeySelectedDevice, std::string()); | 83 context_.SetString(kContextKeySelectedDevice, std::string()); |
85 device_preselected_ = false; | 84 device_preselected_ = false; |
86 break; | 85 break; |
87 } | 86 } |
(...skipping 17 matching lines...) Expand all Loading... | |
105 } | 104 } |
106 case ControllerPairingController::STAGE_HOST_UPDATE_IN_PROGRESS: { | 105 case ControllerPairingController::STAGE_HOST_UPDATE_IN_PROGRESS: { |
107 desired_page = kPageHostUpdate; | 106 desired_page = kPageHostUpdate; |
108 break; | 107 break; |
109 } | 108 } |
110 case ControllerPairingController::STAGE_HOST_CONNECTION_LOST: { | 109 case ControllerPairingController::STAGE_HOST_CONNECTION_LOST: { |
111 desired_page = kPageHostConnectionLost; | 110 desired_page = kPageHostConnectionLost; |
112 break; | 111 break; |
113 } | 112 } |
114 case ControllerPairingController::STAGE_WAITING_FOR_CREDENTIALS: { | 113 case ControllerPairingController::STAGE_WAITING_FOR_CREDENTIALS: { |
114 observing_controller_ = false; | |
115 controller_->RemoveObserver(this); | |
116 get_screen_observer()->OnExit( | |
117 WizardController::CONTROLLER_PAIRING_FINISHED); | |
118 // TODO: Move the rest of the stages to the proper location. | |
115 desired_page = kPageEnrollmentIntroduction; | 119 desired_page = kPageEnrollmentIntroduction; |
116 break; | 120 break; |
117 } | 121 } |
118 case ControllerPairingController::STAGE_HOST_ENROLLMENT_IN_PROGRESS: { | 122 case ControllerPairingController::STAGE_HOST_ENROLLMENT_IN_PROGRESS: { |
119 desired_page = kPageHostEnrollment; | 123 desired_page = kPageHostEnrollment; |
120 break; | 124 break; |
121 } | 125 } |
122 case ControllerPairingController::STAGE_HOST_ENROLLMENT_ERROR: { | 126 case ControllerPairingController::STAGE_HOST_ENROLLMENT_ERROR: { |
123 desired_page = kPageHostEnrollmentError; | 127 desired_page = kPageHostEnrollmentError; |
124 break; | 128 break; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 } else if (action == kActionRejectCode) { | 197 } else if (action == kActionRejectCode) { |
194 controller_->SetConfirmationCodeIsCorrect(false); | 198 controller_->SetConfirmationCodeIsCorrect(false); |
195 } else if (action == kActionProceedToAuthentication) { | 199 } else if (action == kActionProceedToAuthentication) { |
196 context_.SetString(kContextKeyPage, kPageAuthentication); | 200 context_.SetString(kContextKeyPage, kPageAuthentication); |
197 disable_controls = false; | 201 disable_controls = false; |
198 } else if (action == kActionEnroll) { | 202 } else if (action == kActionEnroll) { |
199 const std::string account_id = | 203 const std::string account_id = |
200 gaia::SanitizeEmail(context_.GetString(kContextKeyAccountId)); | 204 gaia::SanitizeEmail(context_.GetString(kContextKeyAccountId)); |
201 const std::string domain(gaia::ExtractDomainName(account_id)); | 205 const std::string domain(gaia::ExtractDomainName(account_id)); |
202 context_.SetString(kContextKeyEnrollmentDomain, domain); | 206 context_.SetString(kContextKeyEnrollmentDomain, domain); |
203 // TODO(zork): Get proper credentials. (http://crbug.com/405744) | |
204 controller_->OnAuthenticationDone(domain, kTestAuthToken); | |
205 } else if (action == kActionStartSession) { | 207 } else if (action == kActionStartSession) { |
206 controller_->StartSession(); | 208 controller_->StartSession(); |
207 } | 209 } |
208 context_.SetBoolean(kContextKeyControlsDisabled, disable_controls); | 210 context_.SetBoolean(kContextKeyControlsDisabled, disable_controls); |
209 CommitContextChanges(); | 211 CommitContextChanges(); |
210 } | 212 } |
211 | 213 |
212 void ControllerPairingScreen::OnScreenContextChanged( | 214 void ControllerPairingScreen::OnScreenContextChanged( |
213 const base::DictionaryValue& diff) { | 215 const base::DictionaryValue& diff) { |
214 std::vector<std::string> changedKeys; | 216 std::vector<std::string> changedKeys; |
215 context_.ApplyChanges(diff, &changedKeys); | 217 context_.ApplyChanges(diff, &changedKeys); |
216 for (std::vector<std::string>::const_iterator key = changedKeys.begin(); | 218 for (std::vector<std::string>::const_iterator key = changedKeys.begin(); |
217 key != changedKeys.end(); | 219 key != changedKeys.end(); |
218 ++key) { | 220 ++key) { |
219 if (*key == kContextKeySelectedDevice) { | 221 if (*key == kContextKeySelectedDevice) { |
220 context_.SetBoolean(kContextKeyControlsDisabled, | 222 context_.SetBoolean(kContextKeyControlsDisabled, |
221 context_.GetString(*key).empty()); | 223 context_.GetString(*key).empty()); |
222 CommitContextChanges(); | 224 CommitContextChanges(); |
223 } | 225 } |
224 } | 226 } |
225 } | 227 } |
226 | 228 |
227 } // namespace chromeos | 229 } // namespace chromeos |
OLD | NEW |