Chromium Code Reviews| 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..62dbf0809c4cec53022d19354e52d2ea6a364c54 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,30 @@ |
| #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 { |
| + |
| +bool IsCleanupComponentRegistered() { |
| + component_updater::ComponentUpdateService* cus = |
| + g_browser_process->component_updater(); |
| + std::vector<std::string> component_ids = cus->GetComponentIDs(); |
| + |
| + return std::find(component_ids.begin(), component_ids.end(), |
| + component_updater::kSwReporterComponentId) != |
| + component_ids.end(); |
| +} |
| + |
| +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
|
| +constexpr char kDetectionUwSText[] = "2 potentially harmful programs detected"; |
| +constexpr char kDetectionTimeText[] = "Last scanned today"; |
| +constexpr char kCleanupUnsupportedText[] = "Chrome Cleanup is not supported."; |
| +constexpr char kUnsupportedHelpText[] = "Please try reinstalling Chrome"; |
| + |
| +} // namespace |
| CleanupActionHandler::CleanupActionHandler() {} |
| @@ -16,6 +39,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( |
| @@ -30,9 +56,46 @@ void CleanupActionHandler::HandleRequestLastScanResult( |
| // TODO(proberge): Localize strings once they are finalized. |
| last_scan_results.SetBoolean("hasScanResults", false); |
| last_scan_results.SetBoolean("isInfected", false); |
| - last_scan_results.SetString("detectionStatusText", "No problems detected"); |
| - last_scan_results.SetString("detectionTimeText", "Last scanned today"); |
| + last_scan_results.SetString("detectionStatusText", kDetectionOkText); |
| + last_scan_results.SetString("detectionTimeText", kDetectionTimeText); |
| 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()) { |
| + base::DictionaryValue scan_results; |
| + // TODO(proberge): Localize strings once they are finalized. |
| + scan_results.SetBoolean("hasScanResults", false); |
| + scan_results.SetBoolean("isInfected", false); |
| + scan_results.SetString("detectionStatusText", kCleanupUnsupportedText); |
| + scan_results.SetString("detectionTimeText", kUnsupportedHelpText); |
| + |
| + 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(const 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", kDetectionUwSText); |
| + scan_results.SetString("detectionTimeText", kDetectionTimeText); |
| + |
| + AllowJavascript(); |
| + ResolveJavascriptCallback(base::Value(callback_id), scan_results); |
| +} |