Chromium Code Reviews| 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 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.
| |
| 16 | |
| 17 bool IsCleanupComponentRegistered() { | |
| 18 component_updater::ComponentUpdateService* cus = | |
| 19 g_browser_process->component_updater(); | |
| 20 std::vector<std::string> component_ids; | |
| 21 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.
| |
| 22 | |
| 23 return std::find(component_ids.begin(), component_ids.end(), kComponentId) != | |
| 24 component_ids.end(); | |
| 25 } | |
| 26 | |
| 27 } // namespace | |
| 9 | 28 |
| 10 CleanupActionHandler::CleanupActionHandler() {} | 29 CleanupActionHandler::CleanupActionHandler() {} |
| 11 | 30 |
| 12 CleanupActionHandler::~CleanupActionHandler() {} | 31 CleanupActionHandler::~CleanupActionHandler() {} |
| 13 | 32 |
| 14 void CleanupActionHandler::RegisterMessages() { | 33 void CleanupActionHandler::RegisterMessages() { |
| 15 web_ui()->RegisterMessageCallback( | 34 web_ui()->RegisterMessageCallback( |
| 16 "requestLastScanResult", | 35 "requestLastScanResult", |
| 17 base::Bind(&CleanupActionHandler::HandleRequestLastScanResult, | 36 base::Bind(&CleanupActionHandler::HandleRequestLastScanResult, |
| 18 base::Unretained(this))); | 37 base::Unretained(this))); |
| 38 web_ui()->RegisterMessageCallback( | |
| 39 "startScan", base::Bind(&CleanupActionHandler::HandleStartScan, | |
| 40 base::Unretained(this))); | |
| 19 } | 41 } |
| 20 | 42 |
| 21 void CleanupActionHandler::HandleRequestLastScanResult( | 43 void CleanupActionHandler::HandleRequestLastScanResult( |
| 22 const base::ListValue* args) { | 44 const base::ListValue* args) { |
| 23 std::string webui_callback_id; | 45 std::string webui_callback_id; |
| 24 CHECK_EQ(1U, args->GetSize()); | 46 CHECK_EQ(1U, args->GetSize()); |
| 25 bool success = args->GetString(0, &webui_callback_id); | 47 bool success = args->GetString(0, &webui_callback_id); |
| 26 DCHECK(success); | 48 DCHECK(success); |
| 27 | 49 |
| 28 base::DictionaryValue last_scan_results; | 50 base::DictionaryValue last_scan_results; |
| 29 // TODO(proberge): Return real information about the last run. | 51 // TODO(proberge): Return real information about the last run. |
| 30 // TODO(proberge): Localize strings once they are finalized. | 52 // TODO(proberge): Localize strings once they are finalized. |
| 31 last_scan_results.SetBoolean("hasScanResults", false); | 53 last_scan_results.SetBoolean("hasScanResults", false); |
| 32 last_scan_results.SetBoolean("isInfected", false); | 54 last_scan_results.SetBoolean("isInfected", false); |
| 33 last_scan_results.SetString("detectionStatusText", "No problems detected"); | 55 last_scan_results.SetString("detectionStatusText", "No problems detected"); |
| 34 last_scan_results.SetString("detectionTimeText", "Last scanned today"); | 56 last_scan_results.SetString("detectionTimeText", "Last scanned today"); |
| 35 | 57 |
| 36 AllowJavascript(); | 58 AllowJavascript(); |
| 37 ResolveJavascriptCallback(base::Value(webui_callback_id), last_scan_results); | 59 ResolveJavascriptCallback(base::Value(webui_callback_id), last_scan_results); |
| 38 } | 60 } |
| 61 | |
| 62 void CleanupActionHandler::HandleStartScan(const base::ListValue* args) { | |
| 63 std::string webui_callback_id; | |
| 64 CHECK_EQ(1U, args->GetSize()); | |
| 65 bool success = args->GetString(0, &webui_callback_id); | |
| 66 DCHECK(success); | |
| 67 | |
| 68 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
| |
| 69 base::DictionaryValue scan_results; | |
| 70 // 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.
| |
| 71 scan_results.SetBoolean("hasScanResults", false); | |
| 72 scan_results.SetBoolean("isInfected", false); | |
| 73 scan_results.SetString("detectionStatusText", | |
| 74 "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.
| |
| 75 scan_results.SetString("detectionTimeText", | |
| 76 "Please try reinstalling Chrome"); | |
| 77 | |
| 78 AllowJavascript(); | |
| 79 ResolveJavascriptCallback(base::Value(webui_callback_id), scan_results); | |
| 80 return; | |
| 81 } | |
| 82 | |
| 83 component_updater::RegisterUserInitiatedSwReporterScan( | |
| 84 base::Bind(&CleanupActionHandler::ReportScanResults, | |
| 85 base::Unretained(this), webui_callback_id)); | |
| 86 } | |
| 87 | |
| 88 void CleanupActionHandler::ReportScanResults(std::string callback_id) { | |
| 89 base::DictionaryValue scan_results; | |
| 90 // TODO(proberge): Return real information about the scan. | |
| 91 // TODO(proberge): Localize strings once they are finalized. | |
| 92 scan_results.SetBoolean("hasScanResults", true); | |
| 93 scan_results.SetBoolean("isInfected", true); | |
| 94 scan_results.SetString("detectionStatusText", | |
| 95 "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?
| |
| 96 scan_results.SetString("detectionTimeText", "Last scanned today"); | |
| 97 | |
| 98 AllowJavascript(); | |
| 99 ResolveJavascriptCallback(base::Value(callback_id), scan_results); | |
| 100 } | |
| OLD | NEW |