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/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 | |
25 | 10 |
26 namespace chromeos { | 11 namespace chromeos { |
27 | 12 |
28 ResetScreen::ResetScreen(BaseScreenDelegate* base_screen_delegate, | 13 ResetScreen::ResetScreen(BaseScreenDelegate* base_screen_delegate, |
29 ResetView* view) | 14 ResetScreenActor* actor) |
30 : ResetModel(base_screen_delegate), | 15 : BaseScreen(base_screen_delegate), actor_(actor) { |
31 view_(view), | 16 DCHECK(actor_); |
32 weak_ptr_factory_(this) { | 17 if (actor_) |
33 DCHECK(view_); | 18 actor_->SetDelegate(this); |
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 | |
44 } | 19 } |
45 | 20 |
46 ResetScreen::~ResetScreen() { | 21 ResetScreen::~ResetScreen() { |
47 if (view_) | 22 if (actor_) |
48 view_->Unbind(); | 23 actor_->SetDelegate(NULL); |
49 DBusThreadManager::Get()->GetUpdateEngineClient()->RemoveObserver(this); | |
50 } | 24 } |
51 | 25 |
52 void ResetScreen::PrepareToShow() { | 26 void ResetScreen::PrepareToShow() { |
53 if (view_) | 27 if (actor_) |
54 view_->PrepareToShow(); | 28 actor_->PrepareToShow(); |
55 } | 29 } |
56 | 30 |
57 void ResetScreen::Show() { | 31 void ResetScreen::Show() { |
58 if (view_) | 32 if (actor_) |
59 view_->Show(); | 33 actor_->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(); | |
94 } | 34 } |
95 | 35 |
96 void ResetScreen::Hide() { | 36 void ResetScreen::Hide() { |
97 if (view_) | 37 if (actor_) |
98 view_->Hide(); | 38 actor_->Hide(); |
99 } | 39 } |
100 | 40 |
101 void ResetScreen::OnViewDestroyed(ResetView* view) { | 41 std::string ResetScreen::GetName() const { |
102 if (view_ == view) | 42 return WizardController::kResetScreenName; |
103 view_ = nullptr; | |
104 } | 43 } |
105 | 44 |
106 void ResetScreen::OnUserAction(const std::string& action_id) { | 45 void ResetScreen::OnExit() { |
107 if (action_id == kUserActionCancelReset) | 46 Finish(BaseScreenDelegate::RESET_CANCELED); |
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 } | 47 } |
124 | 48 |
125 void ResetScreen::OnCancel() { | 49 void ResetScreen::OnActorDestroyed(ResetScreenActor* actor) { |
126 if (context_.GetInteger( | 50 if (actor_ == actor) |
127 kContextKeyScreenState, STATE_RESTART_REQUIRED) == STATE_REVERT_PROMISE) | 51 actor_ = NULL; |
128 return; | |
129 // Hide Rollback view for the next show. | |
130 if (context_.GetBoolean(kContextKeyIsRollbackAvailable) && | |
131 context_.GetBoolean(kContextKeyIsRollbackChecked)) | |
132 OnToggleRollback(); | |
133 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 } | |
245 | |
246 ErrorScreen* ResetScreen::GetErrorScreen() { | |
247 return get_base_screen_delegate()->GetErrorScreen(); | |
248 } | 52 } |
249 | 53 |
250 } // namespace chromeos | 54 } // namespace chromeos |
OLD | NEW |