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

Side by Side Diff: chrome/browser/ui/webui/chromeos/login/enable_debugging_screen_handler.cc

Issue 539273002: Added UI to enable debugging features on CrOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/chromeos/login/enable_debugging_screen_handler .h"
6
7 #include <string>
8
9 #include "base/command_line.h"
10 #include "base/prefs/pref_registry_simple.h"
11 #include "base/prefs/pref_service.h"
12 #include "base/values.h"
13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/chromeos/login/help_app_launcher.h"
15 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
16 #include "chrome/common/pref_names.h"
17 #include "chrome/grit/chromium_strings.h"
18 #include "chrome/grit/generated_resources.h"
19 #include "chromeos/chromeos_switches.h"
20 #include "chromeos/dbus/dbus_thread_manager.h"
21 #include "chromeos/dbus/debug_daemon_client.h"
22 #include "chromeos/dbus/power_manager_client.h"
23
24 namespace {
25
26 const char kJsScreenPath[] = "login.EnableDebuggingScreen";
27
28 const char kEnableDebuggingScreen[] = "debugging";
29
30 } // namespace
31
32 namespace chromeos {
33
34 EnableDebuggingScreenHandler::EnableDebuggingScreenHandler()
35 : BaseScreenHandler(kJsScreenPath),
36 delegate_(NULL),
37 show_on_init_(false),
38 ready_for_setup_(false),
39 weak_ptr_factory_(this) {
40 }
41
42 EnableDebuggingScreenHandler::~EnableDebuggingScreenHandler() {
43 if (delegate_)
44 delegate_->OnActorDestroyed(this);
45 }
46
47 void EnableDebuggingScreenHandler::PrepareToShow() {
48 }
49
50 void EnableDebuggingScreenHandler::ShowWithParams() {
51 base::DictionaryValue debugging_screen_params;
52 #if defined(OFFICIAL_BUILD)
53 debugging_screen_params.SetBoolean("isOfficialBuild", true);
54 #endif
55 ShowScreen(kEnableDebuggingScreen, &debugging_screen_params);
56
57 // Check the status of debugging features.
58 chromeos::DebugDaemonClient* client =
59 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient();
60 client->QueryDebuggingFeatures(
61 base::Bind(&EnableDebuggingScreenHandler::OnQueryDebuggingFeatures,
62 weak_ptr_factory_.GetWeakPtr()));
63 }
64
65 void EnableDebuggingScreenHandler::Show() {
66 if (!page_is_ready()) {
67 show_on_init_ = true;
68 return;
69 }
70
71 ChooseAndApplyShowScenario();
72 }
73
74 void EnableDebuggingScreenHandler::ChooseAndApplyShowScenario() {
75 PrefService* prefs = g_browser_process->local_state();
76 bool fresh_start = !CommandLine::ForCurrentProcess()->HasSwitch(
77 switches::kFirstExecAfterBoot);
78
79 // TODO: Check if we have permission to show anything here.
80 if (fresh_start) { // First exec after boot.
81 ready_for_setup_ = prefs->GetBoolean(prefs::kDebuggingFeaturesRequested);
xiyuan 2014/10/31 03:36:01 prefs::kDebuggingFeaturesRequested and |ready_for_
zel 2014/10/31 23:23:43 Done.
82 }
83 ShowWithParams();
84 }
85
86 void EnableDebuggingScreenHandler::Hide() {
87 }
xiyuan 2014/10/31 03:36:01 weak_ptr_factory_.InvalidateWeakPtrs() to cancel p
zel 2014/10/31 23:23:43 good idea, done
88
89 void EnableDebuggingScreenHandler::SetDelegate(Delegate* delegate) {
90 delegate_ = delegate;
91 if (page_is_ready())
92 Initialize();
93 }
94
95 void EnableDebuggingScreenHandler::DeclareLocalizedValues(
96 LocalizedValuesBuilder* builder) {
97 builder->Add("enableDebuggingScreenTitle",
98 IDS_ENABLE_DEBUGGING_SCREEN_TITLE);
99 builder->Add("enableDebuggingScreenAccessibleTitle",
100 IDS_ENABLE_DEBUGGING_SCREEN_TITLE);
101 builder->Add("enableDebuggingScreenIconTitle", IDS_EXCLAMATION_ICON_TITLE);
102 builder->Add("enableDebuggingCancelButton", IDS_CANCEL);
103 builder->Add("enableDebuggingOKButton", IDS_OK);
104 builder->Add("enableDebuggingRemoveButton",
105 IDS_ENABLE_DEBUGGING_REMOVE_ROOTFS_BUTTON);
106 builder->Add("enableDebuggingEnableButton",
107 IDS_ENABLE_DEBUGGING_ENABLE_BUTTON);
108 builder->Add("enableDebuggingRemveRootfsMessage",
109 IDS_ENABLE_DEBUGGING_SCREEN_ROOTFS_REMOVE_MSG);
110 builder->Add("enableDebuggingSetupMessage",
111 IDS_ENABLE_DEBUGGING_SETUP_MESSAGE);
112 builder->Add("enableDebuggingWaitMessage",
113 IDS_ENABLE_DEBUGGING_WAIT_MESSAGE);
114 builder->AddF("enableDebuggingWarningTitle",
115 IDS_ENABLE_DEBUGGING_SCREEN_WARNING_MSG,
116 IDS_SHORT_PRODUCT_NAME);
117 builder->AddF("enableDebuggingDoneMessage",
118 IDS_ENABLE_DEBUGGING_DONE_MESSAGE,
119 IDS_SHORT_PRODUCT_NAME);
120 builder->AddF("enableDebuggingErrorMessage",
121 IDS_ENABLE_DEBUGGING_ERROR_MESSAGE,
xiyuan 2014/10/31 03:36:01 nit: wrong indent.
zel 2014/10/31 23:23:43 Done.
122 IDS_SHORT_PRODUCT_NAME);
123 builder->Add("enableDebuggingPasswordLabel",
124 IDS_ENABLE_DEBUGGING_ROOT_PASSWORD_LABEL);
125 builder->Add("enableDebuggingConfirmPasswordLabel",
126 IDS_ENABLE_DEBUGGING_CONFIRM_PASSWORD_LABEL);
127 builder->Add("enableDebuggingPasswordLengthNote",
128 IDS_ENABLE_DEBUGGING_EMPTY_ROOT_PASSWORD_LABEL);
129 }
130
131 // static
132 void EnableDebuggingScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) {
133 registry->RegisterBooleanPref(prefs::kDebuggingFeaturesRequested, false);
134 }
135
136 void EnableDebuggingScreenHandler::Initialize() {
137 if (!page_is_ready() || !delegate_)
138 return;
139
140 if (show_on_init_) {
141 Show();
142 show_on_init_ = false;
143 }
144 }
145
146 void EnableDebuggingScreenHandler::RegisterMessages() {
147 AddCallback("enableDebuggingOnCancel",
148 &EnableDebuggingScreenHandler::HandleOnCancel);
149 AddCallback("enableDebuggingOnDone",
150 &EnableDebuggingScreenHandler::HandleOnDone);
151 AddCallback("enableDebuggingOnLearnMore",
152 &EnableDebuggingScreenHandler::HandleOnLearnMore);
153 AddCallback("enableDebuggingOnRemoveRootFSProtection",
154 &EnableDebuggingScreenHandler::HandleOnRemoveRootFSProtection);
155 AddCallback("enableDebuggingOnSetup",
156 &EnableDebuggingScreenHandler::HandleOnSetup);
157 }
158
159 void EnableDebuggingScreenHandler::HandleOnCancel() {
160 if (delegate_)
161 delegate_->OnExit(false);
162 }
163
164 void EnableDebuggingScreenHandler::HandleOnDone() {
165 if (delegate_)
166 delegate_->OnExit(true);
167 }
168
169 void EnableDebuggingScreenHandler::HandleOnRemoveRootFSProtection() {
170 UpdateUIState(UI_STATE_WAIT);
171 chromeos::DebugDaemonClient* client =
172 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient();
173 client->RemoveRootfsVerification(
174 base::Bind(&EnableDebuggingScreenHandler::OnRemoveRootfsVerification,
175 weak_ptr_factory_.GetWeakPtr()));
176 }
177
178 void EnableDebuggingScreenHandler::HandleOnSetup(
179 const std::string& password) {
180 UpdateUIState(UI_STATE_WAIT);
181 chromeos::DebugDaemonClient* client =
182 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient();
183 client->EnableDebuggingFeatures(
184 password,
185 base::Bind(&EnableDebuggingScreenHandler::OnEnableDebuggingFeatures,
186 weak_ptr_factory_.GetWeakPtr()));
187 }
188
189 // Removes rootfs verification, add flag to start with enable debugging features
190 // screen and reboots the machine.
191 void EnableDebuggingScreenHandler::OnRemoveRootfsVerification(bool success) {
192 if (!success) {
193 UpdateUIState(UI_STATE_ERROR);
194 return;
195 }
196
197 PrefService* prefs = g_browser_process->local_state();
198 prefs->SetBoolean(prefs::kDebuggingFeaturesRequested, true);
199 prefs->CommitPendingWrite();
200 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart();
201 }
202
203
204 void EnableDebuggingScreenHandler::OnEnableDebuggingFeatures(bool success) {
205 if (!success) {
206 UpdateUIState(UI_STATE_ERROR);
207 return;
208 }
209
210 UpdateUIState(UI_STATE_DONE);
211 }
212
213
214 void EnableDebuggingScreenHandler::OnQueryDebuggingFeatures(bool success,
215 int features_flag) {
216 if (!success || features_flag == DebugDaemonClient::DEV_FEATURES_DISABLED) {
217 UpdateUIState(UI_STATE_ERROR);
218 return;
219 }
220
221 if (features_flag == DebugDaemonClient::DEV_FEATURE_NONE) {
222 UpdateUIState(UI_STATE_REMOVE_PROTECTION);
223 return;
224 }
225
226 if (features_flag & DebugDaemonClient::DEV_FEATURE_ALL_ENABLED) {
227 UpdateUIState(UI_STATE_DONE);
228 } else if (features_flag &
229 DebugDaemonClient::DEV_FEATURE_ROOTFS_VERIFICATION_REMOVED) {
230 UpdateUIState(UI_STATE_SETUP);
231 } else {
232 LOG(WARNING) << "Unexpected status of debugging features:" << features_flag;
233 UpdateUIState(UI_STATE_ERROR);
234 }
235 }
236
237 void EnableDebuggingScreenHandler::UpdateUIState(
238 EnableDebuggingScreenHandler::UIState state) {
239 if (state == UI_STATE_ERROR || state == UI_STATE_DONE) {
240 PrefService* prefs = g_browser_process->local_state();
241 prefs->ClearPref(prefs::kDebuggingFeaturesRequested);
242 prefs->CommitPendingWrite();
243 }
244
245 web_ui()->CallJavascriptFunction(
246 "login.EnableDebuggingScreen.updateState",
247 base::FundamentalValue(static_cast<int>(state)));
248 }
249
250 void EnableDebuggingScreenHandler::HandleOnLearnMore() {
251 VLOG(1) << "Trying to view the help article about debugging features.";
252 if (!help_app_.get())
253 help_app_ = new HelpAppLauncher(GetNativeWindow());
254 help_app_->ShowHelpTopic(HelpAppLauncher::HELP_ENABLE_DEBUGGING);
255 }
256
257 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698