OLD | NEW |
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 "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/task_runner.h" | 9 #include "base/task_runner.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 << " " << current << "/" << total; | 155 << " " << current << "/" << total; |
156 if (state_ == UPLOAD_FILE) | 156 if (state_ == UPLOAD_FILE) |
157 progress_callback_.Run(current, total); | 157 progress_callback_.Run(current, total); |
158 } | 158 } |
159 | 159 |
160 void TwoPhaseUploaderImpl::UploadMetadata() { | 160 void TwoPhaseUploaderImpl::UploadMetadata() { |
161 DCHECK(CalledOnValidThread()); | 161 DCHECK(CalledOnValidThread()); |
162 state_ = UPLOAD_METADATA; | 162 state_ = UPLOAD_METADATA; |
163 url_fetcher_.reset(net::URLFetcher::Create(base_url_, net::URLFetcher::POST, | 163 url_fetcher_.reset(net::URLFetcher::Create(base_url_, net::URLFetcher::POST, |
164 this)); | 164 this)); |
165 url_fetcher_->SetRequestContext(url_request_context_getter_); | 165 url_fetcher_->SetRequestContext(url_request_context_getter_.get()); |
166 url_fetcher_->SetExtraRequestHeaders(kStartHeader); | 166 url_fetcher_->SetExtraRequestHeaders(kStartHeader); |
167 url_fetcher_->SetUploadData(kUploadContentType, metadata_); | 167 url_fetcher_->SetUploadData(kUploadContentType, metadata_); |
168 url_fetcher_->Start(); | 168 url_fetcher_->Start(); |
169 } | 169 } |
170 | 170 |
171 void TwoPhaseUploaderImpl::UploadFile() { | 171 void TwoPhaseUploaderImpl::UploadFile() { |
172 DCHECK(CalledOnValidThread()); | 172 DCHECK(CalledOnValidThread()); |
173 state_ = UPLOAD_FILE; | 173 state_ = UPLOAD_FILE; |
174 | 174 |
175 url_fetcher_.reset(net::URLFetcher::Create(upload_url_, net::URLFetcher::PUT, | 175 url_fetcher_.reset(net::URLFetcher::Create(upload_url_, net::URLFetcher::PUT, |
176 this)); | 176 this)); |
177 url_fetcher_->SetRequestContext(url_request_context_getter_); | 177 url_fetcher_->SetRequestContext(url_request_context_getter_.get()); |
178 url_fetcher_->SetUploadFilePath(kUploadContentType, | 178 url_fetcher_->SetUploadFilePath( |
179 file_path_, | 179 kUploadContentType, file_path_, 0, kuint64max, file_task_runner_); |
180 0, | |
181 kuint64max, | |
182 file_task_runner_); | |
183 url_fetcher_->Start(); | 180 url_fetcher_->Start(); |
184 } | 181 } |
185 | 182 |
186 void TwoPhaseUploaderImpl::Finish(int net_error, | 183 void TwoPhaseUploaderImpl::Finish(int net_error, |
187 int response_code, | 184 int response_code, |
188 const std::string& response) { | 185 const std::string& response) { |
189 DCHECK(CalledOnValidThread()); | 186 DCHECK(CalledOnValidThread()); |
190 finish_callback_.Run(state_, net_error, response_code, response); | 187 finish_callback_.Run(state_, net_error, response_code, response); |
191 } | 188 } |
192 | 189 |
(...skipping 12 matching lines...) Expand all Loading... |
205 const ProgressCallback& progress_callback, | 202 const ProgressCallback& progress_callback, |
206 const FinishCallback& finish_callback) { | 203 const FinishCallback& finish_callback) { |
207 if (!TwoPhaseUploader::factory_) | 204 if (!TwoPhaseUploader::factory_) |
208 return new TwoPhaseUploaderImpl( | 205 return new TwoPhaseUploaderImpl( |
209 url_request_context_getter, file_task_runner, base_url, metadata, | 206 url_request_context_getter, file_task_runner, base_url, metadata, |
210 file_path, progress_callback, finish_callback); | 207 file_path, progress_callback, finish_callback); |
211 return TwoPhaseUploader::factory_->CreateTwoPhaseUploader( | 208 return TwoPhaseUploader::factory_->CreateTwoPhaseUploader( |
212 url_request_context_getter, file_task_runner, base_url, metadata, | 209 url_request_context_getter, file_task_runner, base_url, metadata, |
213 file_path, progress_callback, finish_callback); | 210 file_path, progress_callback, finish_callback); |
214 } | 211 } |
OLD | NEW |