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

Side by Side Diff: chrome/browser/safe_browsing/two_phase_uploader.cc

Issue 1502503004: Remove kuint64max. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@kint8
Patch Set: rebase Created 5 years 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/two_phase_uploader.h" 5 #include "chrome/browser/safe_browsing/two_phase_uploader.h"
6 6
7 #include "base/basictypes.h" 7 #include <stdint.h>
8
9 #include <limits>
10
8 #include "base/bind.h" 11 #include "base/bind.h"
9 #include "base/task_runner.h" 12 #include "base/task_runner.h"
10 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
11 #include "net/http/http_response_headers.h" 14 #include "net/http/http_response_headers.h"
12 #include "net/url_request/url_fetcher.h" 15 #include "net/url_request/url_fetcher.h"
13 #include "net/url_request/url_fetcher_delegate.h" 16 #include "net/url_request/url_fetcher_delegate.h"
14 #include "net/url_request/url_request_status.h" 17 #include "net/url_request/url_request_status.h"
15 18
16 namespace { 19 namespace {
17 20
(...skipping 16 matching lines...) Expand all
34 const ProgressCallback& progress_callback, 37 const ProgressCallback& progress_callback,
35 const FinishCallback& finish_callback); 38 const FinishCallback& finish_callback);
36 ~TwoPhaseUploaderImpl() override; 39 ~TwoPhaseUploaderImpl() override;
37 40
38 // Begins the upload process. 41 // Begins the upload process.
39 void Start() override; 42 void Start() override;
40 43
41 // net::URLFetcherDelegate implementation: 44 // net::URLFetcherDelegate implementation:
42 void OnURLFetchComplete(const net::URLFetcher* source) override; 45 void OnURLFetchComplete(const net::URLFetcher* source) override;
43 void OnURLFetchUploadProgress(const net::URLFetcher* source, 46 void OnURLFetchUploadProgress(const net::URLFetcher* source,
44 int64 current, 47 int64_t current,
45 int64 total) override; 48 int64_t total) override;
46 49
47 private: 50 private:
48 void UploadMetadata(); 51 void UploadMetadata();
49 void UploadFile(); 52 void UploadFile();
50 void Finish(int net_error, int response_code, const std::string& response); 53 void Finish(int net_error, int response_code, const std::string& response);
51 54
52 State state_; 55 State state_;
53 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; 56 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
54 scoped_refptr<base::TaskRunner> file_task_runner_; 57 scoped_refptr<base::TaskRunner> file_task_runner_;
55 GURL base_url_; 58 GURL base_url_;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 if (response_code != 200) { 139 if (response_code != 200) {
137 LOG(ERROR) << "Invalid response to upload request: " 140 LOG(ERROR) << "Invalid response to upload request: "
138 << response_code; 141 << response_code;
139 } else { 142 } else {
140 state_ = STATE_SUCCESS; 143 state_ = STATE_SUCCESS;
141 } 144 }
142 Finish(net::OK, response_code, response); 145 Finish(net::OK, response_code, response);
143 return; 146 return;
144 default: 147 default:
145 NOTREACHED(); 148 NOTREACHED();
146 }; 149 }
147 } 150 }
148 151
149 void TwoPhaseUploaderImpl::OnURLFetchUploadProgress( 152 void TwoPhaseUploaderImpl::OnURLFetchUploadProgress(
150 const net::URLFetcher* source, 153 const net::URLFetcher* source,
151 int64 current, 154 int64_t current,
152 int64 total) { 155 int64_t total) {
153 DCHECK(CalledOnValidThread()); 156 DCHECK(CalledOnValidThread());
154 DVLOG(3) << __FUNCTION__ << " " << source->GetURL().spec() 157 DVLOG(3) << __FUNCTION__ << " " << source->GetURL().spec()
155 << " " << current << "/" << total; 158 << " " << current << "/" << total;
156 if (state_ == UPLOAD_FILE && !progress_callback_.is_null()) 159 if (state_ == UPLOAD_FILE && !progress_callback_.is_null())
157 progress_callback_.Run(current, total); 160 progress_callback_.Run(current, total);
158 } 161 }
159 162
160 void TwoPhaseUploaderImpl::UploadMetadata() { 163 void TwoPhaseUploaderImpl::UploadMetadata() {
161 DCHECK(CalledOnValidThread()); 164 DCHECK(CalledOnValidThread());
162 state_ = UPLOAD_METADATA; 165 state_ = UPLOAD_METADATA;
163 url_fetcher_ = 166 url_fetcher_ =
164 net::URLFetcher::Create(base_url_, net::URLFetcher::POST, this); 167 net::URLFetcher::Create(base_url_, net::URLFetcher::POST, this);
165 url_fetcher_->SetRequestContext(url_request_context_getter_.get()); 168 url_fetcher_->SetRequestContext(url_request_context_getter_.get());
166 url_fetcher_->SetExtraRequestHeaders(kStartHeader); 169 url_fetcher_->SetExtraRequestHeaders(kStartHeader);
167 url_fetcher_->SetUploadData(kUploadContentType, metadata_); 170 url_fetcher_->SetUploadData(kUploadContentType, metadata_);
168 url_fetcher_->Start(); 171 url_fetcher_->Start();
169 } 172 }
170 173
171 void TwoPhaseUploaderImpl::UploadFile() { 174 void TwoPhaseUploaderImpl::UploadFile() {
172 DCHECK(CalledOnValidThread()); 175 DCHECK(CalledOnValidThread());
173 state_ = UPLOAD_FILE; 176 state_ = UPLOAD_FILE;
174 177
175 url_fetcher_ = 178 url_fetcher_ =
176 net::URLFetcher::Create(upload_url_, net::URLFetcher::PUT, this); 179 net::URLFetcher::Create(upload_url_, net::URLFetcher::PUT, this);
177 url_fetcher_->SetRequestContext(url_request_context_getter_.get()); 180 url_fetcher_->SetRequestContext(url_request_context_getter_.get());
178 url_fetcher_->SetUploadFilePath( 181 url_fetcher_->SetUploadFilePath(kUploadContentType, file_path_, 0,
179 kUploadContentType, file_path_, 0, kuint64max, file_task_runner_); 182 std::numeric_limits<uint64_t>::max(),
183 file_task_runner_);
180 url_fetcher_->Start(); 184 url_fetcher_->Start();
181 } 185 }
182 186
183 void TwoPhaseUploaderImpl::Finish(int net_error, 187 void TwoPhaseUploaderImpl::Finish(int net_error,
184 int response_code, 188 int response_code,
185 const std::string& response) { 189 const std::string& response) {
186 DCHECK(CalledOnValidThread()); 190 DCHECK(CalledOnValidThread());
187 finish_callback_.Run(state_, net_error, response_code, response); 191 finish_callback_.Run(state_, net_error, response_code, response);
188 } 192 }
189 193
(...skipping 12 matching lines...) Expand all
202 const ProgressCallback& progress_callback, 206 const ProgressCallback& progress_callback,
203 const FinishCallback& finish_callback) { 207 const FinishCallback& finish_callback) {
204 if (!TwoPhaseUploader::factory_) 208 if (!TwoPhaseUploader::factory_)
205 return new TwoPhaseUploaderImpl( 209 return new TwoPhaseUploaderImpl(
206 url_request_context_getter, file_task_runner, base_url, metadata, 210 url_request_context_getter, file_task_runner, base_url, metadata,
207 file_path, progress_callback, finish_callback); 211 file_path, progress_callback, finish_callback);
208 return TwoPhaseUploader::factory_->CreateTwoPhaseUploader( 212 return TwoPhaseUploader::factory_->CreateTwoPhaseUploader(
209 url_request_context_getter, file_task_runner, base_url, metadata, 213 url_request_context_getter, file_task_runner, base_url, metadata,
210 file_path, progress_callback, finish_callback); 214 file_path, progress_callback, finish_callback);
211 } 215 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698