| 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 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 15 #include "base/location.h" | 15 #include "base/location.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 18 #include "base/metrics/histogram_macros.h" |
| 18 #include "base/task_scheduler/post_task.h" | 19 #include "base/task_scheduler/post_task.h" |
| 19 #include "base/task_scheduler/task_traits.h" | 20 #include "base/task_scheduler/task_traits.h" |
| 20 #include "base/threading/thread_restrictions.h" | 21 #include "base/threading/thread_restrictions.h" |
| 21 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
| 22 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
| 23 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | 24 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/profiles/profile_manager.h" | 26 #include "chrome/browser/profiles/profile_manager.h" |
| 26 #include "chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_fetcher_win
.h" | 27 #include "chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_fetcher_win
.h" |
| 27 #include "chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_runner_win.
h" | 28 #include "chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_runner_win.
h" |
| 28 #include "chrome/browser/safe_browsing/chrome_cleaner/settings_resetter_win.h" | 29 #include "chrome/browser/safe_browsing/chrome_cleaner/settings_resetter_win.h" |
| 29 #include "chrome/browser/safe_browsing/chrome_cleaner/srt_client_info_win.h" | 30 #include "chrome/browser/safe_browsing/chrome_cleaner/srt_client_info_win.h" |
| 31 #include "chrome/browser/safe_browsing/chrome_cleaner/srt_field_trial_win.h" |
| 30 #include "chrome/installer/util/scoped_token_privilege.h" | 32 #include "chrome/installer/util/scoped_token_privilege.h" |
| 31 #include "components/chrome_cleaner/public/constants/constants.h" | 33 #include "components/chrome_cleaner/public/constants/constants.h" |
| 32 #include "components/safe_browsing/common/safe_browsing_prefs.h" | 34 #include "components/safe_browsing/common/safe_browsing_prefs.h" |
| 33 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
| 34 #include "net/http/http_status_code.h" | 36 #include "net/http/http_status_code.h" |
| 35 | 37 |
| 36 namespace safe_browsing { | 38 namespace safe_browsing { |
| 37 | 39 |
| 38 namespace { | 40 namespace { |
| 39 | 41 |
| 40 using ::chrome_cleaner::mojom::ChromePrompt; | 42 using ::chrome_cleaner::mojom::ChromePrompt; |
| 41 using ::chrome_cleaner::mojom::PromptAcceptance; | 43 using ::chrome_cleaner::mojom::PromptAcceptance; |
| 42 using ::content::BrowserThread; | 44 using ::content::BrowserThread; |
| 43 | 45 |
| 44 // The global singleton instance. Exposed outside of GetInstance() so that it | 46 // The global singleton instance. Exposed outside of GetInstance() so that it |
| 45 // can be reset by tests. | 47 // can be reset by tests. |
| 46 ChromeCleanerController* g_controller = nullptr; | 48 ChromeCleanerController* g_controller = nullptr; |
| 47 | 49 |
| 48 // TODO(alito): Move these shared exit codes to the chrome_cleaner component. | 50 // TODO(alito): Move these shared exit codes to the chrome_cleaner component. |
| 49 // https://crbug.com/727956 | 51 // https://crbug.com/727956 |
| 50 constexpr int kRebootRequiredExitCode = 15; | 52 constexpr int kRebootRequiredExitCode = 15; |
| 51 constexpr int kRebootNotRequiredExitCode = 0; | 53 constexpr int kRebootNotRequiredExitCode = 0; |
| 52 | 54 |
| 55 // These values are used to send UMA information and are replicated in the |
| 56 // histograms.xml file, so the order MUST NOT CHANGE. |
| 57 enum CleanupResultHistogramValue { |
| 58 CLEANUP_RESULT_SUCCEEDED = 0, |
| 59 CLEANUP_RESULT_REBOOT_REQUIRED = 1, |
| 60 CLEANUP_RESULT_FAILED = 2, |
| 61 |
| 62 CLEANUP_RESULT_MAX, |
| 63 }; |
| 64 |
| 65 enum RebootResponseHistogramValue { |
| 66 REBOOT_RESPONSE_INITIATED = 0, |
| 67 |
| 68 REBOOT_RESPONSE_MAX, |
| 69 }; |
| 70 |
| 53 // Attempts to change the Chrome Cleaner binary's suffix to ".exe". Will return | 71 // Attempts to change the Chrome Cleaner binary's suffix to ".exe". Will return |
| 54 // an empty FilePath on failure. Should be called on a sequence with traits | 72 // an empty FilePath on failure. Should be called on a sequence with traits |
| 55 // appropriate for IO operations. | 73 // appropriate for IO operations. |
| 56 base::FilePath VerifyAndRenameDownloadedCleaner( | 74 base::FilePath VerifyAndRenameDownloadedCleaner( |
| 57 base::FilePath downloaded_path, | 75 base::FilePath downloaded_path, |
| 58 ChromeCleanerFetchStatus fetch_status) { | 76 ChromeCleanerFetchStatus fetch_status) { |
| 59 base::ThreadRestrictions::AssertIOAllowed(); | 77 base::ThreadRestrictions::AssertIOAllowed(); |
| 60 | 78 |
| 61 if (downloaded_path.empty() || !base::PathExists(downloaded_path)) | 79 if (downloaded_path.empty() || !base::PathExists(downloaded_path)) |
| 62 return base::FilePath(); | 80 return base::FilePath(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 93 ChromeCleanerController::IdleReason IdleReasonWhenConnectionClosedTooSoon( | 111 ChromeCleanerController::IdleReason IdleReasonWhenConnectionClosedTooSoon( |
| 94 ChromeCleanerController::State current_state) { | 112 ChromeCleanerController::State current_state) { |
| 95 DCHECK(current_state == ChromeCleanerController::State::kScanning || | 113 DCHECK(current_state == ChromeCleanerController::State::kScanning || |
| 96 current_state == ChromeCleanerController::State::kInfected); | 114 current_state == ChromeCleanerController::State::kInfected); |
| 97 | 115 |
| 98 return current_state == ChromeCleanerController::State::kScanning | 116 return current_state == ChromeCleanerController::State::kScanning |
| 99 ? ChromeCleanerController::IdleReason::kScanningFailed | 117 ? ChromeCleanerController::IdleReason::kScanningFailed |
| 100 : ChromeCleanerController::IdleReason::kConnectionLost; | 118 : ChromeCleanerController::IdleReason::kConnectionLost; |
| 101 } | 119 } |
| 102 | 120 |
| 121 void RecordCleanerLogsAcceptanceHistogram(bool logs_accepted) { |
| 122 UMA_HISTOGRAM_BOOLEAN("SoftwareReporter.CleanerLogsAcceptance", |
| 123 logs_accepted); |
| 124 } |
| 125 |
| 126 void RecordCleanupResultHistogram(CleanupResultHistogramValue result) { |
| 127 UMA_HISTOGRAM_ENUMERATION("SoftwareReporter.Cleaner.CleanupResult", result, |
| 128 CLEANUP_RESULT_MAX); |
| 129 } |
| 130 |
| 103 } // namespace | 131 } // namespace |
| 104 | 132 |
| 133 void RecordCleanupStartedHistogram(CleanupStartedHistogramValue value) { |
| 134 UMA_HISTOGRAM_ENUMERATION("SoftwareReporter.CleanupStarted", value, |
| 135 CLEANUP_STARTED_MAX); |
| 136 } |
| 137 |
| 105 ChromeCleanerControllerDelegate::ChromeCleanerControllerDelegate() = default; | 138 ChromeCleanerControllerDelegate::ChromeCleanerControllerDelegate() = default; |
| 106 | 139 |
| 107 ChromeCleanerControllerDelegate::~ChromeCleanerControllerDelegate() = default; | 140 ChromeCleanerControllerDelegate::~ChromeCleanerControllerDelegate() = default; |
| 108 | 141 |
| 109 void ChromeCleanerControllerDelegate::FetchAndVerifyChromeCleaner( | 142 void ChromeCleanerControllerDelegate::FetchAndVerifyChromeCleaner( |
| 110 FetchedCallback fetched_callback) { | 143 FetchedCallback fetched_callback) { |
| 111 FetchChromeCleaner( | 144 FetchChromeCleaner( |
| 112 base::BindOnce(&OnChromeCleanerFetched, base::Passed(&fetched_callback))); | 145 base::BindOnce(&OnChromeCleanerFetched, base::Passed(&fetched_callback))); |
| 113 } | 146 } |
| 114 | 147 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 return; | 257 return; |
| 225 | 258 |
| 226 DCHECK(prompt_user_callback_); | 259 DCHECK(prompt_user_callback_); |
| 227 | 260 |
| 228 PromptAcceptance acceptance = PromptAcceptance::DENIED; | 261 PromptAcceptance acceptance = PromptAcceptance::DENIED; |
| 229 State new_state = State::kIdle; | 262 State new_state = State::kIdle; |
| 230 switch (user_response) { | 263 switch (user_response) { |
| 231 case UserResponse::kAcceptedWithLogs: | 264 case UserResponse::kAcceptedWithLogs: |
| 232 acceptance = PromptAcceptance::ACCEPTED_WITH_LOGS; | 265 acceptance = PromptAcceptance::ACCEPTED_WITH_LOGS; |
| 233 SetLogsEnabled(true); | 266 SetLogsEnabled(true); |
| 267 RecordCleanerLogsAcceptanceHistogram(true); |
| 234 new_state = State::kCleaning; | 268 new_state = State::kCleaning; |
| 235 delegate_->TagForResetting(profile); | 269 delegate_->TagForResetting(profile); |
| 236 break; | 270 break; |
| 237 case UserResponse::kAcceptedWithoutLogs: | 271 case UserResponse::kAcceptedWithoutLogs: |
| 238 acceptance = PromptAcceptance::ACCEPTED_WITHOUT_LOGS; | 272 acceptance = PromptAcceptance::ACCEPTED_WITHOUT_LOGS; |
| 239 SetLogsEnabled(false); | 273 SetLogsEnabled(false); |
| 274 RecordCleanerLogsAcceptanceHistogram(false); |
| 240 new_state = State::kCleaning; | 275 new_state = State::kCleaning; |
| 241 delegate_->TagForResetting(profile); | 276 delegate_->TagForResetting(profile); |
| 242 break; | 277 break; |
| 243 case UserResponse::kDenied: // Fallthrough | 278 case UserResponse::kDenied: // Fallthrough |
| 244 case UserResponse::kDismissed: | 279 case UserResponse::kDismissed: |
| 245 acceptance = PromptAcceptance::DENIED; | 280 acceptance = PromptAcceptance::DENIED; |
| 246 idle_reason_ = IdleReason::kUserDeclinedCleanup; | 281 idle_reason_ = IdleReason::kUserDeclinedCleanup; |
| 247 new_state = State::kIdle; | 282 new_state = State::kIdle; |
| 248 break; | 283 break; |
| 249 } | 284 } |
| 250 | 285 |
| 251 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO) | 286 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO) |
| 252 ->PostTask(FROM_HERE, | 287 ->PostTask(FROM_HERE, |
| 253 base::BindOnce(std::move(prompt_user_callback_), acceptance)); | 288 base::BindOnce(std::move(prompt_user_callback_), acceptance)); |
| 254 | 289 |
| 255 // The transition to a new state should happen only after the response has | 290 // The transition to a new state should happen only after the response has |
| 256 // been posted on the UI thread so that if we transition to the kIdle state, | 291 // been posted on the UI thread so that if we transition to the kIdle state, |
| 257 // the response callback is not cleared before it has been posted. | 292 // the response callback is not cleared before it has been posted. |
| 258 SetStateAndNotifyObservers(new_state); | 293 SetStateAndNotifyObservers(new_state); |
| 259 } | 294 } |
| 260 | 295 |
| 261 void ChromeCleanerController::Reboot() { | 296 void ChromeCleanerController::Reboot() { |
| 262 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | 297 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 263 | 298 |
| 264 if (state() != State::kRebootRequired) | 299 if (state() != State::kRebootRequired) |
| 265 return; | 300 return; |
| 266 | 301 |
| 302 UMA_HISTOGRAM_ENUMERATION("SoftwareReporter.Cleaner.RebootResponse", |
| 303 REBOOT_RESPONSE_INITIATED, REBOOT_RESPONSE_MAX); |
| 267 InitiateReboot(); | 304 InitiateReboot(); |
| 268 } | 305 } |
| 269 | 306 |
| 270 ChromeCleanerController::ChromeCleanerController() | 307 ChromeCleanerController::ChromeCleanerController() |
| 271 : real_delegate_(base::MakeUnique<ChromeCleanerControllerDelegate>()), | 308 : real_delegate_(base::MakeUnique<ChromeCleanerControllerDelegate>()), |
| 272 delegate_(real_delegate_.get()), | 309 delegate_(real_delegate_.get()), |
| 273 weak_factory_(this) { | 310 weak_factory_(this) { |
| 274 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | 311 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 275 } | 312 } |
| 276 | 313 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 | 359 |
| 323 void ChromeCleanerController::OnChromeCleanerFetchedAndVerified( | 360 void ChromeCleanerController::OnChromeCleanerFetchedAndVerified( |
| 324 base::FilePath executable_path) { | 361 base::FilePath executable_path) { |
| 325 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | 362 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 326 DCHECK_EQ(State::kScanning, state()); | 363 DCHECK_EQ(State::kScanning, state()); |
| 327 DCHECK(reporter_invocation_); | 364 DCHECK(reporter_invocation_); |
| 328 | 365 |
| 329 if (executable_path.empty()) { | 366 if (executable_path.empty()) { |
| 330 idle_reason_ = IdleReason::kScanningFailed; | 367 idle_reason_ = IdleReason::kScanningFailed; |
| 331 SetStateAndNotifyObservers(State::kIdle); | 368 SetStateAndNotifyObservers(State::kIdle); |
| 369 RecordPromptNotShownWithReasonHistogram( |
| 370 NO_PROMPT_REASON_CLEANER_DOWNLOAD_FAILED); |
| 332 return; | 371 return; |
| 333 } | 372 } |
| 334 | 373 |
| 335 DCHECK(executable_path.MatchesExtension(FILE_PATH_LITERAL(".exe"))); | 374 DCHECK(executable_path.MatchesExtension(FILE_PATH_LITERAL(".exe"))); |
| 336 | 375 |
| 337 ChromeCleanerRunner::ChromeMetricsStatus metrics_status = | 376 ChromeCleanerRunner::ChromeMetricsStatus metrics_status = |
| 338 delegate_->IsMetricsAndCrashReportingEnabled() | 377 delegate_->IsMetricsAndCrashReportingEnabled() |
| 339 ? ChromeCleanerRunner::ChromeMetricsStatus::kEnabled | 378 ? ChromeCleanerRunner::ChromeMetricsStatus::kEnabled |
| 340 : ChromeCleanerRunner::ChromeMetricsStatus::kDisabled; | 379 : ChromeCleanerRunner::ChromeMetricsStatus::kDisabled; |
| 341 | 380 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 DCHECK_EQ(State::kScanning, state()); | 423 DCHECK_EQ(State::kScanning, state()); |
| 385 DCHECK(!files_to_delete_); | 424 DCHECK(!files_to_delete_); |
| 386 DCHECK(!prompt_user_callback_); | 425 DCHECK(!prompt_user_callback_); |
| 387 | 426 |
| 388 if (files_to_delete->empty()) { | 427 if (files_to_delete->empty()) { |
| 389 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO) | 428 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO) |
| 390 ->PostTask(FROM_HERE, base::BindOnce(std::move(prompt_user_callback), | 429 ->PostTask(FROM_HERE, base::BindOnce(std::move(prompt_user_callback), |
| 391 PromptAcceptance::DENIED)); | 430 PromptAcceptance::DENIED)); |
| 392 idle_reason_ = IdleReason::kScanningFoundNothing; | 431 idle_reason_ = IdleReason::kScanningFoundNothing; |
| 393 SetStateAndNotifyObservers(State::kIdle); | 432 SetStateAndNotifyObservers(State::kIdle); |
| 433 RecordPromptNotShownWithReasonHistogram(NO_PROMPT_REASON_NOTHING_FOUND); |
| 394 return; | 434 return; |
| 395 } | 435 } |
| 396 | 436 |
| 437 UMA_HISTOGRAM_COUNTS_1000("SoftwareReporter.NumberOfFilesToDelete", |
| 438 files_to_delete->size()); |
| 397 files_to_delete_ = std::move(files_to_delete); | 439 files_to_delete_ = std::move(files_to_delete); |
| 398 prompt_user_callback_ = std::move(prompt_user_callback); | 440 prompt_user_callback_ = std::move(prompt_user_callback); |
| 399 SetStateAndNotifyObservers(State::kInfected); | 441 SetStateAndNotifyObservers(State::kInfected); |
| 400 } | 442 } |
| 401 | 443 |
| 402 void ChromeCleanerController::OnConnectionClosed() { | 444 void ChromeCleanerController::OnConnectionClosed() { |
| 403 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | 445 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 404 DCHECK_NE(State::kIdle, state()); | 446 DCHECK_NE(State::kIdle, state()); |
| 405 DCHECK_NE(State::kRebootRequired, state()); | 447 DCHECK_NE(State::kRebootRequired, state()); |
| 406 | 448 |
| 407 if (state() == State::kScanning || state() == State::kInfected) { | 449 if (state() == State::kScanning || state() == State::kInfected) { |
| 408 idle_reason_ = IdleReasonWhenConnectionClosedTooSoon(state()); | 450 idle_reason_ = IdleReasonWhenConnectionClosedTooSoon(state()); |
| 409 SetStateAndNotifyObservers(State::kIdle); | 451 SetStateAndNotifyObservers(State::kIdle); |
| 452 RecordPromptNotShownWithReasonHistogram( |
| 453 NO_PROMPT_REASON_IPC_CONNECTION_BROKEN); |
| 410 return; | 454 return; |
| 411 } | 455 } |
| 412 // Nothing to do if OnConnectionClosed() is called in other states: | 456 // Nothing to do if OnConnectionClosed() is called in other states: |
| 413 // - This function will not be called in the kIdle and kRebootRequired | 457 // - This function will not be called in the kIdle and kRebootRequired |
| 414 // states since we invalidate all weak pointers when we enter those states. | 458 // states since we invalidate all weak pointers when we enter those states. |
| 415 // - In the kCleaning state, we don't care about the connection to the Chrome | 459 // - In the kCleaning state, we don't care about the connection to the Chrome |
| 416 // Cleaner process since communication via Mojo is complete and only the | 460 // Cleaner process since communication via Mojo is complete and only the |
| 417 // exit code of the process is of any use to us (for deciding whether we | 461 // exit code of the process is of any use to us (for deciding whether we |
| 418 // need to reboot). | 462 // need to reboot). |
| 419 } | 463 } |
| 420 | 464 |
| 421 void ChromeCleanerController::OnCleanerProcessDone( | 465 void ChromeCleanerController::OnCleanerProcessDone( |
| 422 ChromeCleanerRunner::ProcessStatus process_status) { | 466 ChromeCleanerRunner::ProcessStatus process_status) { |
| 423 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | 467 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 424 | 468 |
| 425 if (state() == State::kScanning || state() == State::kInfected) { | 469 if (state() == State::kScanning || state() == State::kInfected) { |
| 426 idle_reason_ = IdleReasonWhenConnectionClosedTooSoon(state()); | 470 idle_reason_ = IdleReasonWhenConnectionClosedTooSoon(state()); |
| 427 SetStateAndNotifyObservers(State::kIdle); | 471 SetStateAndNotifyObservers(State::kIdle); |
| 428 return; | 472 return; |
| 429 } | 473 } |
| 430 | 474 |
| 431 DCHECK_EQ(State::kCleaning, state()); | 475 DCHECK_EQ(State::kCleaning, state()); |
| 432 DCHECK_NE(ChromeCleanerRunner::LaunchStatus::kLaunchFailed, | 476 DCHECK_NE(ChromeCleanerRunner::LaunchStatus::kLaunchFailed, |
| 433 process_status.launch_status); | 477 process_status.launch_status); |
| 434 | 478 |
| 435 if (process_status.launch_status != | 479 if (process_status.launch_status == |
| 436 ChromeCleanerRunner::LaunchStatus::kSuccess) { | 480 ChromeCleanerRunner::LaunchStatus::kSuccess) { |
| 437 idle_reason_ = IdleReason::kCleaningFailed; | 481 if (process_status.exit_code == kRebootRequiredExitCode) { |
| 438 SetStateAndNotifyObservers(State::kIdle); | 482 RecordCleanupResultHistogram(CLEANUP_RESULT_REBOOT_REQUIRED); |
| 439 return; | 483 SetStateAndNotifyObservers(State::kRebootRequired); |
| 484 return; |
| 485 } |
| 486 |
| 487 if (process_status.exit_code == kRebootNotRequiredExitCode) { |
| 488 RecordCleanupResultHistogram(CLEANUP_RESULT_SUCCEEDED); |
| 489 delegate_->ResetTaggedProfiles( |
| 490 g_browser_process->profile_manager()->GetLoadedProfiles(), |
| 491 base::BindOnce(&ChromeCleanerController::OnSettingsResetCompleted, |
| 492 base::Unretained(this))); |
| 493 ResetCleanerDataAndInvalidateWeakPtrs(); |
| 494 return; |
| 495 } |
| 440 } | 496 } |
| 441 | 497 |
| 442 if (process_status.exit_code == kRebootRequiredExitCode) { | 498 RecordCleanupResultHistogram(CLEANUP_RESULT_FAILED); |
| 443 SetStateAndNotifyObservers(State::kRebootRequired); | |
| 444 return; | |
| 445 } | |
| 446 | |
| 447 if (process_status.exit_code == kRebootNotRequiredExitCode) { | |
| 448 delegate_->ResetTaggedProfiles( | |
| 449 g_browser_process->profile_manager()->GetLoadedProfiles(), | |
| 450 base::BindOnce(&ChromeCleanerController::OnSettingsResetCompleted, | |
| 451 base::Unretained(this))); | |
| 452 ResetCleanerDataAndInvalidateWeakPtrs(); | |
| 453 return; | |
| 454 } | |
| 455 | |
| 456 idle_reason_ = IdleReason::kCleaningFailed; | 499 idle_reason_ = IdleReason::kCleaningFailed; |
| 457 SetStateAndNotifyObservers(State::kIdle); | 500 SetStateAndNotifyObservers(State::kIdle); |
| 458 } | 501 } |
| 459 | 502 |
| 460 void ChromeCleanerController::InitiateReboot() { | 503 void ChromeCleanerController::InitiateReboot() { |
| 461 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | 504 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 462 | 505 |
| 463 installer::ScopedTokenPrivilege scoped_se_shutdown_privilege( | 506 installer::ScopedTokenPrivilege scoped_se_shutdown_privilege( |
| 464 SE_SHUTDOWN_NAME); | 507 SE_SHUTDOWN_NAME); |
| 465 if (!scoped_se_shutdown_privilege.is_enabled() || | 508 if (!scoped_se_shutdown_privilege.is_enabled() || |
| 466 !::ExitWindowsEx(EWX_REBOOT, SHTDN_REASON_MAJOR_SOFTWARE | | 509 !::ExitWindowsEx(EWX_REBOOT, SHTDN_REASON_MAJOR_SOFTWARE | |
| 467 SHTDN_REASON_MINOR_OTHER | | 510 SHTDN_REASON_MINOR_OTHER | |
| 468 SHTDN_REASON_FLAG_PLANNED)) { | 511 SHTDN_REASON_FLAG_PLANNED)) { |
| 469 for (auto& observer : observer_list_) | 512 for (auto& observer : observer_list_) |
| 470 observer.OnRebootFailed(); | 513 observer.OnRebootFailed(); |
| 471 } | 514 } |
| 472 } | 515 } |
| 473 | 516 |
| 474 void ChromeCleanerController::OnSettingsResetCompleted() { | 517 void ChromeCleanerController::OnSettingsResetCompleted() { |
| 475 idle_reason_ = IdleReason::kCleaningSucceeded; | 518 idle_reason_ = IdleReason::kCleaningSucceeded; |
| 476 SetStateAndNotifyObservers(State::kIdle); | 519 SetStateAndNotifyObservers(State::kIdle); |
| 477 } | 520 } |
| 478 | 521 |
| 479 } // namespace safe_browsing | 522 } // namespace safe_browsing |
| OLD | NEW |