Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(643)

Side by Side Diff: chrome/browser/chromeos/login/enrollment/auto_enrollment_check_screen.cc

Issue 289133002: Add a enterprise enrollment check screen to OOBE in ChromeOS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adjusted tests and replaced webkit-box with flex. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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,
20 AutoEnrollmentController* auto_enrollment_controller) 21 AutoEnrollmentCheckScreenActor* actor)
21 : screen_observer_(screen_observer), 22 : WizardScreen(observer),
22 auto_enrollment_controller_(auto_enrollment_controller), 23 actor_(actor),
23 captive_portal_status_( 24 captive_portal_status_(
24 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN), 25 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN),
25 auto_enrollment_state_(policy::AUTO_ENROLLMENT_STATE_IDLE) {} 26 auto_enrollment_state_(policy::AUTO_ENROLLMENT_STATE_IDLE) {
27 if (actor_)
28 actor_->SetDelegate(this);
29 }
26 30
27 AutoEnrollmentCheckStep::~AutoEnrollmentCheckStep() { 31 AutoEnrollmentCheckScreen::~AutoEnrollmentCheckScreen() {
28 NetworkPortalDetector::Get()->RemoveObserver(this); 32 NetworkPortalDetector::Get()->RemoveObserver(this);
29 } 33 }
30 34
31 void AutoEnrollmentCheckStep::Start() { 35 void AutoEnrollmentCheckScreen::Start() {
32 if (AutoEnrollmentController::GetMode() != 36 if (!IsStartNeeded())
33 AutoEnrollmentController::MODE_FORCED_RE_ENROLLMENT) {
34 SignalCompletion();
35 return; 37 return;
36 }
37 38
38 // Make sure the auto-enrollment client is running. 39 // Make sure the auto-enrollment client is running.
39 auto_enrollment_controller_->Start(); 40 auto_enrollment_controller_->Start();
40 41
41 auto_enrollment_progress_subscription_ = 42 auto_enrollment_progress_subscription_ =
42 auto_enrollment_controller_->RegisterProgressCallback( 43 auto_enrollment_controller_->RegisterProgressCallback(
43 base::Bind(&AutoEnrollmentCheckStep::OnAutoEnrollmentCheckProgressed, 44 base::Bind(
44 base::Unretained(this))); 45 &AutoEnrollmentCheckScreen::OnAutoEnrollmentCheckProgressed,
46 base::Unretained(this)));
45 auto_enrollment_state_ = auto_enrollment_controller_->state(); 47 auto_enrollment_state_ = auto_enrollment_controller_->state();
46 48
47 // NB: AddAndFireObserver below call back into OnPortalDetectionCompleted. 49 // NB: AddAndFireObserver below call back into OnPortalDetectionCompleted.
48 // This guarantees that the UI gets synced to current state. 50 // This guarantees that the UI gets synced to current state.
49 NetworkPortalDetector* portal_detector = NetworkPortalDetector::Get(); 51 NetworkPortalDetector* portal_detector = NetworkPortalDetector::Get();
50 portal_detector->StartDetectionIfIdle(); 52 portal_detector->StartDetectionIfIdle();
51 portal_detector->AddAndFireObserver(this); 53 portal_detector->AddAndFireObserver(this);
52 } 54 }
53 55
54 void AutoEnrollmentCheckStep::OnPortalDetectionCompleted( 56 bool AutoEnrollmentCheckScreen::IsStartNeeded() {
57 // Check that forced reenrollment is wanted and if the check is needed or we
58 // already know the outcome.
59 if (AutoEnrollmentController::GetMode() !=
60 AutoEnrollmentController::MODE_FORCED_RE_ENROLLMENT ||
61 auto_enrollment_state_ ==
62 policy::AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT ||
63 auto_enrollment_state_ == policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT) {
64 SignalCompletion();
65 return false;
66 }
67 return true;
68 }
69
70 void AutoEnrollmentCheckScreen::PrepareToShow() {
71 }
72
73 void AutoEnrollmentCheckScreen::Show() {
74 if (IsStartNeeded()) {
75 Start();
76 if (actor_)
77 actor_->Show();
78 }
79 }
80
81 void AutoEnrollmentCheckScreen::Hide() {
82 }
83
84 std::string AutoEnrollmentCheckScreen::GetName() const {
85 return WizardController::kAutoEnrollmentCheckScreenName;
86 }
87
88 void AutoEnrollmentCheckScreen::OnExit() {
89 get_screen_observer()->OnExit(
90 ScreenObserver::ENTERPRISE_AUTO_ENROLLMENT_CHECK_COMPLETED);
91 }
92
93 void AutoEnrollmentCheckScreen::OnActorDestroyed(
94 AutoEnrollmentCheckScreenActor* actor) {
95 if (actor_ == actor)
96 actor_ = NULL;
97 }
98
99 void AutoEnrollmentCheckScreen::OnPortalDetectionCompleted(
55 const NetworkState* /* network */, 100 const NetworkState* /* network */,
56 const NetworkPortalDetector::CaptivePortalState& state) { 101 const NetworkPortalDetector::CaptivePortalState& state) {
57 UpdateState(state.status, auto_enrollment_state_); 102 UpdateState(state.status, auto_enrollment_state_);
58 } 103 }
59 104
60 void AutoEnrollmentCheckStep::OnAutoEnrollmentCheckProgressed( 105 void AutoEnrollmentCheckScreen::OnAutoEnrollmentCheckProgressed(
61 policy::AutoEnrollmentState state) { 106 policy::AutoEnrollmentState state) {
62 UpdateState(captive_portal_status_, state); 107 UpdateState(captive_portal_status_, state);
63 } 108 }
64 109
65 void AutoEnrollmentCheckStep::UpdateState( 110 void AutoEnrollmentCheckScreen::UpdateState(
66 NetworkPortalDetector::CaptivePortalStatus new_captive_portal_status, 111 NetworkPortalDetector::CaptivePortalStatus new_captive_portal_status,
67 policy::AutoEnrollmentState new_auto_enrollment_state) { 112 policy::AutoEnrollmentState new_auto_enrollment_state) {
68 // Configure the error screen to show the approriate error message. 113 // Configure the error screen to show the approriate error message.
69 if (!UpdateCaptivePortalStatus(new_captive_portal_status)) 114 if (!UpdateCaptivePortalStatus(new_captive_portal_status))
70 UpdateAutoEnrollmentState(new_auto_enrollment_state); 115 UpdateAutoEnrollmentState(new_auto_enrollment_state);
71 116
72 // Update the connecting indicator. 117 // Update the connecting indicator.
73 ErrorScreen* error_screen = screen_observer_->GetErrorScreen(); 118 ErrorScreen* error_screen = get_screen_observer()->GetErrorScreen();
74 error_screen->ShowConnectingIndicator( 119 error_screen->ShowConnectingIndicator(
75 new_auto_enrollment_state == policy::AUTO_ENROLLMENT_STATE_PENDING); 120 new_auto_enrollment_state == policy::AUTO_ENROLLMENT_STATE_PENDING);
76 121
77 // Determine whether a retry is in order. 122 // Determine whether a retry is in order.
78 bool retry = (new_captive_portal_status == 123 bool retry = (new_captive_portal_status ==
79 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE) && 124 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE) &&
80 (captive_portal_status_ != 125 (captive_portal_status_ !=
81 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE); 126 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE);
82 127
83 // Save the new state. 128 // Save the new state.
(...skipping 16 matching lines...) Expand all
100 SignalCompletion(); 145 SignalCompletion();
101 return; 146 return;
102 } 147 }
103 148
104 // Retry if applicable. This is last so eventual callbacks find consistent 149 // Retry if applicable. This is last so eventual callbacks find consistent
105 // state. 150 // state.
106 if (retry) 151 if (retry)
107 auto_enrollment_controller_->Retry(); 152 auto_enrollment_controller_->Retry();
108 } 153 }
109 154
110 bool AutoEnrollmentCheckStep::UpdateCaptivePortalStatus( 155 bool AutoEnrollmentCheckScreen::UpdateCaptivePortalStatus(
111 NetworkPortalDetector::CaptivePortalStatus new_captive_portal_status) { 156 NetworkPortalDetector::CaptivePortalStatus new_captive_portal_status) {
112 switch (new_captive_portal_status) { 157 switch (new_captive_portal_status) {
113 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN: 158 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN:
114 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE: 159 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE:
115 return false; 160 return false;
116 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE: 161 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE:
117 ShowErrorScreen(ErrorScreen::ERROR_STATE_OFFLINE); 162 ShowErrorScreen(ErrorScreen::ERROR_STATE_OFFLINE);
118 return true; 163 return true;
119 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL: 164 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL:
120 ShowErrorScreen(ErrorScreen::ERROR_STATE_PORTAL); 165 ShowErrorScreen(ErrorScreen::ERROR_STATE_PORTAL);
121 if (captive_portal_status_ != new_captive_portal_status) 166 if (captive_portal_status_ != new_captive_portal_status)
122 screen_observer_->GetErrorScreen()->FixCaptivePortal(); 167 get_screen_observer()->GetErrorScreen()->FixCaptivePortal();
123 return true; 168 return true;
124 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED: 169 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED:
125 ShowErrorScreen(ErrorScreen::ERROR_STATE_PROXY); 170 ShowErrorScreen(ErrorScreen::ERROR_STATE_PROXY);
126 return true; 171 return true;
127 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT: 172 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_COUNT:
128 // Trigger NOTREACHED() below. 173 // Trigger NOTREACHED() below.
129 break; 174 break;
130 } 175 }
131 176
132 NOTREACHED() << "Bad status " << new_captive_portal_status; 177 NOTREACHED() << "Bad status " << new_captive_portal_status;
133 return false; 178 return false;
134 } 179 }
135 180
136 bool AutoEnrollmentCheckStep::UpdateAutoEnrollmentState( 181 bool AutoEnrollmentCheckScreen::UpdateAutoEnrollmentState(
137 policy::AutoEnrollmentState new_auto_enrollment_state) { 182 policy::AutoEnrollmentState new_auto_enrollment_state) {
138 switch (new_auto_enrollment_state) { 183 switch (new_auto_enrollment_state) {
139 case policy::AUTO_ENROLLMENT_STATE_IDLE: 184 case policy::AUTO_ENROLLMENT_STATE_IDLE:
140 // The client should have been started already. 185 // The client should have been started already.
141 NOTREACHED(); 186 NOTREACHED();
142 return false; 187 return false;
143 case policy::AUTO_ENROLLMENT_STATE_PENDING: 188 case policy::AUTO_ENROLLMENT_STATE_PENDING:
144 case policy::AUTO_ENROLLMENT_STATE_SERVER_ERROR: 189 case policy::AUTO_ENROLLMENT_STATE_SERVER_ERROR:
145 case policy::AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT: 190 case policy::AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT:
146 case policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT: 191 case policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT:
147 return false; 192 return false;
148 case policy::AUTO_ENROLLMENT_STATE_CONNECTION_ERROR: 193 case policy::AUTO_ENROLLMENT_STATE_CONNECTION_ERROR:
149 ShowErrorScreen(ErrorScreen::ERROR_STATE_OFFLINE); 194 ShowErrorScreen(ErrorScreen::ERROR_STATE_OFFLINE);
150 return true; 195 return true;
151 } 196 }
152 197
153 NOTREACHED() << "bad state " << new_auto_enrollment_state; 198 NOTREACHED() << "bad state " << new_auto_enrollment_state;
154 return false; 199 return false;
155 } 200 }
156 201
157 void AutoEnrollmentCheckStep::ShowErrorScreen( 202 void AutoEnrollmentCheckScreen::ShowErrorScreen(
158 ErrorScreen::ErrorState error_state) { 203 ErrorScreen::ErrorState error_state) {
159 const NetworkState* network = 204 const NetworkState* network =
160 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); 205 NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
161 ErrorScreen* error_screen = screen_observer_->GetErrorScreen(); 206 ErrorScreen* error_screen = get_screen_observer()->GetErrorScreen();
162 error_screen->SetUIState(ErrorScreen::UI_STATE_AUTO_ENROLLMENT_ERROR); 207 error_screen->SetUIState(ErrorScreen::UI_STATE_AUTO_ENROLLMENT_ERROR);
163 error_screen->AllowGuestSignin(true); 208 error_screen->AllowGuestSignin(true);
164 error_screen->SetErrorState(error_state, 209 error_screen->SetErrorState(error_state,
165 network ? network->name() : std::string()); 210 network ? network->name() : std::string());
166 screen_observer_->ShowErrorScreen(); 211 get_screen_observer()->ShowErrorScreen();
167 } 212 }
168 213
169 void AutoEnrollmentCheckStep::SignalCompletion() { 214 void AutoEnrollmentCheckScreen::SignalCompletion() {
170 NetworkPortalDetector::Get()->RemoveObserver(this); 215 NetworkPortalDetector::Get()->RemoveObserver(this);
171 auto_enrollment_progress_subscription_.reset(); 216 auto_enrollment_progress_subscription_.reset();
172 screen_observer_->OnExit( 217 get_screen_observer()->OnExit(
173 ScreenObserver::ENTERPRISE_AUTO_ENROLLMENT_CHECK_COMPLETED); 218 ScreenObserver::ENTERPRISE_AUTO_ENROLLMENT_CHECK_COMPLETED);
174 } 219 }
175 220
176 } // namespace chromeos 221 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698