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

Side by Side Diff: chrome/browser/ui/webui/cleanup_tool/cleanup_action_handler.cc

Issue 2822433003: Cleanup Tool WebUI: Add functionality to the Scan button (Closed)
Patch Set: Add comment to eventually localize strings Created 3 years, 8 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
« no previous file with comments | « chrome/browser/ui/webui/cleanup_tool/cleanup_action_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 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/cleanup_tool/cleanup_action_handler.h" 5 #include "chrome/browser/ui/webui/cleanup_tool/cleanup_action_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/timer/timer.h"
8 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/component_updater/sw_reporter_installer_win.h"
12
13 namespace {
14
15 bool IsCleanupComponentRegistered() {
16 component_updater::ComponentUpdateService* cus =
17 g_browser_process->component_updater();
18 std::vector<std::string> component_ids = cus->GetComponentIDs();
19
20 return std::find(component_ids.begin(), component_ids.end(),
21 component_updater::kSwReporterComponentId) !=
22 component_ids.end();
23 }
24
25 // TODO(proberge): Localize strings once they are finalized.
26 constexpr char kDetectionOkText[] = "No problems detected";
27 constexpr char kDetectionUwSText[] = "2 potentially harmful programs detected";
28 constexpr char kDetectionTimeText[] = "Last scanned today";
29 constexpr char kCleanupUnsupportedText[] = "Chrome Cleanup is not supported.";
30 constexpr char kUnsupportedHelpText[] = "Please try reinstalling Chrome";
tommycli 2017/04/21 18:24:21 Passing localized text back via the C++ handler se
tommycli 2017/04/21 18:28:21 To elaborate... we usually like to design our inte
proberge 2017/04/21 21:04:32 From the mocks I was implementing, two of the stri
tommycli 2017/04/21 21:57:02 It appears there's translation_expectations.pyl as
alito 2017/04/21 22:12:37 Re not translating strings: I've noticed that some
proberge 2017/04/25 17:39:32 Looks like we only have until May 11th to get stri
31
32 } // namespace
9 33
10 CleanupActionHandler::CleanupActionHandler() {} 34 CleanupActionHandler::CleanupActionHandler() {}
11 35
12 CleanupActionHandler::~CleanupActionHandler() {} 36 CleanupActionHandler::~CleanupActionHandler() {}
13 37
14 void CleanupActionHandler::RegisterMessages() { 38 void CleanupActionHandler::RegisterMessages() {
15 web_ui()->RegisterMessageCallback( 39 web_ui()->RegisterMessageCallback(
16 "requestLastScanResult", 40 "requestLastScanResult",
17 base::Bind(&CleanupActionHandler::HandleRequestLastScanResult, 41 base::Bind(&CleanupActionHandler::HandleRequestLastScanResult,
18 base::Unretained(this))); 42 base::Unretained(this)));
43 web_ui()->RegisterMessageCallback(
44 "startScan", base::Bind(&CleanupActionHandler::HandleStartScan,
45 base::Unretained(this)));
19 } 46 }
20 47
21 void CleanupActionHandler::HandleRequestLastScanResult( 48 void CleanupActionHandler::HandleRequestLastScanResult(
22 const base::ListValue* args) { 49 const base::ListValue* args) {
23 std::string webui_callback_id; 50 std::string webui_callback_id;
24 CHECK_EQ(1U, args->GetSize()); 51 CHECK_EQ(1U, args->GetSize());
25 bool success = args->GetString(0, &webui_callback_id); 52 bool success = args->GetString(0, &webui_callback_id);
26 DCHECK(success); 53 DCHECK(success);
27 54
28 base::DictionaryValue last_scan_results; 55 base::DictionaryValue last_scan_results;
29 // TODO(proberge): Return real information about the last run. 56 // TODO(proberge): Return real information about the last run.
30 // TODO(proberge): Localize strings once they are finalized.
31 last_scan_results.SetBoolean("hasScanResults", false); 57 last_scan_results.SetBoolean("hasScanResults", false);
32 last_scan_results.SetBoolean("isInfected", false); 58 last_scan_results.SetBoolean("isInfected", false);
33 last_scan_results.SetString("detectionStatusText", "No problems detected"); 59 last_scan_results.SetString("detectionStatusText", kDetectionOkText);
34 last_scan_results.SetString("detectionTimeText", "Last scanned today"); 60 last_scan_results.SetString("detectionTimeText", kDetectionTimeText);
35 61
36 AllowJavascript(); 62 AllowJavascript();
37 ResolveJavascriptCallback(base::Value(webui_callback_id), last_scan_results); 63 ResolveJavascriptCallback(base::Value(webui_callback_id), last_scan_results);
38 } 64 }
65
66 void CleanupActionHandler::HandleStartScan(const base::ListValue* args) {
67 std::string webui_callback_id;
68 CHECK_EQ(1U, args->GetSize());
69 bool success = args->GetString(0, &webui_callback_id);
70 DCHECK(success);
71
72 if (!IsCleanupComponentRegistered()) {
73 base::DictionaryValue scan_results;
74 scan_results.SetBoolean("hasScanResults", false);
75 scan_results.SetBoolean("isInfected", false);
76 scan_results.SetString("detectionStatusText", kCleanupUnsupportedText);
77 scan_results.SetString("detectionTimeText", kUnsupportedHelpText);
78
79 AllowJavascript();
80 ResolveJavascriptCallback(base::Value(webui_callback_id), scan_results);
81 return;
82 }
83
84 component_updater::RegisterUserInitiatedSwReporterScan(
85 base::Bind(&CleanupActionHandler::ReportScanResults,
86 base::Unretained(this), webui_callback_id));
87 }
88
89 void CleanupActionHandler::ReportScanResults(const std::string& callback_id) {
90 base::DictionaryValue scan_results;
91 // TODO(proberge): Return real information about the scan.
92 scan_results.SetBoolean("hasScanResults", true);
93 scan_results.SetBoolean("isInfected", true);
94 scan_results.SetString("detectionStatusText", kDetectionUwSText);
95 scan_results.SetString("detectionTimeText", kDetectionTimeText);
96
97 AllowJavascript();
tommycli 2017/04/21 18:24:21 I assume this scan can take a long time, where Jav
proberge 2017/04/21 21:04:32 Makes a lot of sense. Thanks for the example usage
98 ResolveJavascriptCallback(base::Value(callback_id), scan_results);
99 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/cleanup_tool/cleanup_action_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698