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

Side by Side Diff: chrome/browser/chromeos/login/screens/reset_screen.cc

Issue 904163003: Reset Screen moved to ScreenContext. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: User actions introduced. Created 5 years, 10 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
OLDNEW
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/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
10 24
11 namespace chromeos { 25 namespace chromeos {
12 26
13 ResetScreen::ResetScreen(BaseScreenDelegate* base_screen_delegate, 27 ResetScreen::ResetScreen(BaseScreenDelegate* base_screen_delegate,
14 ResetScreenActor* actor) 28 ResetView* view)
15 : BaseScreen(base_screen_delegate), actor_(actor) { 29 : ResetModel(base_screen_delegate),
16 DCHECK(actor_); 30 view_(view),
17 if (actor_) 31 weak_ptr_factory_(this) {
18 actor_->SetDelegate(this); 32 DCHECK(view_);
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
19 } 43 }
20 44
21 ResetScreen::~ResetScreen() { 45 ResetScreen::~ResetScreen() {
22 if (actor_) 46 if (view_)
23 actor_->SetDelegate(NULL); 47 view_->Unbind();
48 DBusThreadManager::Get()->GetUpdateEngineClient()->RemoveObserver(this);
24 } 49 }
25 50
26 void ResetScreen::PrepareToShow() { 51 void ResetScreen::PrepareToShow() {
27 if (actor_) 52 if (view_)
28 actor_->PrepareToShow(); 53 view_->PrepareToShow();
29 } 54 }
30 55
31 void ResetScreen::Show() { 56 void ResetScreen::Show() {
32 if (actor_) 57 if (view_)
33 actor_->Show(); 58 view_->Show();
59
60 int dialog_type = -1; // used by UMA metrics.
61
62 bool restart_required = !base::CommandLine::ForCurrentProcess()->HasSwitch(
63 switches::kFirstExecAfterBoot);
64 if (restart_required) {
65 context_.SetInteger(kContextKeyScreenState, STATE_RESTART_REQUIRED);
66 dialog_type = reset::DIALOG_SHORTCUT_RESTART_REQUIRED;
67 } else {
68 context_.SetInteger(kContextKeyScreenState, STATE_POWERWASH_PROPOSAL);
69 }
70
71 // Set availability of Rollback feature.
72 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
73 switches::kDisableRollbackOption)) {
74 context_.SetBoolean(kContextKeyIsRollbackAvailable, false);
75 dialog_type = reset::DIALOG_SHORTCUT_OFFERING_ROLLBACK_UNAVAILABLE;
76 } else {
77 chromeos::DBusThreadManager::Get()->GetUpdateEngineClient()->
78 CanRollbackCheck(base::Bind(&ResetScreen::OnRollbackCheck,
79 weak_ptr_factory_.GetWeakPtr()));
80 }
81
82 CommitContextChanges();
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();
34 } 93 }
35 94
36 void ResetScreen::Hide() { 95 void ResetScreen::Hide() {
37 if (actor_) 96 if (view_)
38 actor_->Hide(); 97 view_->Hide();
39 } 98 }
40 99
41 std::string ResetScreen::GetName() const { 100 void ResetScreen::OnViewDestroyed(ResetView* view) {
42 return WizardController::kResetScreenName; 101 if (view_ == view)
43 } 102 view_ = nullptr;
44 103 }
45 void ResetScreen::OnExit() { 104
105 void ResetScreen::OnUserAction(const std::string& action_id) {
106 if (action_id == kUserActionCancelReset)
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 }
119
120 void ResetScreen::OnCancel() {
121 if (context_.GetInteger(kContextKeyScreenState, STATE_RESTART_REQUIRED) ==
122 STATE_REVERT_PROMISE)
123 return;
124 // Hide Rollback view for the next show.
125 if (context_.GetBoolean(kContextKeyIsRollbackAvailable) &&
126 context_.GetBoolean(kContextKeyIsRollbackChecked))
127 OnToggleRollback();
46 Finish(BaseScreenDelegate::RESET_CANCELED); 128 Finish(BaseScreenDelegate::RESET_CANCELED);
47 } 129 DBusThreadManager::Get()->GetUpdateEngineClient()->RemoveObserver(this);
48 130 }
49 void ResetScreen::OnActorDestroyed(ResetScreenActor* actor) { 131
50 if (actor_ == actor) 132 void ResetScreen::OnPowerwash() {
51 actor_ = NULL; 133 if (context_.GetBoolean(kContextKeyIsRollbackAvailable) &&
134 context_.GetBoolean(kContextKeyIsRollbackChecked)) {
135 context_.SetInteger(kContextKeyScreenState, STATE_REVERT_PROMISE);
136 CommitContextChanges();
137 DBusThreadManager::Get()->GetUpdateEngineClient()->AddObserver(this);
138 VLOG(1) << "Starting Rollback";
139 DBusThreadManager::Get()->GetUpdateEngineClient()->Rollback();
140 } else {
141 if (context_.GetBoolean(kContextKeyIsRollbackChecked) &&
142 !context_.GetBoolean(kContextKeyIsRollbackAvailable)) {
143 NOTREACHED() <<
144 "Rollback was checked but not available. Starting powerwash.";
145 }
146 VLOG(1) << "Starting Powerwash";
147 DBusThreadManager::Get()->GetSessionManagerClient()->StartDeviceWipe();
148 }
149 }
150
151 void ResetScreen::OnRestart() {
152 PrefService* prefs = g_browser_process->local_state();
153 prefs->SetBoolean(prefs::kFactoryResetRequested, true);
154 prefs->CommitPendingWrite();
155
156 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart();
157 }
158
159 void ResetScreen::OnToggleRollback() {
160 // Hide Rollback if visible.
161
162 if (context_.GetBoolean(kContextKeyIsRollbackAvailable) &&
163 context_.GetBoolean(kContextKeyIsRollbackChecked)) {
164 VLOG(1) << "Hiding rollback view on reset screen";
165 context_.SetBoolean(kContextKeyIsRollbackChecked, false);
166 CommitContextChanges();
167 return;
168 }
169
170 // Show Rollback if available.
171 VLOG(1) << "Requested rollback availability" <<
172 context_.GetBoolean(kContextKeyIsRollbackAvailable);
173 if (context_.GetBoolean(kContextKeyIsRollbackAvailable) &&
174 !context_.GetBoolean(kContextKeyIsRollbackChecked)) {
175 UMA_HISTOGRAM_ENUMERATION(
176 "Reset.ChromeOS.PowerwashDialogShown",
177 reset::DIALOG_SHORTCUT_OFFERING_ROLLBACK_AVAILABLE,
178 reset::DIALOG_VIEW_TYPE_SIZE);
179 context_.SetBoolean(kContextKeyIsRollbackChecked, true);
180 CommitContextChanges();
181 }
182 }
183
184 void ResetScreen::OnShowConfirm() {
185 int dialog_type = context_.GetBoolean(kContextKeyIsRollbackChecked) ?
186 reset::DIALOG_SHORTCUT_CONFIRMING_POWERWASH_AND_ROLLBACK :
187 reset::DIALOG_SHORTCUT_CONFIRMING_POWERWASH_ONLY;
188 UMA_HISTOGRAM_ENUMERATION(
189 "Reset.ChromeOS.PowerwashDialogShown",
190 dialog_type,
191 reset::DIALOG_VIEW_TYPE_SIZE);
192 }
193
194 void ResetScreen::OnLearnMore() {
195 #if defined(OFFICIAL_BUILD)
196 VLOG(1) << "Trying to view the help article about reset options.";
197 if (!help_app_.get())
198 help_app_ = new HelpAppLauncher(GetNativeWindow());
199 help_app_->ShowHelpTopic(HelpAppLauncher::HELP_POWERWASH);
200 #endif
201 }
202
203 void ResetScreen::UpdateStatusChanged(
204 const UpdateEngineClient::Status& status) {
205 VLOG(1) << "Update status change to " << status.status;
206 if (status.status == UpdateEngineClient::UPDATE_STATUS_ERROR ||
207 status.status ==
208 UpdateEngineClient::UPDATE_STATUS_REPORTING_ERROR_EVENT) {
209 context_.SetInteger(kContextKeyScreenState, STATE_ERROR);
210 // Show error screen.
211 GetErrorScreen()->SetUIState(ErrorScreen::UI_STATE_ROLLBACK_ERROR);
212 get_base_screen_delegate()->ShowErrorScreen();
213 } else if (status.status ==
214 UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT) {
215 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart();
216 }
217 }
218
219 // Invoked from call to CanRollbackCheck upon completion of the DBus call.
220 void ResetScreen::OnRollbackCheck(bool can_rollback) {
221 VLOG(1) << "Callback from CanRollbackCheck, result " << can_rollback;
222 int dialog_type = can_rollback ?
223 reset::DIALOG_SHORTCUT_OFFERING_ROLLBACK_AVAILABLE :
224 reset::DIALOG_SHORTCUT_OFFERING_ROLLBACK_UNAVAILABLE;
225 UMA_HISTOGRAM_ENUMERATION("Reset.ChromeOS.PowerwashDialogShown",
226 dialog_type,
227 reset::DIALOG_VIEW_TYPE_SIZE);
228
229 context_.SetBoolean(kContextKeyIsRollbackAvailable, can_rollback);
230 CommitContextChanges();
231 }
232
233 ErrorScreen* ResetScreen::GetErrorScreen() {
234 return get_base_screen_delegate()->GetErrorScreen();
52 } 235 }
53 236
54 } // namespace chromeos 237 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698