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 #include <vector> |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 kInitial, | 84 kInitial, |
85 kScanningFoundNothing, | 85 kScanningFoundNothing, |
86 kScanningFailed, | 86 kScanningFailed, |
87 kConnectionLost, | 87 kConnectionLost, |
88 kUserDeclinedCleanup, | 88 kUserDeclinedCleanup, |
89 kCleaningFailed, | 89 kCleaningFailed, |
90 kCleaningSucceeded, | 90 kCleaningSucceeded, |
91 }; | 91 }; |
92 | 92 |
93 enum class UserResponse { | 93 enum class UserResponse { |
94 // User accepted the cleanup operation. | 94 // User accepted the cleanup operation and logs upload is enabled. |
95 kAccepted, | 95 kAcceptedWithLogs, |
| 96 // User accepted the cleanup operation and logs upload is not enabled. |
| 97 kAcceptedWithoutLogs, |
96 // User explicitly denied the cleanup operation, for example by clicking the | 98 // User explicitly denied the cleanup operation, for example by clicking the |
97 // Cleaner dialog's cancel button. | 99 // Cleaner dialog's cancel button. |
98 kDenied, | 100 kDenied, |
99 // The cleanup operation was denied when the user dismissed the Cleaner | 101 // The cleanup operation was denied when the user dismissed the Cleaner |
100 // dialog, for example by pressing the ESC key. | 102 // dialog, for example by pressing the ESC key. |
101 kDismissed, | 103 kDismissed, |
102 }; | 104 }; |
103 | 105 |
104 class Observer { | 106 class Observer { |
105 public: | 107 public: |
106 virtual void OnIdle(IdleReason idle_reason) {} | 108 virtual void OnIdle(IdleReason idle_reason) {} |
107 virtual void OnScanning() {} | 109 virtual void OnScanning() {} |
108 virtual void OnInfected(const std::set<base::FilePath>& files_to_delete) {} | 110 virtual void OnInfected(const std::set<base::FilePath>& files_to_delete) {} |
109 virtual void OnCleaning(const std::set<base::FilePath>& files_to_delete) {} | 111 virtual void OnCleaning(const std::set<base::FilePath>& files_to_delete) {} |
110 virtual void OnRebootRequired() {} | 112 virtual void OnRebootRequired() {} |
111 virtual void OnRebootFailed() {} | 113 virtual void OnRebootFailed() {} |
| 114 virtual void OnLogsEnabledChanged(bool logs_enabled) {} |
112 | 115 |
113 protected: | 116 protected: |
114 virtual ~Observer() = default; | 117 virtual ~Observer() = default; |
115 }; | 118 }; |
116 | 119 |
117 // Returns the global controller object. | 120 // Returns the global controller object. |
118 static ChromeCleanerController* GetInstance(); | 121 static ChromeCleanerController* GetInstance(); |
119 | 122 |
120 // Returns whether the Cleanup card in settings should be displayed. | 123 // Returns whether the Cleanup card in settings should be displayed. |
121 // Static to prevent instantiation of the global controller object. | 124 // Static to prevent instantiation of the global controller object. |
122 static bool ShouldShowCleanupInSettingsUI(); | 125 static bool ShouldShowCleanupInSettingsUI(); |
123 | 126 |
124 State state() const { return state_; } | 127 State state() const { return state_; } |
125 | 128 |
| 129 // Called by Chrome Cleaner's UI when the user changes Cleaner logs upload |
| 130 // permissions. Observers are notified if |logs_enabled| is different from the |
| 131 // current permission state. |
| 132 void SetLogsEnabled(bool logs_enabled); |
| 133 bool logs_enabled() const { return logs_enabled_; } |
| 134 |
126 // |AddObserver()| immediately notifies |observer| of the controller's state | 135 // |AddObserver()| immediately notifies |observer| of the controller's state |
127 // by calling the corresponding |On*()| function. | 136 // by calling the corresponding |On*()| function. |
128 void AddObserver(Observer* observer); | 137 void AddObserver(Observer* observer); |
129 void RemoveObserver(Observer* observer); | 138 void RemoveObserver(Observer* observer); |
130 | 139 |
131 // Downloads the Chrome Cleaner binary, executes it and waits for the Cleaner | 140 // Downloads the Chrome Cleaner binary, executes it and waits for the Cleaner |
132 // to communicate with Chrome about harmful software found on the | 141 // to communicate with Chrome about harmful software found on the |
133 // system. During this time, the controller will be in the kScanning state. If | 142 // system. During this time, the controller will be in the kScanning state. If |
134 // any of the steps fail or if the Cleaner does not find harmful software on | 143 // any of the steps fail or if the Cleaner does not find harmful software on |
135 // the system, the controller will transition to the kIdle state, passing to | 144 // the system, the controller will transition to the kIdle state, passing to |
(...skipping 24 matching lines...) Expand all Loading... |
160 // the computer. Call this after obtaining permission from the user to | 169 // the computer. Call this after obtaining permission from the user to |
161 // reboot. | 170 // reboot. |
162 // | 171 // |
163 // If initiating the reboot fails, observers will be notified via a call to | 172 // If initiating the reboot fails, observers will be notified via a call to |
164 // OnRebootFailed(). | 173 // OnRebootFailed(). |
165 // | 174 // |
166 // Note that there are no guarantees that the reboot will in fact happen even | 175 // Note that there are no guarantees that the reboot will in fact happen even |
167 // if the system calls to initiate a reboot return success. | 176 // if the system calls to initiate a reboot return success. |
168 void Reboot(); | 177 void Reboot(); |
169 | 178 |
| 179 static void ResetInstanceForTesting(); |
170 // Passing in a nullptr as |delegate| resets the delegate to a default | 180 // Passing in a nullptr as |delegate| resets the delegate to a default |
171 // production version. | 181 // production version. |
172 void SetDelegateForTesting(ChromeCleanerControllerDelegate* delegate); | 182 void SetDelegateForTesting(ChromeCleanerControllerDelegate* delegate); |
173 void DismissRebootForTesting(); | |
174 | 183 |
175 private: | 184 private: |
176 ChromeCleanerController(); | 185 ChromeCleanerController(); |
177 ~ChromeCleanerController(); | 186 ~ChromeCleanerController(); |
178 | 187 |
179 void NotifyObserver(Observer* observer) const; | 188 void NotifyObserver(Observer* observer) const; |
180 void SetStateAndNotifyObservers(State state); | 189 void SetStateAndNotifyObservers(State state); |
181 // Used to invalidate weak pointers and reset accumulated data that is no | 190 // Used to invalidate weak pointers and reset accumulated data that is no |
182 // longer needed when entering the kIdle or kRebootRequired states. | 191 // longer needed when entering the kIdle or kRebootRequired states. |
183 void ResetCleanerDataAndInvalidateWeakPtrs(); | 192 void ResetCleanerDataAndInvalidateWeakPtrs(); |
(...skipping 25 matching lines...) Expand all Loading... |
209 void InitiateReboot(); | 218 void InitiateReboot(); |
210 | 219 |
211 // Invoked once settings reset is done for tagged profiles. | 220 // Invoked once settings reset is done for tagged profiles. |
212 void OnSettingsResetCompleted(); | 221 void OnSettingsResetCompleted(); |
213 | 222 |
214 std::unique_ptr<ChromeCleanerControllerDelegate> real_delegate_; | 223 std::unique_ptr<ChromeCleanerControllerDelegate> real_delegate_; |
215 // Pointer to either real_delegate_ or one set by tests. | 224 // Pointer to either real_delegate_ or one set by tests. |
216 ChromeCleanerControllerDelegate* delegate_; | 225 ChromeCleanerControllerDelegate* delegate_; |
217 | 226 |
218 State state_ = State::kIdle; | 227 State state_ = State::kIdle; |
| 228 // The logs permission checkboxes in the Chrome Cleaner dialog and webui page |
| 229 // are opt out. |
| 230 bool logs_enabled_ = true; |
219 IdleReason idle_reason_ = IdleReason::kInitial; | 231 IdleReason idle_reason_ = IdleReason::kInitial; |
220 std::unique_ptr<SwReporterInvocation> reporter_invocation_; | 232 std::unique_ptr<SwReporterInvocation> reporter_invocation_; |
221 std::unique_ptr<std::set<base::FilePath>> files_to_delete_; | 233 std::unique_ptr<std::set<base::FilePath>> files_to_delete_; |
222 // The Mojo callback that should be called to send a response to the Chrome | 234 // The Mojo callback that should be called to send a response to the Chrome |
223 // Cleaner process. This must be posted to run on the IO thread. | 235 // Cleaner process. This must be posted to run on the IO thread. |
224 chrome_cleaner::mojom::ChromePrompt::PromptUserCallback prompt_user_callback_; | 236 chrome_cleaner::mojom::ChromePrompt::PromptUserCallback prompt_user_callback_; |
225 | 237 |
226 base::ObserverList<Observer> observer_list_; | 238 base::ObserverList<Observer> observer_list_; |
227 | 239 |
228 THREAD_CHECKER(thread_checker_); | 240 THREAD_CHECKER(thread_checker_); |
229 | 241 |
230 base::WeakPtrFactory<ChromeCleanerController> weak_factory_; | 242 base::WeakPtrFactory<ChromeCleanerController> weak_factory_; |
231 | 243 |
232 DISALLOW_COPY_AND_ASSIGN(ChromeCleanerController); | 244 DISALLOW_COPY_AND_ASSIGN(ChromeCleanerController); |
233 }; | 245 }; |
234 | 246 |
235 } // namespace safe_browsing | 247 } // namespace safe_browsing |
236 | 248 |
237 #endif // CHROME_BROWSER_SAFE_BROWSING_CHROME_CLEANER_CHROME_CLEANER_CONTROLLER
_WIN_H_ | 249 #endif // CHROME_BROWSER_SAFE_BROWSING_CHROME_CLEANER_CHROME_CLEANER_CONTROLLER
_WIN_H_ |
OLD | NEW |