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

Side by Side Diff: chrome/browser/ui/webui/settings/chrome_cleanup_handler.cc

Issue 2971823002: Cleanup Tool WebUI: Add logs upload checkbox and minor polishing (Closed)
Patch Set: Address review comments on #3, simplify idle error cases Created 3 years, 5 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) 2017 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2017 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/ui/webui/settings/chrome_cleanup_handler.h" 5 #include "chrome/browser/ui/webui/settings/chrome_cleanup_handler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/feature_list.h" 10 #include "base/feature_list.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 base::Bind(&ChromeCleanupHandler::HandleDismiss, base::Unretained(this))); 68 base::Bind(&ChromeCleanupHandler::HandleDismiss, base::Unretained(this)));
69 web_ui()->RegisterMessageCallback( 69 web_ui()->RegisterMessageCallback(
70 "registerChromeCleanerObserver", 70 "registerChromeCleanerObserver",
71 base::Bind(&ChromeCleanupHandler::HandleRegisterChromeCleanerObserver, 71 base::Bind(&ChromeCleanupHandler::HandleRegisterChromeCleanerObserver,
72 base::Unretained(this))); 72 base::Unretained(this)));
73 web_ui()->RegisterMessageCallback( 73 web_ui()->RegisterMessageCallback(
74 "restartComputer", 74 "restartComputer",
75 base::Bind(&ChromeCleanupHandler::HandleRestartComputer, 75 base::Bind(&ChromeCleanupHandler::HandleRestartComputer,
76 base::Unretained(this))); 76 base::Unretained(this)));
77 web_ui()->RegisterMessageCallback( 77 web_ui()->RegisterMessageCallback(
78 "setLogsUploadPermission",
79 base::Bind(&ChromeCleanupHandler::HandleSetLogsUploadPermission,
80 base::Unretained(this)));
81 web_ui()->RegisterMessageCallback(
78 "startCleanup", base::Bind(&ChromeCleanupHandler::HandleStartCleanup, 82 "startCleanup", base::Bind(&ChromeCleanupHandler::HandleStartCleanup,
79 base::Unretained(this))); 83 base::Unretained(this)));
80 } 84 }
81 85
82 void ChromeCleanupHandler::OnJavascriptAllowed() { 86 void ChromeCleanupHandler::OnJavascriptAllowed() {
83 controller_->AddObserver(this); 87 controller_->AddObserver(this);
84 } 88 }
85 89
86 void ChromeCleanupHandler::OnJavascriptDisallowed() { 90 void ChromeCleanupHandler::OnJavascriptDisallowed() {
87 controller_->RemoveObserver(this); 91 controller_->RemoveObserver(this);
(...skipping 21 matching lines...) Expand all
109 CallJavascriptFunction("cr.webUIListenerCallback", 113 CallJavascriptFunction("cr.webUIListenerCallback",
110 base::Value("chrome-cleanup-on-cleaning"), 114 base::Value("chrome-cleanup-on-cleaning"),
111 GetFilesAsListStorage(files)); 115 GetFilesAsListStorage(files));
112 } 116 }
113 117
114 void ChromeCleanupHandler::OnRebootRequired() { 118 void ChromeCleanupHandler::OnRebootRequired() {
115 CallJavascriptFunction("cr.webUIListenerCallback", 119 CallJavascriptFunction("cr.webUIListenerCallback",
116 base::Value("chrome-cleanup-on-reboot-required")); 120 base::Value("chrome-cleanup-on-reboot-required"));
117 } 121 }
118 122
123 void ChromeCleanupHandler::OnLogsEnabledChanged(bool logs_enabled) {
124 CallJavascriptFunction("cr.webUIListenerCallback",
125 base::Value("chrome-cleanup-upload-permission-change"),
126 base::Value(logs_enabled));
127 }
128
119 void ChromeCleanupHandler::HandleDismiss(const base::ListValue* args) { 129 void ChromeCleanupHandler::HandleDismiss(const base::ListValue* args) {
120 DCHECK_EQ(0U, args->GetSize()); 130 DCHECK_EQ(0U, args->GetSize());
121 131
122 controller_->RemoveObserver(this); 132 controller_->RemoveObserver(this);
123 133
124 CallJavascriptFunction("cr.webUIListenerCallback", 134 CallJavascriptFunction("cr.webUIListenerCallback",
125 base::Value("chrome-cleanup-on-dismiss")); 135 base::Value("chrome-cleanup-on-dismiss"));
126 } 136 }
127 137
128 void ChromeCleanupHandler::HandleRegisterChromeCleanerObserver( 138 void ChromeCleanupHandler::HandleRegisterChromeCleanerObserver(
129 const base::ListValue* args) { 139 const base::ListValue* args) {
130 DCHECK_EQ(0U, args->GetSize()); 140 DCHECK_EQ(0U, args->GetSize());
131 // The Polymer element should never be attached if the feature is 141 // The Polymer element should never be attached if the feature is
132 // disabled. 142 // disabled.
133 DCHECK( 143 DCHECK(
134 base::FeatureList::IsEnabled(safe_browsing::kInBrowserCleanerUIFeature)); 144 base::FeatureList::IsEnabled(safe_browsing::kInBrowserCleanerUIFeature));
135 145
136 AllowJavascript(); 146 AllowJavascript();
147
148 // Send the current logs upload state.
149 OnLogsEnabledChanged(controller_->logs_enabled());
137 } 150 }
138 151
139 void ChromeCleanupHandler::HandleRestartComputer(const base::ListValue* args) { 152 void ChromeCleanupHandler::HandleRestartComputer(const base::ListValue* args) {
140 DCHECK_EQ(0U, args->GetSize()); 153 DCHECK_EQ(0U, args->GetSize());
141 154
142 CallJavascriptFunction("cr.webUIListenerCallback", 155 CallJavascriptFunction("cr.webUIListenerCallback",
143 base::Value("chrome-cleanup-on-dismiss")); 156 base::Value("chrome-cleanup-on-dismiss"));
144 // TODO(proberge): Show a prompt to reboot the system. 157
158 controller_->Reboot();
159 }
160
161 void ChromeCleanupHandler::HandleSetLogsUploadPermission(
162 const base::ListValue* args) {
163 CHECK_EQ(1U, args->GetSize());
164 bool allow_logs_upload = false;
165 args->GetBoolean(0, &allow_logs_upload);
166
167 controller_->SetLogsEnabled(allow_logs_upload);
145 } 168 }
146 169
147 void ChromeCleanupHandler::HandleStartCleanup(const base::ListValue* args) { 170 void ChromeCleanupHandler::HandleStartCleanup(const base::ListValue* args) {
148 DCHECK_EQ(0U, args->GetSize()); 171 CHECK_EQ(1U, args->GetSize());
172 bool allow_logs_upload = false;
173 args->GetBoolean(0, &allow_logs_upload);
174
175 // The state is propagated to all open tabs and should be consistent.
176 DCHECK_EQ(controller_->logs_enabled(), allow_logs_upload);
149 177
150 controller_->ReplyWithUserResponse( 178 controller_->ReplyWithUserResponse(
151 // TODO(proberge): Send kAcceptedWithLogs or kAcceptedWithoutLogs based on 179 profile_,
152 // the state of a logs upload permissions checkbox. 180 allow_logs_upload
153 profile_, ChromeCleanerController::UserResponse::kAcceptedWithoutLogs); 181 ? ChromeCleanerController::UserResponse::kAcceptedWithLogs
182 : ChromeCleanerController::UserResponse::kAcceptedWithoutLogs);
154 } 183 }
155 184
156 } // namespace settings 185 } // namespace settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698