Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1226)

Side by Side Diff: chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_controller_win.cc

Issue 2929483002: Chrome Cleaner: download the Chrome Cleaner executable in an empty directory. (Closed)
Patch Set: Nits Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_fetcher_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 25 matching lines...) Expand all
36 using ::content::BrowserThread; 36 using ::content::BrowserThread;
37 37
38 // TODO(alito): Move these shared exit codes to the chrome_cleaner component. 38 // TODO(alito): Move these shared exit codes to the chrome_cleaner component.
39 // https://crbug.com/727956 39 // https://crbug.com/727956
40 constexpr int kRebootRequiredExitCode = 15; 40 constexpr int kRebootRequiredExitCode = 15;
41 constexpr int kRebootNotRequiredExitCode = 0; 41 constexpr int kRebootNotRequiredExitCode = 0;
42 42
43 // Attempts to change the Chrome Cleaner binary's suffix to ".exe". Will return 43 // Attempts to change the Chrome Cleaner binary's suffix to ".exe". Will return
44 // an empty FilePath on failure. Should be called on a sequence with traits 44 // an empty FilePath on failure. Should be called on a sequence with traits
45 // appropriate for IO operations. 45 // appropriate for IO operations.
46 base::FilePath VerifyAndRenameDownloadedCleaner(base::FilePath downloaded_path, 46 base::FilePath VerifyAndRenameDownloadedCleaner(
47 int http_response_code) { 47 base::FilePath downloaded_path,
48 ChromeCleanerFetchStatus fetch_status) {
48 base::ThreadRestrictions::AssertIOAllowed(); 49 base::ThreadRestrictions::AssertIOAllowed();
49 50
50 if (downloaded_path.empty() || !base::PathExists(downloaded_path)) 51 if (downloaded_path.empty() || !base::PathExists(downloaded_path))
51 return base::FilePath(); 52 return base::FilePath();
52 53
53 if (http_response_code != net::HTTP_OK) { 54 if (fetch_status != ChromeCleanerFetchStatus::kSuccess) {
54 base::DeleteFile(downloaded_path, /*recursive=*/false); 55 base::DeleteFile(downloaded_path, /*recursive=*/false);
55 return base::FilePath(); 56 return base::FilePath();
56 } 57 }
57 58
58 base::FilePath executable_path( 59 base::FilePath executable_path(
59 downloaded_path.ReplaceExtension(FILE_PATH_LITERAL("exe"))); 60 downloaded_path.ReplaceExtension(FILE_PATH_LITERAL("exe")));
60 61
61 if (!base::ReplaceFile(downloaded_path, executable_path, nullptr)) { 62 if (!base::ReplaceFile(downloaded_path, executable_path, nullptr)) {
62 base::DeleteFile(downloaded_path, /*recursive=*/false); 63 base::DeleteFile(downloaded_path, /*recursive=*/false);
63 return base::FilePath(); 64 return base::FilePath();
64 } 65 }
65 66
66 return executable_path; 67 return executable_path;
67 } 68 }
68 69
69 void OnChromeCleanerFetched( 70 void OnChromeCleanerFetched(
70 ChromeCleanerControllerDelegate::FetchedCallback fetched_callback, 71 ChromeCleanerControllerDelegate::FetchedCallback fetched_callback,
71 base::FilePath downloaded_path, 72 base::FilePath downloaded_path,
72 int http_response_code) { 73 ChromeCleanerFetchStatus fetch_status) {
73 base::PostTaskWithTraitsAndReplyWithResult( 74 base::PostTaskWithTraitsAndReplyWithResult(
74 FROM_HERE, 75 FROM_HERE,
75 {base::MayBlock(), base::TaskPriority::BACKGROUND, 76 {base::MayBlock(), base::TaskPriority::BACKGROUND,
76 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}, 77 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
77 base::BindOnce(VerifyAndRenameDownloadedCleaner, downloaded_path, 78 base::BindOnce(VerifyAndRenameDownloadedCleaner, downloaded_path,
78 http_response_code), 79 fetch_status),
79 std::move(fetched_callback)); 80 std::move(fetched_callback));
80 } 81 }
81 82
82 ChromeCleanerController::IdleReason IdleReasonWhenConnectionClosedTooSoon( 83 ChromeCleanerController::IdleReason IdleReasonWhenConnectionClosedTooSoon(
83 ChromeCleanerController::State current_state) { 84 ChromeCleanerController::State current_state) {
84 DCHECK(current_state == ChromeCleanerController::State::kScanning || 85 DCHECK(current_state == ChromeCleanerController::State::kScanning ||
85 current_state == ChromeCleanerController::State::kInfected); 86 current_state == ChromeCleanerController::State::kInfected);
86 87
87 return current_state == ChromeCleanerController::State::kScanning 88 return current_state == ChromeCleanerController::State::kScanning
88 ? ChromeCleanerController::IdleReason::kScanningFailed 89 ? ChromeCleanerController::IdleReason::kScanningFailed
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 idle_reason_ = IdleReason::kCleaningSucceeded; 371 idle_reason_ = IdleReason::kCleaningSucceeded;
371 SetStateAndNotifyObservers(State::kIdle); 372 SetStateAndNotifyObservers(State::kIdle);
372 return; 373 return;
373 } 374 }
374 375
375 idle_reason_ = IdleReason::kCleaningFailed; 376 idle_reason_ = IdleReason::kCleaningFailed;
376 SetStateAndNotifyObservers(State::kIdle); 377 SetStateAndNotifyObservers(State::kIdle);
377 } 378 }
378 379
379 } // namespace safe_browsing 380 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_fetcher_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698