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