| 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 // These values are used to send UMA information and are replicated in the |
| 66 // histograms.xml file, so the order MUST NOT CHANGE. |
| 67 enum RebootResponseHistogramValue { |
| 68 REBOOT_RESPONSE_INITIATED = 0, |
| 69 |
| 70 REBOOT_RESPONSE_MAX, |
| 71 }; |
| 72 |
| 73 // These values are used to send UMA information and are replicated in the |
| 74 // histograms.xml file, so the order MUST NOT CHANGE. |
| 75 enum IPCConnectionErrorHistogramValue { |
| 76 IPC_ERROR_CONNECTION_LOST_WHILE_SCANNING = 0, |
| 77 IPC_ERROR_CONNECTION_LOST_USER_PROMPTED = 1, |
| 78 |
| 79 IPC_ERROR_CONNECTION_MAX, |
| 80 }; |
| 81 |
| 53 // Attempts to change the Chrome Cleaner binary's suffix to ".exe". Will return | 82 // 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 | 83 // an empty FilePath on failure. Should be called on a sequence with traits |
| 55 // appropriate for IO operations. | 84 // appropriate for IO operations. |
| 56 base::FilePath VerifyAndRenameDownloadedCleaner( | 85 base::FilePath VerifyAndRenameDownloadedCleaner( |
| 57 base::FilePath downloaded_path, | 86 base::FilePath downloaded_path, |
| 58 ChromeCleanerFetchStatus fetch_status) { | 87 ChromeCleanerFetchStatus fetch_status) { |
| 59 base::ThreadRestrictions::AssertIOAllowed(); | 88 base::ThreadRestrictions::AssertIOAllowed(); |
| 60 | 89 |
| 61 if (downloaded_path.empty() || !base::PathExists(downloaded_path)) | 90 if (downloaded_path.empty() || !base::PathExists(downloaded_path)) |
| 62 return base::FilePath(); | 91 return base::FilePath(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 93 ChromeCleanerController::IdleReason IdleReasonWhenConnectionClosedTooSoon( | 122 ChromeCleanerController::IdleReason IdleReasonWhenConnectionClosedTooSoon( |
| 94 ChromeCleanerController::State current_state) { | 123 ChromeCleanerController::State current_state) { |
| 95 DCHECK(current_state == ChromeCleanerController::State::kScanning || | 124 DCHECK(current_state == ChromeCleanerController::State::kScanning || |
| 96 current_state == ChromeCleanerController::State::kInfected); | 125 current_state == ChromeCleanerController::State::kInfected); |
| 97 | 126 |
| 98 return current_state == ChromeCleanerController::State::kScanning | 127 return current_state == ChromeCleanerController::State::kScanning |
| 99 ? ChromeCleanerController::IdleReason::kScanningFailed | 128 ? ChromeCleanerController::IdleReason::kScanningFailed |
| 100 : ChromeCleanerController::IdleReason::kConnectionLost; | 129 : ChromeCleanerController::IdleReason::kConnectionLost; |
| 101 } | 130 } |
| 102 | 131 |
| 132 void RecordCleanerLogsAcceptanceHistogram(bool logs_accepted) { |
| 133 UMA_HISTOGRAM_BOOLEAN("SoftwareReporter.CleanerLogsAcceptance", |
| 134 logs_accepted); |
| 135 } |
| 136 |
| 137 void RecordCleanupResultHistogram(CleanupResultHistogramValue result) { |
| 138 UMA_HISTOGRAM_ENUMERATION("SoftwareReporter.Cleaner.CleanupResult", result, |
| 139 CLEANUP_RESULT_MAX); |
| 140 } |
| 141 |
| 142 void RecordIPCConnectionErrorHistogram(IPCConnectionErrorHistogramValue error) { |
| 143 UMA_HISTOGRAM_ENUMERATION("SoftwareReporter.IPCConnectionError", error, |
| 144 IPC_ERROR_CONNECTION_MAX); |
| 145 } |
| 146 |
| 103 } // namespace | 147 } // namespace |
| 104 | 148 |
| 149 void RecordCleanupStartedHistogram(CleanupStartedHistogramValue value) { |
| 150 UMA_HISTOGRAM_ENUMERATION("SoftwareReporter.CleanupStarted", value, |
| 151 CLEANUP_STARTED_MAX); |
| 152 } |
| 153 |
| 105 ChromeCleanerControllerDelegate::ChromeCleanerControllerDelegate() = default; | 154 ChromeCleanerControllerDelegate::ChromeCleanerControllerDelegate() = default; |
| 106 | 155 |
| 107 ChromeCleanerControllerDelegate::~ChromeCleanerControllerDelegate() = default; | 156 ChromeCleanerControllerDelegate::~ChromeCleanerControllerDelegate() = default; |
| 108 | 157 |
| 109 void ChromeCleanerControllerDelegate::FetchAndVerifyChromeCleaner( | 158 void ChromeCleanerControllerDelegate::FetchAndVerifyChromeCleaner( |
| 110 FetchedCallback fetched_callback) { | 159 FetchedCallback fetched_callback) { |
| 111 FetchChromeCleaner( | 160 FetchChromeCleaner( |
| 112 base::BindOnce(&OnChromeCleanerFetched, base::Passed(&fetched_callback))); | 161 base::BindOnce(&OnChromeCleanerFetched, base::Passed(&fetched_callback))); |
| 113 } | 162 } |
| 114 | 163 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 return; | 273 return; |
| 225 | 274 |
| 226 DCHECK(prompt_user_callback_); | 275 DCHECK(prompt_user_callback_); |
| 227 | 276 |
| 228 PromptAcceptance acceptance = PromptAcceptance::DENIED; | 277 PromptAcceptance acceptance = PromptAcceptance::DENIED; |
| 229 State new_state = State::kIdle; | 278 State new_state = State::kIdle; |
| 230 switch (user_response) { | 279 switch (user_response) { |
| 231 case UserResponse::kAcceptedWithLogs: | 280 case UserResponse::kAcceptedWithLogs: |
| 232 acceptance = PromptAcceptance::ACCEPTED_WITH_LOGS; | 281 acceptance = PromptAcceptance::ACCEPTED_WITH_LOGS; |
| 233 SetLogsEnabled(true); | 282 SetLogsEnabled(true); |
| 283 RecordCleanerLogsAcceptanceHistogram(true); |
| 234 new_state = State::kCleaning; | 284 new_state = State::kCleaning; |
| 235 delegate_->TagForResetting(profile); | 285 delegate_->TagForResetting(profile); |
| 236 break; | 286 break; |
| 237 case UserResponse::kAcceptedWithoutLogs: | 287 case UserResponse::kAcceptedWithoutLogs: |
| 238 acceptance = PromptAcceptance::ACCEPTED_WITHOUT_LOGS; | 288 acceptance = PromptAcceptance::ACCEPTED_WITHOUT_LOGS; |
| 239 SetLogsEnabled(false); | 289 SetLogsEnabled(false); |
| 290 RecordCleanerLogsAcceptanceHistogram(false); |
| 240 new_state = State::kCleaning; | 291 new_state = State::kCleaning; |
| 241 delegate_->TagForResetting(profile); | 292 delegate_->TagForResetting(profile); |
| 242 break; | 293 break; |
| 243 case UserResponse::kDenied: // Fallthrough | 294 case UserResponse::kDenied: // Fallthrough |
| 244 case UserResponse::kDismissed: | 295 case UserResponse::kDismissed: |
| 245 acceptance = PromptAcceptance::DENIED; | 296 acceptance = PromptAcceptance::DENIED; |
| 246 idle_reason_ = IdleReason::kUserDeclinedCleanup; | 297 idle_reason_ = IdleReason::kUserDeclinedCleanup; |
| 247 new_state = State::kIdle; | 298 new_state = State::kIdle; |
| 248 break; | 299 break; |
| 249 } | 300 } |
| 250 | 301 |
| 251 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO) | 302 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO) |
| 252 ->PostTask(FROM_HERE, | 303 ->PostTask(FROM_HERE, |
| 253 base::BindOnce(std::move(prompt_user_callback_), acceptance)); | 304 base::BindOnce(std::move(prompt_user_callback_), acceptance)); |
| 254 | 305 |
| 255 // The transition to a new state should happen only after the response has | 306 // 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, | 307 // 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. | 308 // the response callback is not cleared before it has been posted. |
| 258 SetStateAndNotifyObservers(new_state); | 309 SetStateAndNotifyObservers(new_state); |
| 259 } | 310 } |
| 260 | 311 |
| 261 void ChromeCleanerController::Reboot() { | 312 void ChromeCleanerController::Reboot() { |
| 262 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | 313 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 263 | 314 |
| 264 if (state() != State::kRebootRequired) | 315 if (state() != State::kRebootRequired) |
| 265 return; | 316 return; |
| 266 | 317 |
| 318 UMA_HISTOGRAM_ENUMERATION("SoftwareReporter.Cleaner.RebootResponse", |
| 319 REBOOT_RESPONSE_INITIATED, REBOOT_RESPONSE_MAX); |
| 267 InitiateReboot(); | 320 InitiateReboot(); |
| 268 } | 321 } |
| 269 | 322 |
| 270 ChromeCleanerController::ChromeCleanerController() | 323 ChromeCleanerController::ChromeCleanerController() |
| 271 : real_delegate_(base::MakeUnique<ChromeCleanerControllerDelegate>()), | 324 : real_delegate_(base::MakeUnique<ChromeCleanerControllerDelegate>()), |
| 272 delegate_(real_delegate_.get()), | 325 delegate_(real_delegate_.get()), |
| 273 weak_factory_(this) { | 326 weak_factory_(this) { |
| 274 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | 327 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 275 } | 328 } |
| 276 | 329 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 | 375 |
| 323 void ChromeCleanerController::OnChromeCleanerFetchedAndVerified( | 376 void ChromeCleanerController::OnChromeCleanerFetchedAndVerified( |
| 324 base::FilePath executable_path) { | 377 base::FilePath executable_path) { |
| 325 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | 378 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 326 DCHECK_EQ(State::kScanning, state()); | 379 DCHECK_EQ(State::kScanning, state()); |
| 327 DCHECK(reporter_invocation_); | 380 DCHECK(reporter_invocation_); |
| 328 | 381 |
| 329 if (executable_path.empty()) { | 382 if (executable_path.empty()) { |
| 330 idle_reason_ = IdleReason::kScanningFailed; | 383 idle_reason_ = IdleReason::kScanningFailed; |
| 331 SetStateAndNotifyObservers(State::kIdle); | 384 SetStateAndNotifyObservers(State::kIdle); |
| 385 RecordPromptNotShownWithReasonHistogram( |
| 386 NO_PROMPT_REASON_CLEANER_DOWNLOAD_FAILED); |
| 332 return; | 387 return; |
| 333 } | 388 } |
| 334 | 389 |
| 335 DCHECK(executable_path.MatchesExtension(FILE_PATH_LITERAL(".exe"))); | 390 DCHECK(executable_path.MatchesExtension(FILE_PATH_LITERAL(".exe"))); |
| 336 | 391 |
| 337 ChromeCleanerRunner::ChromeMetricsStatus metrics_status = | 392 ChromeCleanerRunner::ChromeMetricsStatus metrics_status = |
| 338 delegate_->IsMetricsAndCrashReportingEnabled() | 393 delegate_->IsMetricsAndCrashReportingEnabled() |
| 339 ? ChromeCleanerRunner::ChromeMetricsStatus::kEnabled | 394 ? ChromeCleanerRunner::ChromeMetricsStatus::kEnabled |
| 340 : ChromeCleanerRunner::ChromeMetricsStatus::kDisabled; | 395 : ChromeCleanerRunner::ChromeMetricsStatus::kDisabled; |
| 341 | 396 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 DCHECK_EQ(State::kScanning, state()); | 439 DCHECK_EQ(State::kScanning, state()); |
| 385 DCHECK(!files_to_delete_); | 440 DCHECK(!files_to_delete_); |
| 386 DCHECK(!prompt_user_callback_); | 441 DCHECK(!prompt_user_callback_); |
| 387 | 442 |
| 388 if (files_to_delete->empty()) { | 443 if (files_to_delete->empty()) { |
| 389 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO) | 444 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO) |
| 390 ->PostTask(FROM_HERE, base::BindOnce(std::move(prompt_user_callback), | 445 ->PostTask(FROM_HERE, base::BindOnce(std::move(prompt_user_callback), |
| 391 PromptAcceptance::DENIED)); | 446 PromptAcceptance::DENIED)); |
| 392 idle_reason_ = IdleReason::kScanningFoundNothing; | 447 idle_reason_ = IdleReason::kScanningFoundNothing; |
| 393 SetStateAndNotifyObservers(State::kIdle); | 448 SetStateAndNotifyObservers(State::kIdle); |
| 449 RecordPromptNotShownWithReasonHistogram(NO_PROMPT_REASON_NOTHING_FOUND); |
| 394 return; | 450 return; |
| 395 } | 451 } |
| 396 | 452 |
| 453 UMA_HISTOGRAM_COUNTS_1000("SoftwareReporter.NumberOfFilesToDelete", |
| 454 files_to_delete->size()); |
| 397 files_to_delete_ = std::move(files_to_delete); | 455 files_to_delete_ = std::move(files_to_delete); |
| 398 prompt_user_callback_ = std::move(prompt_user_callback); | 456 prompt_user_callback_ = std::move(prompt_user_callback); |
| 399 SetStateAndNotifyObservers(State::kInfected); | 457 SetStateAndNotifyObservers(State::kInfected); |
| 400 } | 458 } |
| 401 | 459 |
| 402 void ChromeCleanerController::OnConnectionClosed() { | 460 void ChromeCleanerController::OnConnectionClosed() { |
| 403 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | 461 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 404 DCHECK_NE(State::kIdle, state()); | 462 DCHECK_NE(State::kIdle, state()); |
| 405 DCHECK_NE(State::kRebootRequired, state()); | 463 DCHECK_NE(State::kRebootRequired, state()); |
| 406 | 464 |
| 407 if (state() == State::kScanning || state() == State::kInfected) { | 465 if (state() == State::kScanning || state() == State::kInfected) { |
| 466 if (state() == State::kScanning) { |
| 467 RecordPromptNotShownWithReasonHistogram( |
| 468 NO_PROMPT_REASON_IPC_CONNECTION_BROKEN); |
| 469 RecordIPCConnectionErrorHistogram( |
| 470 IPC_ERROR_CONNECTION_LOST_WHILE_SCANNING); |
| 471 } else { |
| 472 RecordIPCConnectionErrorHistogram( |
| 473 IPC_ERROR_CONNECTION_LOST_USER_PROMPTED); |
| 474 } |
| 475 |
| 408 idle_reason_ = IdleReasonWhenConnectionClosedTooSoon(state()); | 476 idle_reason_ = IdleReasonWhenConnectionClosedTooSoon(state()); |
| 409 SetStateAndNotifyObservers(State::kIdle); | 477 SetStateAndNotifyObservers(State::kIdle); |
| 410 return; | 478 return; |
| 411 } | 479 } |
| 412 // Nothing to do if OnConnectionClosed() is called in other states: | 480 // Nothing to do if OnConnectionClosed() is called in other states: |
| 413 // - This function will not be called in the kIdle and kRebootRequired | 481 // - This function will not be called in the kIdle and kRebootRequired |
| 414 // states since we invalidate all weak pointers when we enter those states. | 482 // 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 | 483 // - 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 | 484 // 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 | 485 // exit code of the process is of any use to us (for deciding whether we |
| 418 // need to reboot). | 486 // need to reboot). |
| 419 } | 487 } |
| 420 | 488 |
| 421 void ChromeCleanerController::OnCleanerProcessDone( | 489 void ChromeCleanerController::OnCleanerProcessDone( |
| 422 ChromeCleanerRunner::ProcessStatus process_status) { | 490 ChromeCleanerRunner::ProcessStatus process_status) { |
| 423 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | 491 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 424 | 492 |
| 425 if (state() == State::kScanning || state() == State::kInfected) { | 493 if (state() == State::kScanning || state() == State::kInfected) { |
| 426 idle_reason_ = IdleReasonWhenConnectionClosedTooSoon(state()); | 494 idle_reason_ = IdleReasonWhenConnectionClosedTooSoon(state()); |
| 427 SetStateAndNotifyObservers(State::kIdle); | 495 SetStateAndNotifyObservers(State::kIdle); |
| 428 return; | 496 return; |
| 429 } | 497 } |
| 430 | 498 |
| 431 DCHECK_EQ(State::kCleaning, state()); | 499 DCHECK_EQ(State::kCleaning, state()); |
| 432 DCHECK_NE(ChromeCleanerRunner::LaunchStatus::kLaunchFailed, | 500 DCHECK_NE(ChromeCleanerRunner::LaunchStatus::kLaunchFailed, |
| 433 process_status.launch_status); | 501 process_status.launch_status); |
| 434 | 502 |
| 435 if (process_status.launch_status != | 503 if (process_status.launch_status == |
| 436 ChromeCleanerRunner::LaunchStatus::kSuccess) { | 504 ChromeCleanerRunner::LaunchStatus::kSuccess) { |
| 437 idle_reason_ = IdleReason::kCleaningFailed; | 505 if (process_status.exit_code == kRebootRequiredExitCode) { |
| 438 SetStateAndNotifyObservers(State::kIdle); | 506 RecordCleanupResultHistogram(CLEANUP_RESULT_REBOOT_REQUIRED); |
| 439 return; | 507 SetStateAndNotifyObservers(State::kRebootRequired); |
| 508 return; |
| 509 } |
| 510 |
| 511 if (process_status.exit_code == kRebootNotRequiredExitCode) { |
| 512 RecordCleanupResultHistogram(CLEANUP_RESULT_SUCCEEDED); |
| 513 delegate_->ResetTaggedProfiles( |
| 514 g_browser_process->profile_manager()->GetLoadedProfiles(), |
| 515 base::BindOnce(&ChromeCleanerController::OnSettingsResetCompleted, |
| 516 base::Unretained(this))); |
| 517 ResetCleanerDataAndInvalidateWeakPtrs(); |
| 518 return; |
| 519 } |
| 440 } | 520 } |
| 441 | 521 |
| 442 if (process_status.exit_code == kRebootRequiredExitCode) { | 522 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; | 523 idle_reason_ = IdleReason::kCleaningFailed; |
| 457 SetStateAndNotifyObservers(State::kIdle); | 524 SetStateAndNotifyObservers(State::kIdle); |
| 458 } | 525 } |
| 459 | 526 |
| 460 void ChromeCleanerController::InitiateReboot() { | 527 void ChromeCleanerController::InitiateReboot() { |
| 461 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | 528 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 462 | 529 |
| 463 installer::ScopedTokenPrivilege scoped_se_shutdown_privilege( | 530 installer::ScopedTokenPrivilege scoped_se_shutdown_privilege( |
| 464 SE_SHUTDOWN_NAME); | 531 SE_SHUTDOWN_NAME); |
| 465 if (!scoped_se_shutdown_privilege.is_enabled() || | 532 if (!scoped_se_shutdown_privilege.is_enabled() || |
| 466 !::ExitWindowsEx(EWX_REBOOT, SHTDN_REASON_MAJOR_SOFTWARE | | 533 !::ExitWindowsEx(EWX_REBOOT, SHTDN_REASON_MAJOR_SOFTWARE | |
| 467 SHTDN_REASON_MINOR_OTHER | | 534 SHTDN_REASON_MINOR_OTHER | |
| 468 SHTDN_REASON_FLAG_PLANNED)) { | 535 SHTDN_REASON_FLAG_PLANNED)) { |
| 469 for (auto& observer : observer_list_) | 536 for (auto& observer : observer_list_) |
| 470 observer.OnRebootFailed(); | 537 observer.OnRebootFailed(); |
| 471 } | 538 } |
| 472 } | 539 } |
| 473 | 540 |
| 474 void ChromeCleanerController::OnSettingsResetCompleted() { | 541 void ChromeCleanerController::OnSettingsResetCompleted() { |
| 475 idle_reason_ = IdleReason::kCleaningSucceeded; | 542 idle_reason_ = IdleReason::kCleaningSucceeded; |
| 476 SetStateAndNotifyObservers(State::kIdle); | 543 SetStateAndNotifyObservers(State::kIdle); |
| 477 } | 544 } |
| 478 | 545 |
| 479 } // namespace safe_browsing | 546 } // namespace safe_browsing |
| OLD | NEW |