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/safe_browsing/chrome_cleaner/chrome_cleaner_controller_
win.h" | 5 #include "chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_controller_
win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include "net/http/http_status_code.h" | 34 #include "net/http/http_status_code.h" |
35 | 35 |
36 namespace safe_browsing { | 36 namespace safe_browsing { |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 using ::chrome_cleaner::mojom::ChromePrompt; | 40 using ::chrome_cleaner::mojom::ChromePrompt; |
41 using ::chrome_cleaner::mojom::PromptAcceptance; | 41 using ::chrome_cleaner::mojom::PromptAcceptance; |
42 using ::content::BrowserThread; | 42 using ::content::BrowserThread; |
43 | 43 |
44 // Keeps track of whether GetInstance() has been called. | 44 // The global singleton instance. Exposed outside of GetInstance() so that it |
45 bool g_instance_exists = false; | 45 // can be reset by tests. |
| 46 ChromeCleanerController* g_controller = nullptr; |
46 | 47 |
47 // TODO(alito): Move these shared exit codes to the chrome_cleaner component. | 48 // TODO(alito): Move these shared exit codes to the chrome_cleaner component. |
48 // https://crbug.com/727956 | 49 // https://crbug.com/727956 |
49 constexpr int kRebootRequiredExitCode = 15; | 50 constexpr int kRebootRequiredExitCode = 15; |
50 constexpr int kRebootNotRequiredExitCode = 0; | 51 constexpr int kRebootNotRequiredExitCode = 0; |
51 | 52 |
52 // Attempts to change the Chrome Cleaner binary's suffix to ".exe". Will return | 53 // Attempts to change the Chrome Cleaner binary's suffix to ".exe". Will return |
53 // an empty FilePath on failure. Should be called on a sequence with traits | 54 // an empty FilePath on failure. Should be called on a sequence with traits |
54 // appropriate for IO operations. | 55 // appropriate for IO operations. |
55 base::FilePath VerifyAndRenameDownloadedCleaner( | 56 base::FilePath VerifyAndRenameDownloadedCleaner( |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 PostCleanupSettingsResetter().ResetTaggedProfiles( | 133 PostCleanupSettingsResetter().ResetTaggedProfiles( |
133 std::move(profiles), std::move(continuation), | 134 std::move(profiles), std::move(continuation), |
134 base::MakeUnique<PostCleanupSettingsResetter::Delegate>()); | 135 base::MakeUnique<PostCleanupSettingsResetter::Delegate>()); |
135 } | 136 } |
136 } | 137 } |
137 | 138 |
138 // static | 139 // static |
139 ChromeCleanerController* ChromeCleanerController::GetInstance() { | 140 ChromeCleanerController* ChromeCleanerController::GetInstance() { |
140 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 141 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
141 | 142 |
142 static ChromeCleanerController* const kInstance = | 143 if (!g_controller) |
143 new ChromeCleanerController(); | 144 g_controller = new ChromeCleanerController(); |
144 g_instance_exists = true; | 145 |
145 return kInstance; | 146 return g_controller; |
146 } | 147 } |
147 | 148 |
148 // static | 149 // static |
149 bool ChromeCleanerController::ShouldShowCleanupInSettingsUI() { | 150 bool ChromeCleanerController::ShouldShowCleanupInSettingsUI() { |
150 // Short-circuit if the instance doesn't exist to avoid creating it during | 151 // Short-circuit if the instance doesn't exist to avoid creating it during |
151 // navigation to chrome://settings. | 152 // navigation to chrome://settings. |
152 if (!g_instance_exists) | 153 if (!g_controller) |
153 return false; | 154 return false; |
154 | 155 |
155 State state = GetInstance()->state(); | 156 State state = GetInstance()->state(); |
156 return state == State::kInfected || state == State::kCleaning || | 157 return state == State::kInfected || state == State::kCleaning || |
157 state == State::kRebootRequired; | 158 state == State::kRebootRequired; |
158 } | 159 } |
159 | 160 |
| 161 void ChromeCleanerController::SetLogsEnabled(bool logs_enabled) { |
| 162 if (logs_enabled_ == logs_enabled) |
| 163 return; |
| 164 |
| 165 logs_enabled_ = logs_enabled; |
| 166 for (auto& observer : observer_list_) |
| 167 observer.OnLogsEnabledChanged(logs_enabled_); |
| 168 } |
| 169 |
160 void ChromeCleanerController::SetDelegateForTesting( | 170 void ChromeCleanerController::SetDelegateForTesting( |
161 ChromeCleanerControllerDelegate* delegate) { | 171 ChromeCleanerControllerDelegate* delegate) { |
162 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | 172 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
163 delegate_ = delegate ? delegate : real_delegate_.get(); | 173 delegate_ = delegate ? delegate : real_delegate_.get(); |
164 DCHECK(delegate_); | 174 DCHECK(delegate_); |
165 } | 175 } |
166 | 176 |
167 void ChromeCleanerController::DismissRebootForTesting() { | 177 // static |
168 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | 178 void ChromeCleanerController::ResetInstanceForTesting() { |
169 DCHECK_EQ(State::kRebootRequired, state()); | 179 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
170 state_ = State::kIdle; | 180 |
| 181 if (g_controller) { |
| 182 delete g_controller; |
| 183 g_controller = nullptr; |
| 184 } |
171 } | 185 } |
172 | 186 |
173 void ChromeCleanerController::AddObserver(Observer* observer) { | 187 void ChromeCleanerController::AddObserver(Observer* observer) { |
174 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | 188 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
175 observer_list_.AddObserver(observer); | 189 observer_list_.AddObserver(observer); |
176 NotifyObserver(observer); | 190 NotifyObserver(observer); |
177 } | 191 } |
178 | 192 |
179 void ChromeCleanerController::RemoveObserver(Observer* observer) { | 193 void ChromeCleanerController::RemoveObserver(Observer* observer) { |
180 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | 194 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
(...skipping 26 matching lines...) Expand all Loading... |
207 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | 221 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
208 | 222 |
209 if (state() != State::kInfected) | 223 if (state() != State::kInfected) |
210 return; | 224 return; |
211 | 225 |
212 DCHECK(prompt_user_callback_); | 226 DCHECK(prompt_user_callback_); |
213 | 227 |
214 PromptAcceptance acceptance = PromptAcceptance::DENIED; | 228 PromptAcceptance acceptance = PromptAcceptance::DENIED; |
215 State new_state = State::kIdle; | 229 State new_state = State::kIdle; |
216 switch (user_response) { | 230 switch (user_response) { |
217 case UserResponse::kAccepted: | 231 case UserResponse::kAcceptedWithLogs: |
218 acceptance = PromptAcceptance::ACCEPTED; | 232 acceptance = PromptAcceptance::ACCEPTED_WITH_LOGS; |
| 233 SetLogsEnabled(true); |
219 new_state = State::kCleaning; | 234 new_state = State::kCleaning; |
220 delegate_->TagForResetting(profile); | 235 delegate_->TagForResetting(profile); |
221 break; | 236 break; |
| 237 case UserResponse::kAcceptedWithoutLogs: |
| 238 acceptance = PromptAcceptance::ACCEPTED_WITHOUT_LOGS; |
| 239 SetLogsEnabled(false); |
| 240 new_state = State::kCleaning; |
| 241 delegate_->TagForResetting(profile); |
| 242 break; |
222 case UserResponse::kDenied: // Fallthrough | 243 case UserResponse::kDenied: // Fallthrough |
223 case UserResponse::kDismissed: | 244 case UserResponse::kDismissed: |
224 acceptance = PromptAcceptance::DENIED; | 245 acceptance = PromptAcceptance::DENIED; |
225 idle_reason_ = IdleReason::kUserDeclinedCleanup; | 246 idle_reason_ = IdleReason::kUserDeclinedCleanup; |
226 new_state = State::kIdle; | 247 new_state = State::kIdle; |
227 break; | 248 break; |
228 } | 249 } |
229 | 250 |
230 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO) | 251 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO) |
231 ->PostTask(FROM_HERE, | 252 ->PostTask(FROM_HERE, |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 observer.OnRebootFailed(); | 470 observer.OnRebootFailed(); |
450 } | 471 } |
451 } | 472 } |
452 | 473 |
453 void ChromeCleanerController::OnSettingsResetCompleted() { | 474 void ChromeCleanerController::OnSettingsResetCompleted() { |
454 idle_reason_ = IdleReason::kCleaningSucceeded; | 475 idle_reason_ = IdleReason::kCleaningSucceeded; |
455 SetStateAndNotifyObservers(State::kIdle); | 476 SetStateAndNotifyObservers(State::kIdle); |
456 } | 477 } |
457 | 478 |
458 } // namespace safe_browsing | 479 } // namespace safe_browsing |
OLD | NEW |