|
1 |
| -// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 1 | +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 | 2 | // Use of this source code is governed by a BSD-style license that can be
|
3 | 3 | // found in the LICENSE file.
|
4 | 4 |
|
5 | 5 | #include "chrome/browser/chromeos/login/screens/reset_screen.h"
|
6 | 6 |
|
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" |
| 7 | +#include "base/logging.h" |
13 | 8 | #include "chrome/browser/chromeos/login/screens/base_screen_delegate.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 |
| - |
| 9 | +#include "chrome/browser/chromeos/login/wizard_controller.h" |
25 | 10 |
|
26 | 11 | namespace chromeos {
|
27 | 12 |
|
28 | 13 | ResetScreen::ResetScreen(BaseScreenDelegate* base_screen_delegate,
|
29 |
| - ResetView* view) |
30 |
| - : ResetModel(base_screen_delegate), |
31 |
| - view_(view), |
32 |
| - weak_ptr_factory_(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 |
| 14 | + ResetScreenActor* actor) |
| 15 | + : BaseScreen(base_screen_delegate), actor_(actor) { |
| 16 | + DCHECK(actor_); |
| 17 | + if (actor_) |
| 18 | + actor_->SetDelegate(this); |
44 | 19 | }
|
45 | 20 |
|
46 | 21 | ResetScreen::~ResetScreen() {
|
47 |
| - if (view_) |
48 |
| - view_->Unbind(); |
49 |
| - DBusThreadManager::Get()->GetUpdateEngineClient()->RemoveObserver(this); |
| 22 | + if (actor_) |
| 23 | + actor_->SetDelegate(NULL); |
50 | 24 | }
|
51 | 25 |
|
52 | 26 | void ResetScreen::PrepareToShow() {
|
53 |
| - if (view_) |
54 |
| - view_->PrepareToShow(); |
| 27 | + if (actor_) |
| 28 | + actor_->PrepareToShow(); |
55 | 29 | }
|
56 | 30 |
|
57 | 31 | void ResetScreen::Show() {
|
58 |
| - if (view_) |
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(); |
| 32 | + if (actor_) |
| 33 | + actor_->Show(); |
94 | 34 | }
|
95 | 35 |
|
96 | 36 | void ResetScreen::Hide() {
|
97 |
| - if (view_) |
98 |
| - view_->Hide(); |
99 |
| -} |
100 |
| - |
101 |
| -void ResetScreen::OnViewDestroyed(ResetView* view) { |
102 |
| - if (view_ == view) |
103 |
| - view_ = nullptr; |
| 37 | + if (actor_) |
| 38 | + actor_->Hide(); |
104 | 39 | }
|
105 | 40 |
|
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); |
| 41 | +std::string ResetScreen::GetName() const { |
| 42 | + return WizardController::kResetScreenName; |
123 | 43 | }
|
124 | 44 |
|
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(); |
| 45 | +void ResetScreen::OnExit() { |
133 | 46 | Finish(BaseScreenDelegate::RESET_CANCELED);
|
134 |
| - DBusThreadManager::Get()->GetUpdateEngineClient()->RemoveObserver(this); |
135 |
| -} |
136 |
| - |
137 |
| -void ResetScreen::OnPowerwash() { |
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()); |
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 | 47 | }
|
245 | 48 |
|
246 |
| -ErrorScreen* ResetScreen::GetErrorScreen() { |
247 |
| - return get_base_screen_delegate()->GetErrorScreen(); |
| 49 | +void ResetScreen::OnActorDestroyed(ResetScreenActor* actor) { |
| 50 | + if (actor_ == actor) |
| 51 | + actor_ = NULL; |
248 | 52 | }
|
249 | 53 |
|
250 | 54 | } // namespace chromeos
|
0 commit comments