| 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" | |
| 9 #include "base/values.h" | 8 #include "base/values.h" |
| 10 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/component_updater/sw_reporter_installer_win.h" | 10 #include "chrome/browser/component_updater/sw_reporter_installer_win.h" |
| 11 #include "components/component_updater/component_updater_service.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 bool IsCleanupComponentRegistered() { | 15 bool IsCleanupComponentRegistered() { |
| 16 component_updater::ComponentUpdateService* cus = | 16 component_updater::ComponentUpdateService* cus = |
| 17 g_browser_process->component_updater(); | 17 g_browser_process->component_updater(); |
| 18 std::vector<std::string> component_ids = cus->GetComponentIDs(); | 18 std::vector<std::string> component_ids = cus->GetComponentIDs(); |
| 19 | 19 |
| 20 return std::find(component_ids.begin(), component_ids.end(), | 20 return std::find(component_ids.begin(), component_ids.end(), |
| 21 component_updater::kSwReporterComponentId) != | 21 component_updater::kSwReporterComponentId) != |
| 22 component_ids.end(); | 22 component_ids.end(); |
| 23 } | 23 } |
| 24 | 24 |
| 25 // TODO(proberge): Connect this to the Cleanup Tool manager class once that's |
| 26 // implemented. |
| 27 void StartScan(base::Closure callback) { |
| 28 callback.Run(); |
| 29 } |
| 30 |
| 31 // TODO(proberge): Connect this to the Cleanup Tool manager class once that's |
| 32 // implemented. |
| 33 void StartCleanup(base::Closure callback) { |
| 34 callback.Run(); |
| 35 } |
| 36 |
| 25 // TODO(proberge): Localize strings once they are finalized. | 37 // TODO(proberge): Localize strings once they are finalized. |
| 26 constexpr char kDetectionOkText[] = "No problems detected"; | 38 constexpr char kDetectionOkText[] = "No problems detected"; |
| 27 constexpr char kDetectionUwSText[] = "2 potentially harmful programs detected"; | 39 constexpr char kDetectionUwSText[] = "2 potentially harmful programs detected"; |
| 28 constexpr char kDetectionTimeText[] = "Last scanned today"; | 40 constexpr char kDetectionTimeText[] = "Last scanned today"; |
| 29 constexpr char kCleanupUnsupportedText[] = "Chrome Cleanup is not supported."; | 41 constexpr char kCleanupUnsupportedText[] = "Chrome Cleanup is not supported."; |
| 30 constexpr char kUnsupportedHelpText[] = "Please try reinstalling Chrome"; | 42 constexpr char kUnsupportedHelpText[] = "Please try reinstalling Chrome"; |
| 31 | 43 |
| 32 } // namespace | 44 } // namespace |
| 33 | 45 |
| 34 CleanupActionHandler::CleanupActionHandler() | 46 CleanupActionHandler::CleanupActionHandler() |
| 35 : callback_weak_ptr_factory_(this) {} | 47 : callback_weak_ptr_factory_(this) {} |
| 36 | 48 |
| 37 CleanupActionHandler::~CleanupActionHandler() {} | 49 CleanupActionHandler::~CleanupActionHandler() {} |
| 38 | 50 |
| 39 void CleanupActionHandler::RegisterMessages() { | 51 void CleanupActionHandler::RegisterMessages() { |
| 40 web_ui()->RegisterMessageCallback( | 52 web_ui()->RegisterMessageCallback( |
| 41 "requestLastScanResult", | 53 "requestLastScanResult", |
| 42 base::Bind(&CleanupActionHandler::HandleRequestLastScanResult, | 54 base::Bind(&CleanupActionHandler::HandleRequestLastScanResult, |
| 43 base::Unretained(this))); | 55 base::Unretained(this))); |
| 44 web_ui()->RegisterMessageCallback( | 56 web_ui()->RegisterMessageCallback( |
| 45 "startScan", base::Bind(&CleanupActionHandler::HandleStartScan, | 57 "startScan", base::Bind(&CleanupActionHandler::HandleStartScan, |
| 46 base::Unretained(this))); | 58 base::Unretained(this))); |
| 59 web_ui()->RegisterMessageCallback( |
| 60 "startCleanup", base::Bind(&CleanupActionHandler::HandleStartCleanup, |
| 61 base::Unretained(this))); |
| 47 } | 62 } |
| 48 | 63 |
| 49 void CleanupActionHandler::OnJavascriptDisallowed() { | 64 void CleanupActionHandler::OnJavascriptDisallowed() { |
| 50 callback_weak_ptr_factory_.InvalidateWeakPtrs(); | 65 callback_weak_ptr_factory_.InvalidateWeakPtrs(); |
| 51 } | 66 } |
| 52 | 67 |
| 53 void CleanupActionHandler::HandleRequestLastScanResult( | 68 void CleanupActionHandler::HandleRequestLastScanResult( |
| 54 const base::ListValue* args) { | 69 const base::ListValue* args) { |
| 70 CHECK_EQ(1U, args->GetSize()); |
| 55 std::string webui_callback_id; | 71 std::string webui_callback_id; |
| 56 CHECK_EQ(1U, args->GetSize()); | |
| 57 bool success = args->GetString(0, &webui_callback_id); | 72 bool success = args->GetString(0, &webui_callback_id); |
| 58 DCHECK(success); | 73 DCHECK(success); |
| 59 | 74 |
| 60 base::DictionaryValue last_scan_results; | 75 base::DictionaryValue last_scan_results; |
| 61 // TODO(proberge): Return real information about the last run. | 76 // TODO(proberge): Return real information about the last run. |
| 62 last_scan_results.SetBoolean("hasScanResults", false); | 77 last_scan_results.SetBoolean("hasScanResults", false); |
| 63 last_scan_results.SetBoolean("isInfected", false); | 78 last_scan_results.SetBoolean("isInfected", false); |
| 64 last_scan_results.SetString("detectionStatusText", kDetectionOkText); | 79 last_scan_results.SetString("detectionStatusText", kDetectionOkText); |
| 65 last_scan_results.SetString("detectionTimeText", kDetectionTimeText); | 80 last_scan_results.SetString("detectionTimeText", kDetectionTimeText); |
| 66 | 81 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 79 scan_results.SetBoolean("hasScanResults", false); | 94 scan_results.SetBoolean("hasScanResults", false); |
| 80 scan_results.SetBoolean("isInfected", false); | 95 scan_results.SetBoolean("isInfected", false); |
| 81 scan_results.SetString("detectionStatusText", kCleanupUnsupportedText); | 96 scan_results.SetString("detectionStatusText", kCleanupUnsupportedText); |
| 82 scan_results.SetString("detectionTimeText", kUnsupportedHelpText); | 97 scan_results.SetString("detectionTimeText", kUnsupportedHelpText); |
| 83 | 98 |
| 84 AllowJavascript(); | 99 AllowJavascript(); |
| 85 ResolveJavascriptCallback(base::Value(webui_callback_id), scan_results); | 100 ResolveJavascriptCallback(base::Value(webui_callback_id), scan_results); |
| 86 return; | 101 return; |
| 87 } | 102 } |
| 88 | 103 |
| 89 component_updater::RegisterUserInitiatedSwReporterScan( | 104 StartScan(base::Bind(&CleanupActionHandler::ReportScanResults, |
| 90 base::Bind(&CleanupActionHandler::ReportScanResults, | 105 callback_weak_ptr_factory_.GetWeakPtr(), |
| 91 callback_weak_ptr_factory_.GetWeakPtr(), webui_callback_id)); | 106 webui_callback_id)); |
| 92 } | 107 } |
| 93 | 108 |
| 94 void CleanupActionHandler::ReportScanResults(const std::string& callback_id) { | 109 void CleanupActionHandler::ReportScanResults(const std::string& callback_id) { |
| 95 base::DictionaryValue scan_results; | 110 base::DictionaryValue scan_results; |
| 96 // TODO(proberge): Return real information about the scan. | 111 // TODO(proberge): Return real information about the scan. |
| 97 scan_results.SetBoolean("hasScanResults", true); | 112 scan_results.SetBoolean("hasScanResults", true); |
| 98 scan_results.SetBoolean("isInfected", true); | 113 scan_results.SetBoolean("isInfected", true); |
| 99 scan_results.SetString("detectionStatusText", kDetectionUwSText); | 114 scan_results.SetString("detectionStatusText", kDetectionUwSText); |
| 100 scan_results.SetString("detectionTimeText", kDetectionTimeText); | 115 scan_results.SetString("detectionTimeText", kDetectionTimeText); |
| 101 | 116 |
| 102 AllowJavascript(); | 117 AllowJavascript(); |
| 103 ResolveJavascriptCallback(base::Value(callback_id), scan_results); | 118 ResolveJavascriptCallback(base::Value(callback_id), scan_results); |
| 104 } | 119 } |
| 120 |
| 121 void CleanupActionHandler::HandleStartCleanup(const base::ListValue* args) { |
| 122 CHECK_EQ(1U, args->GetSize()); |
| 123 std::string webui_callback_id; |
| 124 bool success = args->GetString(0, &webui_callback_id); |
| 125 DCHECK(success); |
| 126 |
| 127 StartCleanup(base::Bind(&CleanupActionHandler::ReportCleanupResults, |
| 128 base::Unretained(this), webui_callback_id)); |
| 129 } |
| 130 |
| 131 void CleanupActionHandler::ReportCleanupResults( |
| 132 const std::string& callback_id) { |
| 133 base::DictionaryValue cleanup_results; |
| 134 // TODO(proberge): Return real information about the cleanup. |
| 135 cleanup_results.SetBoolean("wasCancelled", true); |
| 136 cleanup_results.SetBoolean("requiresReboot", false); |
| 137 |
| 138 ResolveJavascriptCallback(base::Value(callback_id), cleanup_results); |
| 139 } |
| OLD | NEW |