OLD | NEW |
---|---|
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 constexpr char kDetectionOkText[] = "No problems detected"; | |
ftirelo
2017/04/18 13:50:59
Nit: please add a comment saying that these are pl
proberge
2017/04/18 15:28:17
I don't think the strings will come from the repor
| |
26 constexpr char kDetectionUwSText[] = "2 potentially harmful programs detected"; | |
27 constexpr char kDetectionTimeText[] = "Last scanned today"; | |
28 constexpr char kCleanupUnsupportedText[] = "Chrome Cleanup is not supported."; | |
29 constexpr char kUnsupportedHelpText[] = "Please try reinstalling Chrome"; | |
30 | |
31 } // namespace | |
9 | 32 |
10 CleanupActionHandler::CleanupActionHandler() {} | 33 CleanupActionHandler::CleanupActionHandler() {} |
11 | 34 |
12 CleanupActionHandler::~CleanupActionHandler() {} | 35 CleanupActionHandler::~CleanupActionHandler() {} |
13 | 36 |
14 void CleanupActionHandler::RegisterMessages() { | 37 void CleanupActionHandler::RegisterMessages() { |
15 web_ui()->RegisterMessageCallback( | 38 web_ui()->RegisterMessageCallback( |
16 "requestLastScanResult", | 39 "requestLastScanResult", |
17 base::Bind(&CleanupActionHandler::HandleRequestLastScanResult, | 40 base::Bind(&CleanupActionHandler::HandleRequestLastScanResult, |
18 base::Unretained(this))); | 41 base::Unretained(this))); |
42 web_ui()->RegisterMessageCallback( | |
43 "startScan", base::Bind(&CleanupActionHandler::HandleStartScan, | |
44 base::Unretained(this))); | |
19 } | 45 } |
20 | 46 |
21 void CleanupActionHandler::HandleRequestLastScanResult( | 47 void CleanupActionHandler::HandleRequestLastScanResult( |
22 const base::ListValue* args) { | 48 const base::ListValue* args) { |
23 std::string webui_callback_id; | 49 std::string webui_callback_id; |
24 CHECK_EQ(1U, args->GetSize()); | 50 CHECK_EQ(1U, args->GetSize()); |
25 bool success = args->GetString(0, &webui_callback_id); | 51 bool success = args->GetString(0, &webui_callback_id); |
26 DCHECK(success); | 52 DCHECK(success); |
27 | 53 |
28 base::DictionaryValue last_scan_results; | 54 base::DictionaryValue last_scan_results; |
29 // TODO(proberge): Return real information about the last run. | 55 // TODO(proberge): Return real information about the last run. |
30 // TODO(proberge): Localize strings once they are finalized. | 56 // 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 // TODO(proberge): Localize strings once they are finalized. | |
75 scan_results.SetBoolean("hasScanResults", false); | |
76 scan_results.SetBoolean("isInfected", false); | |
77 scan_results.SetString("detectionStatusText", kCleanupUnsupportedText); | |
78 scan_results.SetString("detectionTimeText", kUnsupportedHelpText); | |
79 | |
80 AllowJavascript(); | |
81 ResolveJavascriptCallback(base::Value(webui_callback_id), scan_results); | |
82 return; | |
83 } | |
84 | |
85 component_updater::RegisterUserInitiatedSwReporterScan( | |
86 base::Bind(&CleanupActionHandler::ReportScanResults, | |
87 base::Unretained(this), webui_callback_id)); | |
88 } | |
89 | |
90 void CleanupActionHandler::ReportScanResults(const std::string& callback_id) { | |
91 base::DictionaryValue scan_results; | |
92 // TODO(proberge): Return real information about the scan. | |
93 // TODO(proberge): Localize strings once they are finalized. | |
94 scan_results.SetBoolean("hasScanResults", true); | |
95 scan_results.SetBoolean("isInfected", true); | |
96 scan_results.SetString("detectionStatusText", kDetectionUwSText); | |
97 scan_results.SetString("detectionTimeText", kDetectionTimeText); | |
98 | |
99 AllowJavascript(); | |
100 ResolveJavascriptCallback(base::Value(callback_id), scan_results); | |
101 } | |
OLD | NEW |