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