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/enrollment/auto_enrollment_check_step.h" | 5 #include "chrome/browser/chromeos/login/enrollment/auto_enrollment_check_screen. h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "chrome/browser/chromeos/login/screens/screen_observer.h" | 11 #include "chrome/browser/chromeos/login/screens/screen_observer.h" |
12 #include "chrome/browser/chromeos/login/wizard_controller.h" | |
12 #include "chromeos/chromeos_switches.h" | 13 #include "chromeos/chromeos_switches.h" |
13 #include "chromeos/network/network_state.h" | 14 #include "chromeos/network/network_state.h" |
14 #include "chromeos/network/network_state_handler.h" | 15 #include "chromeos/network/network_state_handler.h" |
15 | 16 |
16 namespace chromeos { | 17 namespace chromeos { |
17 | 18 |
18 AutoEnrollmentCheckStep::AutoEnrollmentCheckStep( | 19 AutoEnrollmentCheckScreen::AutoEnrollmentCheckScreen( |
19 ScreenObserver* screen_observer, | 20 ScreenObserver* observer, |
21 AutoEnrollmentCheckScreenActor* actor, | |
20 AutoEnrollmentController* auto_enrollment_controller) | 22 AutoEnrollmentController* auto_enrollment_controller) |
21 : screen_observer_(screen_observer), | 23 : WizardScreen(observer), |
24 actor_(actor), | |
22 auto_enrollment_controller_(auto_enrollment_controller), | 25 auto_enrollment_controller_(auto_enrollment_controller), |
23 captive_portal_status_( | 26 captive_portal_status_( |
24 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN), | 27 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN), |
25 auto_enrollment_state_(policy::AUTO_ENROLLMENT_STATE_IDLE) {} | 28 auto_enrollment_state_(policy::AUTO_ENROLLMENT_STATE_IDLE) { |
29 DCHECK(actor_); | |
ygorshenin1
2014/05/20 16:54:40
Why do you need this DCHECK()? In the following co
pastarmovj
2014/05/22 13:41:44
Correct. This is an artifact from the code I copie
| |
30 if (actor_) | |
31 actor_->SetDelegate(this); | |
32 } | |
26 | 33 |
27 AutoEnrollmentCheckStep::~AutoEnrollmentCheckStep() { | 34 AutoEnrollmentCheckScreen::~AutoEnrollmentCheckScreen() { |
28 NetworkPortalDetector::Get()->RemoveObserver(this); | 35 NetworkPortalDetector::Get()->RemoveObserver(this); |
29 } | 36 } |
30 | 37 |
31 void AutoEnrollmentCheckStep::Start() { | 38 void AutoEnrollmentCheckScreen::Start() { |
32 if (AutoEnrollmentController::GetMode() != | 39 if (!IsStartNeeded()) |
33 AutoEnrollmentController::MODE_FORCED_RE_ENROLLMENT) { | |
34 SignalCompletion(); | |
35 return; | 40 return; |
36 } | |
37 | 41 |
38 // Make sure the auto-enrollment client is running. | 42 // Make sure the auto-enrollment client is running. |
39 auto_enrollment_controller_->Start(); | 43 auto_enrollment_controller_->Start(); |
40 | 44 |
41 auto_enrollment_progress_subscription_ = | 45 auto_enrollment_progress_subscription_ = |
42 auto_enrollment_controller_->RegisterProgressCallback( | 46 auto_enrollment_controller_->RegisterProgressCallback( |
43 base::Bind(&AutoEnrollmentCheckStep::OnAutoEnrollmentCheckProgressed, | 47 base::Bind( |
44 base::Unretained(this))); | 48 &AutoEnrollmentCheckScreen::OnAutoEnrollmentCheckProgressed, |
49 base::Unretained(this))); | |
45 auto_enrollment_state_ = auto_enrollment_controller_->state(); | 50 auto_enrollment_state_ = auto_enrollment_controller_->state(); |
46 | 51 |
47 // NB: AddAndFireObserver below call back into OnPortalDetectionCompleted. | 52 // NB: AddAndFireObserver below call back into OnPortalDetectionCompleted. |
48 // This guarantees that the UI gets synced to current state. | 53 // This guarantees that the UI gets synced to current state. |
49 NetworkPortalDetector* portal_detector = NetworkPortalDetector::Get(); | 54 NetworkPortalDetector* portal_detector = NetworkPortalDetector::Get(); |
50 portal_detector->StartDetectionIfIdle(); | 55 portal_detector->StartDetectionIfIdle(); |
51 portal_detector->AddAndFireObserver(this); | 56 portal_detector->AddAndFireObserver(this); |
52 } | 57 } |
53 | 58 |
54 void AutoEnrollmentCheckStep::OnPortalDetectionCompleted( | 59 bool AutoEnrollmentCheckScreen::IsStartNeeded() { |
60 // Check that forced reenrollment is wanted and if the check is needed or we | |
61 // already know the outcome. | |
62 if (AutoEnrollmentController::GetMode() != | |
63 AutoEnrollmentController::MODE_FORCED_RE_ENROLLMENT || | |
64 auto_enrollment_state_ == | |
65 policy::AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT || | |
66 auto_enrollment_state_ == policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT) { | |
67 SignalCompletion(); | |
68 return false; | |
69 } | |
70 return true; | |
71 } | |
72 | |
73 void AutoEnrollmentCheckScreen::PrepareToShow() { | |
74 } | |
75 | |
76 void AutoEnrollmentCheckScreen::Show() { | |
77 if (IsStartNeeded()) { | |
78 Start(); | |
79 if (actor_) | |
80 actor_->Show(); | |
81 } | |
82 } | |
83 | |
84 void AutoEnrollmentCheckScreen::Hide() { | |
85 } | |
86 | |
87 std::string AutoEnrollmentCheckScreen::GetName() const { | |
88 return WizardController::kAutoEnrollmentCheckScreenName; | |
89 } | |
90 | |
91 void AutoEnrollmentCheckScreen::OnExit() { | |
92 get_screen_observer()->OnExit( | |
93 ScreenObserver::ENTERPRISE_AUTO_ENROLLMENT_CHECK_COMPLETED); | |
94 } | |
95 | |
96 void AutoEnrollmentCheckScreen::OnActorDestroyed( | |
97 AutoEnrollmentCheckScreenActor* actor) { | |
98 if (actor_ == actor) | |
99 actor_ = NULL; | |
100 } | |
101 | |
102 void AutoEnrollmentCheckScreen::OnPortalDetectionCompleted( | |
55 const NetworkState* /* network */, | 103 const NetworkState* /* network */, |
56 const NetworkPortalDetector::CaptivePortalState& state) { | 104 const NetworkPortalDetector::CaptivePortalState& state) { |
57 UpdateState(state.status, auto_enrollment_state_); | 105 UpdateState(state.status, auto_enrollment_state_); |
58 } | 106 } |
59 | 107 |
60 void AutoEnrollmentCheckStep::OnAutoEnrollmentCheckProgressed( | 108 void AutoEnrollmentCheckScreen::OnAutoEnrollmentCheckProgressed( |
61 policy::AutoEnrollmentState state) { | 109 policy::AutoEnrollmentState state) { |
62 UpdateState(captive_portal_status_, state); | 110 UpdateState(captive_portal_status_, state); |
63 } | 111 } |
64 | 112 |
65 void AutoEnrollmentCheckStep::UpdateState( | 113 void AutoEnrollmentCheckScreen::UpdateState( |
66 NetworkPortalDetector::CaptivePortalStatus new_captive_portal_status, | 114 NetworkPortalDetector::CaptivePortalStatus new_captive_portal_status, |
67 policy::AutoEnrollmentState new_auto_enrollment_state) { | 115 policy::AutoEnrollmentState new_auto_enrollment_state) { |
68 // Configure the error screen to show the approriate error message. | 116 // Configure the error screen to show the approriate error message. |
69 if (!UpdateCaptivePortalStatus(new_captive_portal_status)) | 117 if (!UpdateCaptivePortalStatus(new_captive_portal_status)) |
70 UpdateAutoEnrollmentState(new_auto_enrollment_state); | 118 UpdateAutoEnrollmentState(new_auto_enrollment_state); |
71 | 119 |
72 // Update the connecting indicator. | 120 // Update the connecting indicator. |
73 ErrorScreen* error_screen = screen_observer_->GetErrorScreen(); | 121 ErrorScreen* error_screen = get_screen_observer()->GetErrorScreen(); |
74 error_screen->ShowConnectingIndicator( | 122 error_screen->ShowConnectingIndicator( |
75 new_auto_enrollment_state == policy::AUTO_ENROLLMENT_STATE_PENDING); | 123 new_auto_enrollment_state == policy::AUTO_ENROLLMENT_STATE_PENDING); |
76 | 124 |
77 // Determine whether a retry is in order. | 125 // Determine whether a retry is in order. |
78 bool retry = (new_captive_portal_status == | 126 bool retry = (new_captive_portal_status == |
79 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE) && | 127 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE) && |
80 (captive_portal_status_ != | 128 (captive_portal_status_ != |
81 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE); | 129 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE); |
82 | 130 |
83 // Save the new state. | 131 // Save the new state. |
(...skipping 16 matching lines...) Expand all Loading... | |
100 SignalCompletion(); | 148 SignalCompletion(); |
101 return; | 149 return; |
102 } | 150 } |
103 | 151 |
104 // Retry if applicable. This is last so eventual callbacks find consistent | 152 // Retry if applicable. This is last so eventual callbacks find consistent |
105 // state. | 153 // state. |
106 if (retry) | 154 if (retry) |
107 auto_enrollment_controller_->Retry(); | 155 auto_enrollment_controller_->Retry(); |
108 } | 156 } |
109 | 157 |
110 bool AutoEnrollmentCheckStep::UpdateCaptivePortalStatus( | 158 bool AutoEnrollmentCheckScreen::UpdateCaptivePortalStatus( |
111 NetworkPortalDetector::CaptivePortalStatus new_captive_portal_status) { | 159 NetworkPortalDetector::CaptivePortalStatus new_captive_portal_status) { |
112 switch (new_captive_portal_status) { | 160 switch (new_captive_portal_status) { |
113 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN: | 161 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN: |
114 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE: | 162 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE: |
115 return false; | 163 return false; |
116 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE: | 164 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE: |
117 ShowErrorScreen(ErrorScreen::ERROR_STATE_OFFLINE); | 165 ShowErrorScreen(ErrorScreen::ERROR_STATE_OFFLINE); |
118 return true; | 166 return true; |
119 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL: | 167 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL: |
120 ShowErrorScreen(ErrorScreen::ERROR_STATE_PORTAL); | 168 ShowErrorScreen(ErrorScreen::ERROR_STATE_PORTAL); |
121 if (captive_portal_status_ != new_captive_portal_status) | 169 if (captive_portal_status_ != new_captive_portal_status) |
122 screen_observer_->GetErrorScreen()->FixCaptivePortal(); | 170 get_screen_observer()->GetErrorScreen()->FixCaptivePortal(); |
123 return true; | 171 return true; |
124 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED: | 172 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED: |
125 ShowErrorScreen(ErrorScreen::ERROR_STATE_PROXY); | 173 ShowErrorScreen(ErrorScreen::ERROR_STATE_PROXY); |
126 return true; | 174 return true; |
127 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT: | 175 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT: |
128 // Trigger NOTREACHED() below. | 176 // Trigger NOTREACHED() below. |
129 break; | 177 break; |
130 } | 178 } |
131 | 179 |
132 NOTREACHED() << "Bad status " << new_captive_portal_status; | 180 NOTREACHED() << "Bad status " << new_captive_portal_status; |
133 return false; | 181 return false; |
134 } | 182 } |
135 | 183 |
136 bool AutoEnrollmentCheckStep::UpdateAutoEnrollmentState( | 184 bool AutoEnrollmentCheckScreen::UpdateAutoEnrollmentState( |
137 policy::AutoEnrollmentState new_auto_enrollment_state) { | 185 policy::AutoEnrollmentState new_auto_enrollment_state) { |
138 switch (new_auto_enrollment_state) { | 186 switch (new_auto_enrollment_state) { |
139 case policy::AUTO_ENROLLMENT_STATE_IDLE: | 187 case policy::AUTO_ENROLLMENT_STATE_IDLE: |
140 // The client should have been started already. | 188 // The client should have been started already. |
141 NOTREACHED(); | 189 NOTREACHED(); |
142 return false; | 190 return false; |
143 case policy::AUTO_ENROLLMENT_STATE_PENDING: | 191 case policy::AUTO_ENROLLMENT_STATE_PENDING: |
144 case policy::AUTO_ENROLLMENT_STATE_SERVER_ERROR: | 192 case policy::AUTO_ENROLLMENT_STATE_SERVER_ERROR: |
145 case policy::AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT: | 193 case policy::AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT: |
146 case policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT: | 194 case policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT: |
147 return false; | 195 return false; |
148 case policy::AUTO_ENROLLMENT_STATE_CONNECTION_ERROR: | 196 case policy::AUTO_ENROLLMENT_STATE_CONNECTION_ERROR: |
149 ShowErrorScreen(ErrorScreen::ERROR_STATE_OFFLINE); | 197 ShowErrorScreen(ErrorScreen::ERROR_STATE_OFFLINE); |
150 return true; | 198 return true; |
151 } | 199 } |
152 | 200 |
153 NOTREACHED() << "bad state " << new_auto_enrollment_state; | 201 NOTREACHED() << "bad state " << new_auto_enrollment_state; |
154 return false; | 202 return false; |
155 } | 203 } |
156 | 204 |
157 void AutoEnrollmentCheckStep::ShowErrorScreen( | 205 void AutoEnrollmentCheckScreen::ShowErrorScreen( |
158 ErrorScreen::ErrorState error_state) { | 206 ErrorScreen::ErrorState error_state) { |
159 const NetworkState* network = | 207 const NetworkState* network = |
160 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); | 208 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); |
161 ErrorScreen* error_screen = screen_observer_->GetErrorScreen(); | 209 ErrorScreen* error_screen = get_screen_observer()->GetErrorScreen(); |
162 error_screen->SetUIState(ErrorScreen::UI_STATE_AUTO_ENROLLMENT_ERROR); | 210 error_screen->SetUIState(ErrorScreen::UI_STATE_AUTO_ENROLLMENT_ERROR); |
163 error_screen->AllowGuestSignin(true); | 211 error_screen->AllowGuestSignin(true); |
164 error_screen->SetErrorState(error_state, | 212 error_screen->SetErrorState(error_state, |
165 network ? network->name() : std::string()); | 213 network ? network->name() : std::string()); |
166 screen_observer_->ShowErrorScreen(); | 214 get_screen_observer()->ShowErrorScreen(); |
167 } | 215 } |
168 | 216 |
169 void AutoEnrollmentCheckStep::SignalCompletion() { | 217 void AutoEnrollmentCheckScreen::SignalCompletion() { |
170 NetworkPortalDetector::Get()->RemoveObserver(this); | 218 NetworkPortalDetector::Get()->RemoveObserver(this); |
171 auto_enrollment_progress_subscription_.reset(); | 219 auto_enrollment_progress_subscription_.reset(); |
172 screen_observer_->OnExit( | 220 get_screen_observer()->OnExit( |
173 ScreenObserver::ENTERPRISE_AUTO_ENROLLMENT_CHECK_COMPLETED); | 221 ScreenObserver::ENTERPRISE_AUTO_ENROLLMENT_CHECK_COMPLETED); |
174 } | 222 } |
175 | 223 |
176 } // namespace chromeos | 224 } // namespace chromeos |
OLD | NEW |