| 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 #ifndef CHROME_BROWSER_SAFE_BROWSING_CHROME_CLEANER_CHROME_CLEANER_CONTROLLER_WI
N_H_ | 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_CHROME_CLEANER_CHROME_CLEANER_CONTROLLER_WI
N_H_ |
| 6 #define CHROME_BROWSER_SAFE_BROWSING_CHROME_CLEANER_CHROME_CLEANER_CONTROLLER_WI
N_H_ | 6 #define CHROME_BROWSER_SAFE_BROWSING_CHROME_CLEANER_CHROME_CLEANER_CONTROLLER_WI
N_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> |
| 10 | 11 |
| 12 #include "base/callback.h" |
| 11 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 12 #include "base/macros.h" | 14 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 14 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
| 15 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
| 16 #include "chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_runner_win.
h" | 18 #include "chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_runner_win.
h" |
| 17 #include "chrome/browser/safe_browsing/chrome_cleaner/reporter_runner_win.h" | 19 #include "chrome/browser/safe_browsing/chrome_cleaner/reporter_runner_win.h" |
| 18 #include "components/chrome_cleaner/public/interfaces/chrome_prompt.mojom.h" | 20 #include "components/chrome_cleaner/public/interfaces/chrome_prompt.mojom.h" |
| 19 | 21 |
| 22 class Profile; |
| 23 |
| 20 namespace base { | 24 namespace base { |
| 21 template <typename T> | 25 template <typename T> |
| 22 struct DefaultSingletonTraits; | 26 struct DefaultSingletonTraits; |
| 23 } | 27 } |
| 24 | 28 |
| 25 namespace safe_browsing { | 29 namespace safe_browsing { |
| 26 | 30 |
| 27 // Delegate class that provides services to the ChromeCleanerController class | 31 // Delegate class that provides services to the ChromeCleanerController class |
| 28 // and can be overridden by tests via | 32 // and can be overridden by tests via |
| 29 // SetChromeCleanerControllerDelegateForTesting(). | 33 // SetChromeCleanerControllerDelegateForTesting(). |
| 30 class ChromeCleanerControllerDelegate { | 34 class ChromeCleanerControllerDelegate { |
| 31 public: | 35 public: |
| 32 using FetchedCallback = base::OnceCallback<void(base::FilePath)>; | 36 using FetchedCallback = base::OnceCallback<void(base::FilePath)>; |
| 33 | 37 |
| 34 ChromeCleanerControllerDelegate(); | 38 ChromeCleanerControllerDelegate(); |
| 35 virtual ~ChromeCleanerControllerDelegate(); | 39 virtual ~ChromeCleanerControllerDelegate(); |
| 36 | 40 |
| 37 // Fetches and verifies the Chrome Cleaner binary and passes the name of the | 41 // Fetches and verifies the Chrome Cleaner binary and passes the name of the |
| 38 // executable to |fetched_callback|. The file name will have the ".exe" | 42 // executable to |fetched_callback|. The file name will have the ".exe" |
| 39 // extension. If the operation fails, the file name passed to | 43 // extension. If the operation fails, the file name passed to |
| 40 // |fecthed_callback| will be empty. | 44 // |fecthed_callback| will be empty. |
| 41 virtual void FetchAndVerifyChromeCleaner(FetchedCallback fetched_callback); | 45 virtual void FetchAndVerifyChromeCleaner(FetchedCallback fetched_callback); |
| 42 virtual bool SafeBrowsingExtendedReportingScoutEnabled(); | 46 virtual bool SafeBrowsingExtendedReportingScoutEnabled(); |
| 43 virtual bool IsMetricsAndCrashReportingEnabled(); | 47 virtual bool IsMetricsAndCrashReportingEnabled(); |
| 48 |
| 49 // Auxiliary methods for tagging and resetting open profiles. |
| 50 virtual void InvokeTagProfileForResetting(Profile* profile); |
| 51 virtual void InvokeResetPostCleanupSettingsIfTagged( |
| 52 std::vector<Profile*> profiles, |
| 53 base::OnceClosure continuation); |
| 44 }; | 54 }; |
| 45 | 55 |
| 46 // Controller class that keeps track of the execution of the Chrome Cleaner and | 56 // Controller class that keeps track of the execution of the Chrome Cleaner and |
| 47 // the various states through which the execution will transition. Observers can | 57 // the various states through which the execution will transition. Observers can |
| 48 // register themselves to be notified of state changes. Intended to be used by | 58 // register themselves to be notified of state changes. Intended to be used by |
| 49 // the Chrome Cleaner webui page and the Chrome Cleaner prompt dialog. | 59 // the Chrome Cleaner webui page and the Chrome Cleaner prompt dialog. |
| 50 // | 60 // |
| 51 // This class lives on, and all its members should be called only on, the UI | 61 // This class lives on, and all its members should be called only on, the UI |
| 52 // thread. | 62 // thread. |
| 53 class ChromeCleanerController { | 63 class ChromeCleanerController { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 // which found possible harmful software on the system. | 141 // which found possible harmful software on the system. |
| 132 // | 142 // |
| 133 // A call to Scan() will be a no-op if the controller is not in the kIdle | 143 // A call to Scan() will be a no-op if the controller is not in the kIdle |
| 134 // state. This gracefully handles cases where multiple user responses are | 144 // state. This gracefully handles cases where multiple user responses are |
| 135 // received, for example if a user manages to click on a "Scan" button | 145 // received, for example if a user manages to click on a "Scan" button |
| 136 // multiple times. | 146 // multiple times. |
| 137 void Scan(const SwReporterInvocation& reporter_invocation); | 147 void Scan(const SwReporterInvocation& reporter_invocation); |
| 138 | 148 |
| 139 // Sends the user's response, as to whether or not they want the Chrome | 149 // Sends the user's response, as to whether or not they want the Chrome |
| 140 // Cleaner to remove harmful software that was found, to the Chrome Cleaner | 150 // Cleaner to remove harmful software that was found, to the Chrome Cleaner |
| 141 // process. | 151 // process. If the user accepted the prompt, then tags |profile| for |
| 152 // post-cleanup settings reset. |
| 142 // | 153 // |
| 143 // A call to ReplyWithUserResponse() will be a no-op if the controller is not | 154 // A call to ReplyWithUserResponse() will be a no-op if the controller is not |
| 144 // in the kInfected state. This gracefully handles cases where multiple user | 155 // in the kInfected state. This gracefully handles cases where multiple user |
| 145 // responses are received, for example if a user manages to click on a | 156 // responses are received, for example if a user manages to click on a |
| 146 // "Cleanup" button multiple times. | 157 // "Cleanup" button multiple times. |
| 147 void ReplyWithUserResponse(UserResponse user_response); | 158 void ReplyWithUserResponse(Profile* profile, UserResponse user_response); |
| 148 | 159 |
| 149 // Passing in a nullptr as |delegate| resets the delegate to a default | 160 // Passing in a nullptr as |delegate| resets the delegate to a default |
| 150 // production version. | 161 // production version. |
| 151 void SetDelegateForTesting(ChromeCleanerControllerDelegate* delegate); | 162 void SetDelegateForTesting(ChromeCleanerControllerDelegate* delegate); |
| 152 void DismissRebootForTesting(); | 163 void DismissRebootForTesting(); |
| 153 | 164 |
| 154 private: | 165 private: |
| 155 friend struct base::DefaultSingletonTraits<ChromeCleanerController>; | 166 friend struct base::DefaultSingletonTraits<ChromeCleanerController>; |
| 156 | 167 |
| 157 ChromeCleanerController(); | 168 ChromeCleanerController(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 181 std::unique_ptr<std::set<base::FilePath>> files_to_delete, | 192 std::unique_ptr<std::set<base::FilePath>> files_to_delete, |
| 182 chrome_cleaner::mojom::ChromePrompt::PromptUserCallback | 193 chrome_cleaner::mojom::ChromePrompt::PromptUserCallback |
| 183 prompt_user_callback); | 194 prompt_user_callback); |
| 184 | 195 |
| 185 void OnPromptUser(std::unique_ptr<std::set<base::FilePath>> files_to_delete, | 196 void OnPromptUser(std::unique_ptr<std::set<base::FilePath>> files_to_delete, |
| 186 chrome_cleaner::mojom::ChromePrompt::PromptUserCallback | 197 chrome_cleaner::mojom::ChromePrompt::PromptUserCallback |
| 187 prompt_user_callback); | 198 prompt_user_callback); |
| 188 void OnConnectionClosed(); | 199 void OnConnectionClosed(); |
| 189 void OnCleanerProcessDone(ChromeCleanerRunner::ProcessStatus process_status); | 200 void OnCleanerProcessDone(ChromeCleanerRunner::ProcessStatus process_status); |
| 190 | 201 |
| 202 // Invoked once settings reset is done for tagged profiles. |
| 203 void OnSettingsResetCompleted(); |
| 204 |
| 191 std::unique_ptr<ChromeCleanerControllerDelegate> real_delegate_; | 205 std::unique_ptr<ChromeCleanerControllerDelegate> real_delegate_; |
| 192 // Pointer to either real_delegate_ or one set by tests. | 206 // Pointer to either real_delegate_ or one set by tests. |
| 193 ChromeCleanerControllerDelegate* delegate_; | 207 ChromeCleanerControllerDelegate* delegate_; |
| 194 | 208 |
| 195 State state_ = State::kIdle; | 209 State state_ = State::kIdle; |
| 196 IdleReason idle_reason_ = IdleReason::kInitial; | 210 IdleReason idle_reason_ = IdleReason::kInitial; |
| 197 std::unique_ptr<SwReporterInvocation> reporter_invocation_; | 211 std::unique_ptr<SwReporterInvocation> reporter_invocation_; |
| 198 std::unique_ptr<std::set<base::FilePath>> files_to_delete_; | 212 std::unique_ptr<std::set<base::FilePath>> files_to_delete_; |
| 199 // The Mojo callback that should be called to send a response to the Chrome | 213 // The Mojo callback that should be called to send a response to the Chrome |
| 200 // Cleaner process. This must be posted to run on the IO thread. | 214 // Cleaner process. This must be posted to run on the IO thread. |
| 201 chrome_cleaner::mojom::ChromePrompt::PromptUserCallback prompt_user_callback_; | 215 chrome_cleaner::mojom::ChromePrompt::PromptUserCallback prompt_user_callback_; |
| 202 | 216 |
| 203 base::ObserverList<Observer> observer_list_; | 217 base::ObserverList<Observer> observer_list_; |
| 204 | 218 |
| 205 THREAD_CHECKER(thread_checker_); | 219 THREAD_CHECKER(thread_checker_); |
| 206 | 220 |
| 207 base::WeakPtrFactory<ChromeCleanerController> weak_factory_; | 221 base::WeakPtrFactory<ChromeCleanerController> weak_factory_; |
| 208 | 222 |
| 209 DISALLOW_COPY_AND_ASSIGN(ChromeCleanerController); | 223 DISALLOW_COPY_AND_ASSIGN(ChromeCleanerController); |
| 210 }; | 224 }; |
| 211 | 225 |
| 212 } // namespace safe_browsing | 226 } // namespace safe_browsing |
| 213 | 227 |
| 214 #endif // CHROME_BROWSER_SAFE_BROWSING_CHROME_CLEANER_CHROME_CLEANER_CONTROLLER
_WIN_H_ | 228 #endif // CHROME_BROWSER_SAFE_BROWSING_CHROME_CLEANER_CHROME_CLEANER_CONTROLLER
_WIN_H_ |
| OLD | NEW |