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

Side by Side Diff: chrome/browser/net/file_downloader.cc

Issue 1851803002: [NTP Popular Sites] Store country/version in prefs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review Created 4 years, 8 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 | « chrome/browser/net/file_downloader.h ('k') | chrome/browser/net/file_downloader_unittest.cc » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/net/file_downloader.h" 5 #include "chrome/browser/net/file_downloader.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 FileDownloader::~FileDownloader() {} 52 FileDownloader::~FileDownloader() {}
53 53
54 void FileDownloader::OnURLFetchComplete(const net::URLFetcher* source) { 54 void FileDownloader::OnURLFetchComplete(const net::URLFetcher* source) {
55 DCHECK_EQ(fetcher_.get(), source); 55 DCHECK_EQ(fetcher_.get(), source);
56 56
57 const net::URLRequestStatus& status = source->GetStatus(); 57 const net::URLRequestStatus& status = source->GetStatus();
58 if (!status.is_success()) { 58 if (!status.is_success()) {
59 DLOG(WARNING) << "URLRequestStatus error " << status.error() 59 DLOG(WARNING) << "URLRequestStatus error " << status.error()
60 << " while trying to download " << source->GetURL().spec(); 60 << " while trying to download " << source->GetURL().spec();
61 callback_.Run(false); 61 callback_.Run(FAILED);
62 return; 62 return;
63 } 63 }
64 64
65 int response_code = source->GetResponseCode(); 65 int response_code = source->GetResponseCode();
66 if (response_code != net::HTTP_OK) { 66 if (response_code != net::HTTP_OK) {
67 DLOG(WARNING) << "HTTP error " << response_code 67 DLOG(WARNING) << "HTTP error " << response_code
68 << " while trying to download " << source->GetURL().spec(); 68 << " while trying to download " << source->GetURL().spec();
69 callback_.Run(false); 69 callback_.Run(FAILED);
70 return; 70 return;
71 } 71 }
72 72
73 base::FilePath response_path; 73 base::FilePath response_path;
74 bool success = source->GetResponseAsFilePath(false, &response_path); 74 bool success = source->GetResponseAsFilePath(false, &response_path);
75 if (!success) { 75 if (!success) {
76 callback_.Run(false); 76 callback_.Run(FAILED);
77 return; 77 return;
78 } 78 }
79 79
80 base::PostTaskAndReplyWithResult( 80 base::PostTaskAndReplyWithResult(
81 BrowserThread::GetBlockingPool() 81 BrowserThread::GetBlockingPool()
82 ->GetTaskRunnerWithShutdownBehavior( 82 ->GetTaskRunnerWithShutdownBehavior(
83 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN) 83 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN)
84 .get(), 84 .get(),
85 FROM_HERE, base::Bind(&base::Move, response_path, local_path_), 85 FROM_HERE, base::Bind(&base::Move, response_path, local_path_),
86 base::Bind(&FileDownloader::OnFileMoveDone, 86 base::Bind(&FileDownloader::OnFileMoveDone,
87 weak_ptr_factory_.GetWeakPtr())); 87 weak_ptr_factory_.GetWeakPtr()));
88 } 88 }
89 89
90 void FileDownloader::OnFileExistsCheckDone(bool exists) { 90 void FileDownloader::OnFileExistsCheckDone(bool exists) {
91 if (exists) 91 if (exists)
92 callback_.Run(true); 92 callback_.Run(EXISTS);
93 else 93 else
94 fetcher_->Start(); 94 fetcher_->Start();
95 } 95 }
96 96
97 void FileDownloader::OnFileMoveDone(bool success) { 97 void FileDownloader::OnFileMoveDone(bool success) {
98 if (!success) { 98 if (!success) {
99 DLOG(WARNING) << "Could not move file to " 99 DLOG(WARNING) << "Could not move file to "
100 << local_path_.LossyDisplayName(); 100 << local_path_.LossyDisplayName();
101 } 101 }
102 102
103 callback_.Run(success); 103 callback_.Run(success ? DOWNLOADED : FAILED);
104 } 104 }
OLDNEW
« no previous file with comments | « chrome/browser/net/file_downloader.h ('k') | chrome/browser/net/file_downloader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698