| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/reset_screen.h" | 5 #include "chrome/browser/chromeos/login/screens/reset_screen.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" | |
| 9 #include "base/prefs/pref_registry_simple.h" | |
| 10 #include "base/prefs/pref_service.h" | |
| 11 #include "base/values.h" | |
| 12 #include "chrome/browser/browser_process.h" | |
| 13 #include "chrome/browser/chromeos/login/screens/base_screen_delegate.h" | 8 #include "chrome/browser/chromeos/login/screens/base_screen_delegate.h" |
| 14 #include "chrome/browser/chromeos/login/screens/error_screen.h" | 9 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 15 #include "chrome/browser/chromeos/login/screens/reset_view.h" | |
| 16 #include "chrome/browser/chromeos/reset/metrics.h" | |
| 17 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" | |
| 18 #include "chrome/common/pref_names.h" | |
| 19 #include "chromeos/chromeos_switches.h" | |
| 20 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 21 #include "chromeos/dbus/power_manager_client.h" | |
| 22 #include "chromeos/dbus/session_manager_client.h" | |
| 23 | |
| 24 | 10 |
| 25 namespace chromeos { | 11 namespace chromeos { |
| 26 | 12 |
| 27 ResetScreen::ResetScreen(BaseScreenDelegate* base_screen_delegate, | 13 ResetScreen::ResetScreen(BaseScreenDelegate* base_screen_delegate, |
| 28 ResetView* view) | 14 ResetScreenActor* actor) |
| 29 : ResetModel(base_screen_delegate), | 15 : BaseScreen(base_screen_delegate), actor_(actor) { |
| 30 view_(view), | 16 DCHECK(actor_); |
| 31 weak_ptr_factory_(this) { | 17 if (actor_) |
| 32 DCHECK(view_); | 18 actor_->SetDelegate(this); |
| 33 if (view_) | |
| 34 view_->Bind(*this); | |
| 35 context_.SetInteger(kContextKeyScreenState, STATE_RESTART_REQUIRED); | |
| 36 context_.SetBoolean(kContextKeyIsRollbackAvailable, false); | |
| 37 context_.SetBoolean(kContextKeyIsRollbackChecked, false); | |
| 38 context_.SetBoolean(kContextKeyIsConfirmational, false); | |
| 39 context_.SetBoolean(kContextKeyIsOfficialBuild, false); | |
| 40 #if defined(OFFICIAL_BUILD) | |
| 41 context_.SetBoolean(kContextKeyIsOfficialBuild, true); | |
| 42 #endif | |
| 43 } | 19 } |
| 44 | 20 |
| 45 ResetScreen::~ResetScreen() { | 21 ResetScreen::~ResetScreen() { |
| 46 if (view_) | 22 if (actor_) |
| 47 view_->Unbind(); | 23 actor_->SetDelegate(NULL); |
| 48 DBusThreadManager::Get()->GetUpdateEngineClient()->RemoveObserver(this); | |
| 49 } | 24 } |
| 50 | 25 |
| 51 void ResetScreen::PrepareToShow() { | 26 void ResetScreen::PrepareToShow() { |
| 52 if (view_) | 27 if (actor_) |
| 53 view_->PrepareToShow(); | 28 actor_->PrepareToShow(); |
| 54 } | 29 } |
| 55 | 30 |
| 56 void ResetScreen::Show() { | 31 void ResetScreen::Show() { |
| 57 if (view_) | 32 if (actor_) |
| 58 view_->Show(); | 33 actor_->Show(); |
| 59 | |
| 60 int dialog_type = -1; // used by UMA metrics. | |
| 61 | |
| 62 ContextEditor context_editor = GetContextEditor(); | |
| 63 | |
| 64 bool restart_required = !base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 65 switches::kFirstExecAfterBoot); | |
| 66 if (restart_required) { | |
| 67 context_editor.SetInteger(kContextKeyScreenState, STATE_RESTART_REQUIRED); | |
| 68 dialog_type = reset::DIALOG_SHORTCUT_RESTART_REQUIRED; | |
| 69 } else { | |
| 70 context_editor.SetInteger(kContextKeyScreenState, STATE_POWERWASH_PROPOSAL); | |
| 71 } | |
| 72 | |
| 73 // Set availability of Rollback feature. | |
| 74 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 75 switches::kDisableRollbackOption)) { | |
| 76 context_editor.SetBoolean(kContextKeyIsRollbackAvailable, false); | |
| 77 dialog_type = reset::DIALOG_SHORTCUT_OFFERING_ROLLBACK_UNAVAILABLE; | |
| 78 } else { | |
| 79 chromeos::DBusThreadManager::Get()->GetUpdateEngineClient()-> | |
| 80 CanRollbackCheck(base::Bind(&ResetScreen::OnRollbackCheck, | |
| 81 weak_ptr_factory_.GetWeakPtr())); | |
| 82 } | |
| 83 | |
| 84 if (dialog_type >= 0) { | |
| 85 UMA_HISTOGRAM_ENUMERATION("Reset.ChromeOS.PowerwashDialogShown", | |
| 86 dialog_type, | |
| 87 reset::DIALOG_VIEW_TYPE_SIZE); | |
| 88 } | |
| 89 | |
| 90 PrefService* prefs = g_browser_process->local_state(); | |
| 91 prefs->SetBoolean(prefs::kFactoryResetRequested, false); | |
| 92 prefs->CommitPendingWrite(); | |
| 93 } | 34 } |
| 94 | 35 |
| 95 void ResetScreen::Hide() { | 36 void ResetScreen::Hide() { |
| 96 if (view_) | 37 if (actor_) |
| 97 view_->Hide(); | 38 actor_->Hide(); |
| 98 } | 39 } |
| 99 | 40 |
| 100 void ResetScreen::OnViewDestroyed(ResetView* view) { | 41 std::string ResetScreen::GetName() const { |
| 101 if (view_ == view) | 42 return WizardController::kResetScreenName; |
| 102 view_ = nullptr; | |
| 103 } | 43 } |
| 104 | 44 |
| 105 void ResetScreen::OnUserAction(const std::string& action_id) { | 45 void ResetScreen::OnExit() { |
| 106 if (action_id == kUserActionCancelReset) | 46 Finish(BaseScreenDelegate::RESET_CANCELED); |
| 107 OnCancel(); | |
| 108 else if (action_id == kUserActionResetRestartPressed) | |
| 109 OnRestart(); | |
| 110 else if (action_id == kUserActionResetPowerwashPressed) | |
| 111 OnPowerwash(); | |
| 112 else if (action_id == kUserActionResetLearnMorePressed) | |
| 113 OnLearnMore(); | |
| 114 else if (action_id == kUserActionResetRollbackToggled) | |
| 115 OnToggleRollback(); | |
| 116 else if (action_id == kUserActionResetShowConfirmationPressed) | |
| 117 OnShowConfirm(); | |
| 118 else if (action_id == kUserActionResetResetConfirmationDismissed) | |
| 119 OnConfirmationDismissed(); | |
| 120 else | |
| 121 BaseScreen::OnUserAction(action_id); | |
| 122 } | 47 } |
| 123 | 48 |
| 124 void ResetScreen::OnCancel() { | 49 void ResetScreen::OnActorDestroyed(ResetScreenActor* actor) { |
| 125 if (context_.GetInteger( | 50 if (actor_ == actor) |
| 126 kContextKeyScreenState, STATE_RESTART_REQUIRED) == STATE_REVERT_PROMISE) | 51 actor_ = NULL; |
| 127 return; | |
| 128 // Hide Rollback view for the next show. | |
| 129 if (context_.GetBoolean(kContextKeyIsRollbackAvailable) && | |
| 130 context_.GetBoolean(kContextKeyIsRollbackChecked)) | |
| 131 OnToggleRollback(); | |
| 132 Finish(BaseScreenDelegate::RESET_CANCELED); | |
| 133 DBusThreadManager::Get()->GetUpdateEngineClient()->RemoveObserver(this); | |
| 134 } | |
| 135 | |
| 136 void ResetScreen::OnPowerwash() { | |
| 137 if (context_.GetInteger(kContextKeyScreenState, 0) != | |
| 138 STATE_POWERWASH_PROPOSAL) | |
| 139 return; | |
| 140 | |
| 141 GetContextEditor().SetBoolean(kContextKeyIsConfirmational, false); | |
| 142 CommitContextChanges(); | |
| 143 | |
| 144 if (context_.GetBoolean(kContextKeyIsRollbackAvailable) && | |
| 145 context_.GetBoolean(kContextKeyIsRollbackChecked)) { | |
| 146 GetContextEditor().SetInteger(kContextKeyScreenState, STATE_REVERT_PROMISE); | |
| 147 DBusThreadManager::Get()->GetUpdateEngineClient()->AddObserver(this); | |
| 148 VLOG(1) << "Starting Rollback"; | |
| 149 DBusThreadManager::Get()->GetUpdateEngineClient()->Rollback(); | |
| 150 } else { | |
| 151 if (context_.GetBoolean(kContextKeyIsRollbackChecked) && | |
| 152 !context_.GetBoolean(kContextKeyIsRollbackAvailable)) { | |
| 153 NOTREACHED() << | |
| 154 "Rollback was checked but not available. Starting powerwash."; | |
| 155 } | |
| 156 VLOG(1) << "Starting Powerwash"; | |
| 157 DBusThreadManager::Get()->GetSessionManagerClient()->StartDeviceWipe(); | |
| 158 } | |
| 159 } | |
| 160 | |
| 161 void ResetScreen::OnRestart() { | |
| 162 PrefService* prefs = g_browser_process->local_state(); | |
| 163 prefs->SetBoolean(prefs::kFactoryResetRequested, true); | |
| 164 prefs->CommitPendingWrite(); | |
| 165 | |
| 166 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); | |
| 167 } | |
| 168 | |
| 169 void ResetScreen::OnToggleRollback() { | |
| 170 // Hide Rollback if visible. | |
| 171 if (context_.GetBoolean(kContextKeyIsRollbackAvailable) && | |
| 172 context_.GetBoolean(kContextKeyIsRollbackChecked)) { | |
| 173 VLOG(1) << "Hiding rollback view on reset screen"; | |
| 174 GetContextEditor().SetBoolean(kContextKeyIsRollbackChecked, false); | |
| 175 return; | |
| 176 } | |
| 177 | |
| 178 // Show Rollback if available. | |
| 179 VLOG(1) << "Requested rollback availability" << | |
| 180 context_.GetBoolean(kContextKeyIsRollbackAvailable); | |
| 181 if (context_.GetBoolean(kContextKeyIsRollbackAvailable) && | |
| 182 !context_.GetBoolean(kContextKeyIsRollbackChecked)) { | |
| 183 UMA_HISTOGRAM_ENUMERATION( | |
| 184 "Reset.ChromeOS.PowerwashDialogShown", | |
| 185 reset::DIALOG_SHORTCUT_OFFERING_ROLLBACK_AVAILABLE, | |
| 186 reset::DIALOG_VIEW_TYPE_SIZE); | |
| 187 GetContextEditor().SetBoolean(kContextKeyIsRollbackChecked, true); | |
| 188 } | |
| 189 } | |
| 190 | |
| 191 void ResetScreen::OnShowConfirm() { | |
| 192 int dialog_type = context_.GetBoolean(kContextKeyIsRollbackChecked) ? | |
| 193 reset::DIALOG_SHORTCUT_CONFIRMING_POWERWASH_AND_ROLLBACK : | |
| 194 reset::DIALOG_SHORTCUT_CONFIRMING_POWERWASH_ONLY; | |
| 195 UMA_HISTOGRAM_ENUMERATION( | |
| 196 "Reset.ChromeOS.PowerwashDialogShown", | |
| 197 dialog_type, | |
| 198 reset::DIALOG_VIEW_TYPE_SIZE); | |
| 199 | |
| 200 GetContextEditor().SetBoolean(kContextKeyIsConfirmational, true); | |
| 201 } | |
| 202 | |
| 203 void ResetScreen::OnLearnMore() { | |
| 204 #if defined(OFFICIAL_BUILD) | |
| 205 VLOG(1) << "Trying to view the help article about reset options."; | |
| 206 if (!help_app_.get()) | |
| 207 help_app_ = new HelpAppLauncher(GetNativeWindow()); | |
| 208 help_app_->ShowHelpTopic(HelpAppLauncher::HELP_POWERWASH); | |
| 209 #endif | |
| 210 } | |
| 211 | |
| 212 void ResetScreen::OnConfirmationDismissed() { | |
| 213 GetContextEditor().SetBoolean(kContextKeyIsConfirmational, false); | |
| 214 } | |
| 215 | |
| 216 void ResetScreen::UpdateStatusChanged( | |
| 217 const UpdateEngineClient::Status& status) { | |
| 218 VLOG(1) << "Update status change to " << status.status; | |
| 219 if (status.status == UpdateEngineClient::UPDATE_STATUS_ERROR || | |
| 220 status.status == | |
| 221 UpdateEngineClient::UPDATE_STATUS_REPORTING_ERROR_EVENT) { | |
| 222 GetContextEditor().SetInteger(kContextKeyScreenState, STATE_ERROR); | |
| 223 // Show error screen. | |
| 224 GetErrorScreen()->SetUIState(ErrorScreen::UI_STATE_ROLLBACK_ERROR); | |
| 225 get_base_screen_delegate()->ShowErrorScreen(); | |
| 226 } else if (status.status == | |
| 227 UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT) { | |
| 228 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); | |
| 229 } | |
| 230 } | |
| 231 | |
| 232 // Invoked from call to CanRollbackCheck upon completion of the DBus call. | |
| 233 void ResetScreen::OnRollbackCheck(bool can_rollback) { | |
| 234 VLOG(1) << "Callback from CanRollbackCheck, result " << can_rollback; | |
| 235 int dialog_type = can_rollback ? | |
| 236 reset::DIALOG_SHORTCUT_OFFERING_ROLLBACK_AVAILABLE : | |
| 237 reset::DIALOG_SHORTCUT_OFFERING_ROLLBACK_UNAVAILABLE; | |
| 238 UMA_HISTOGRAM_ENUMERATION("Reset.ChromeOS.PowerwashDialogShown", | |
| 239 dialog_type, | |
| 240 reset::DIALOG_VIEW_TYPE_SIZE); | |
| 241 | |
| 242 GetContextEditor().SetBoolean(kContextKeyIsRollbackAvailable, can_rollback); | |
| 243 } | |
| 244 | |
| 245 ErrorScreen* ResetScreen::GetErrorScreen() { | |
| 246 return get_base_screen_delegate()->GetErrorScreen(); | |
| 247 } | 52 } |
| 248 | 53 |
| 249 } // namespace chromeos | 54 } // namespace chromeos |
| OLD | NEW |