Index: chrome/browser/ui/webui/cleanup_tool/cleanup_action_handler.cc |
diff --git a/chrome/browser/ui/webui/cleanup_tool/cleanup_action_handler.cc b/chrome/browser/ui/webui/cleanup_tool/cleanup_action_handler.cc |
index 1a84b1aebcf12e1a89f46067f1b4f0e15f51f126..f5417dc38e3d0cae0a3e2639bcd4b42c63bade7d 100644 |
--- a/chrome/browser/ui/webui/cleanup_tool/cleanup_action_handler.cc |
+++ b/chrome/browser/ui/webui/cleanup_tool/cleanup_action_handler.cc |
@@ -5,7 +5,26 @@ |
#include "chrome/browser/ui/webui/cleanup_tool/cleanup_action_handler.h" |
#include "base/bind.h" |
+#include "base/timer/timer.h" |
#include "base/values.h" |
+#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/component_updater/sw_reporter_installer_win.h" |
+ |
+namespace { |
+ |
+constexpr char kComponentId[] = "gkmgaooipdjhmangpemjhigmamcehddo"; |
ftirelo
2017/04/13 17:10:43
Please declare this in chrome/browser/component_up
proberge
2017/04/13 18:53:02
Done.
|
+ |
+bool IsCleanupComponentRegistered() { |
+ component_updater::ComponentUpdateService* cus = |
+ g_browser_process->component_updater(); |
+ std::vector<std::string> component_ids; |
+ component_ids = cus->GetComponentIDs(); |
ftirelo
2017/04/13 17:10:43
Please merge this into the previous line.
proberge
2017/04/13 18:53:02
Done.
|
+ |
+ return std::find(component_ids.begin(), component_ids.end(), kComponentId) != |
+ component_ids.end(); |
+} |
+ |
+} // namespace |
CleanupActionHandler::CleanupActionHandler() {} |
@@ -16,6 +35,9 @@ void CleanupActionHandler::RegisterMessages() { |
"requestLastScanResult", |
base::Bind(&CleanupActionHandler::HandleRequestLastScanResult, |
base::Unretained(this))); |
+ web_ui()->RegisterMessageCallback( |
+ "startScan", base::Bind(&CleanupActionHandler::HandleStartScan, |
+ base::Unretained(this))); |
} |
void CleanupActionHandler::HandleRequestLastScanResult( |
@@ -36,3 +58,43 @@ void CleanupActionHandler::HandleRequestLastScanResult( |
AllowJavascript(); |
ResolveJavascriptCallback(base::Value(webui_callback_id), last_scan_results); |
} |
+ |
+void CleanupActionHandler::HandleStartScan(const base::ListValue* args) { |
+ std::string webui_callback_id; |
+ CHECK_EQ(1U, args->GetSize()); |
+ bool success = args->GetString(0, &webui_callback_id); |
+ DCHECK(success); |
+ |
+ if (!IsCleanupComponentRegistered()) { |
ftirelo
2017/04/13 17:10:43
What happens if the reporter is not available beca
proberge
2017/04/13 18:53:03
RegisterUserInitiatedSwReporterScan is responsible
|
+ base::DictionaryValue scan_results; |
+ // TODO(proberge): Localize strings once they are finalized. |
ftirelo
2017/04/13 17:10:43
Please move these strings to constants at the begi
proberge
2017/04/13 18:53:02
Done.
|
+ scan_results.SetBoolean("hasScanResults", false); |
+ scan_results.SetBoolean("isInfected", false); |
+ scan_results.SetString("detectionStatusText", |
+ "The Cleanup Tool is not supported."); |
ftirelo
2017/04/13 17:10:43
Nit: The Cleanup Tool -> Chrome Cleanup
proberge
2017/04/13 18:53:03
Done.
|
+ scan_results.SetString("detectionTimeText", |
+ "Please try reinstalling Chrome"); |
+ |
+ AllowJavascript(); |
+ ResolveJavascriptCallback(base::Value(webui_callback_id), scan_results); |
+ return; |
+ } |
+ |
+ component_updater::RegisterUserInitiatedSwReporterScan( |
+ base::Bind(&CleanupActionHandler::ReportScanResults, |
+ base::Unretained(this), webui_callback_id)); |
+} |
+ |
+void CleanupActionHandler::ReportScanResults(std::string callback_id) { |
+ base::DictionaryValue scan_results; |
+ // TODO(proberge): Return real information about the scan. |
+ // TODO(proberge): Localize strings once they are finalized. |
+ scan_results.SetBoolean("hasScanResults", true); |
+ scan_results.SetBoolean("isInfected", true); |
+ scan_results.SetString("detectionStatusText", |
+ "2 potentially harmful programs detected"); |
ftirelo
2017/04/13 17:10:43
Please add a comment that these are being used as
proberge
2017/04/13 18:53:02
On top of the TODO at the top of this method?
|
+ scan_results.SetString("detectionTimeText", "Last scanned today"); |
+ |
+ AllowJavascript(); |
+ ResolveJavascriptCallback(base::Value(callback_id), scan_results); |
+} |