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