Chromium Code Reviews| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/task_runner.h" | 14 #include "base/task_runner.h" |
| 15 #include "components/data_use_measurement/core/data_use_user_data.h" | 15 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 18 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" |
| 19 #include "net/traffic_annotation/network_traffic_annotation.h" | |
| 19 #include "net/url_request/url_fetcher.h" | 20 #include "net/url_request/url_fetcher.h" |
| 20 #include "net/url_request/url_fetcher_delegate.h" | 21 #include "net/url_request/url_fetcher_delegate.h" |
| 21 #include "net/url_request/url_request_status.h" | 22 #include "net/url_request/url_request_status.h" |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 // Header sent on initial request to start the two phase upload process. | 26 // Header sent on initial request to start the two phase upload process. |
| 26 const char kStartHeader[] = "x-goog-resumable: start"; | 27 const char kStartHeader[] = "x-goog-resumable: start"; |
| 27 | 28 |
| 28 // Header returned on initial response with URL to use for the second phase. | 29 // Header returned on initial response with URL to use for the second phase. |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 162 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 162 DVLOG(3) << __func__ << " " << source->GetURL().spec() << " " << current | 163 DVLOG(3) << __func__ << " " << source->GetURL().spec() << " " << current |
| 163 << "/" << total; | 164 << "/" << total; |
| 164 if (state_ == UPLOAD_FILE && !progress_callback_.is_null()) | 165 if (state_ == UPLOAD_FILE && !progress_callback_.is_null()) |
| 165 progress_callback_.Run(current, total); | 166 progress_callback_.Run(current, total); |
| 166 } | 167 } |
| 167 | 168 |
| 168 void TwoPhaseUploaderImpl::UploadMetadata() { | 169 void TwoPhaseUploaderImpl::UploadMetadata() { |
| 169 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 170 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 170 state_ = UPLOAD_METADATA; | 171 state_ = UPLOAD_METADATA; |
| 171 url_fetcher_ = | 172 |
| 172 net::URLFetcher::Create(base_url_, net::URLFetcher::POST, this); | 173 // Create traffic annotation tag. |
|
mattm
2017/02/18 02:23:45
Although TwoPhaseUploader is only used in one plac
Ramin Halavati
2017/02/20 09:08:35
Done.
| |
| 174 net::NetworkTrafficAnnotationTag traffic_annotation = | |
| 175 net::DefineNetworkTrafficAnnotation("...", R"( | |
|
Nathan Parker
2017/02/18 22:16:55
Is there a doc describing the intention of these f
Ramin Halavati
2017/02/20 09:08:35
Yes, there are references on the first email on th
| |
| 176 semantics { | |
| 177 sender: "..." | |
| 178 description: "..." | |
| 179 trigger: "..." | |
| 180 data: "..." | |
| 181 destination: WEBSITE/GOOGLE_OWNED_SERVICE/OTHER | |
| 182 } | |
| 183 policy { | |
| 184 cookies_allowed: false/true | |
| 185 cookies_store: "..." | |
| 186 setting: "..." | |
| 187 policy { | |
| 188 [POLICY_NAME] { | |
| 189 policy_options {mode: MANDATORY/RECOMMENDED/UNSET} | |
| 190 value: ... | |
| 191 } | |
| 192 } | |
| 193 policy_exception_justification: "..." | |
| 194 })"); | |
| 195 | |
| 196 url_fetcher_ = net::URLFetcher::Create(base_url_, net::URLFetcher::POST, this, | |
| 197 traffic_annotation); | |
| 173 data_use_measurement::DataUseUserData::AttachToFetcher( | 198 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 174 url_fetcher_.get(), data_use_measurement::DataUseUserData::SAFE_BROWSING); | 199 url_fetcher_.get(), data_use_measurement::DataUseUserData::SAFE_BROWSING); |
| 175 url_fetcher_->SetRequestContext(url_request_context_getter_.get()); | 200 url_fetcher_->SetRequestContext(url_request_context_getter_.get()); |
| 176 url_fetcher_->SetExtraRequestHeaders(kStartHeader); | 201 url_fetcher_->SetExtraRequestHeaders(kStartHeader); |
| 177 url_fetcher_->SetUploadData(kUploadContentType, metadata_); | 202 url_fetcher_->SetUploadData(kUploadContentType, metadata_); |
| 178 url_fetcher_->Start(); | 203 url_fetcher_->Start(); |
| 179 } | 204 } |
| 180 | 205 |
| 181 void TwoPhaseUploaderImpl::UploadFile() { | 206 void TwoPhaseUploaderImpl::UploadFile() { |
| 182 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 207 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 183 state_ = UPLOAD_FILE; | 208 state_ = UPLOAD_FILE; |
| 184 | 209 |
| 185 url_fetcher_ = | 210 // Create traffic annotation tag. |
| 186 net::URLFetcher::Create(upload_url_, net::URLFetcher::PUT, this); | 211 net::NetworkTrafficAnnotationTag traffic_annotation = |
| 212 net::DefineNetworkTrafficAnnotation("...", R"( | |
| 213 semantics { | |
| 214 sender: "..." | |
| 215 description: "..." | |
| 216 trigger: "..." | |
| 217 data: "..." | |
| 218 destination: WEBSITE/GOOGLE_OWNED_SERVICE/OTHER | |
| 219 } | |
| 220 policy { | |
| 221 cookies_allowed: false/true | |
| 222 cookies_store: "..." | |
| 223 setting: "..." | |
| 224 policy { | |
| 225 [POLICY_NAME] { | |
| 226 policy_options {mode: MANDATORY/RECOMMENDED/UNSET} | |
| 227 value: ... | |
| 228 } | |
| 229 } | |
| 230 policy_exception_justification: "..." | |
| 231 })"); | |
| 232 | |
| 233 url_fetcher_ = net::URLFetcher::Create(upload_url_, net::URLFetcher::PUT, | |
| 234 this, traffic_annotation); | |
| 187 data_use_measurement::DataUseUserData::AttachToFetcher( | 235 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 188 url_fetcher_.get(), data_use_measurement::DataUseUserData::SAFE_BROWSING); | 236 url_fetcher_.get(), data_use_measurement::DataUseUserData::SAFE_BROWSING); |
| 189 url_fetcher_->SetRequestContext(url_request_context_getter_.get()); | 237 url_fetcher_->SetRequestContext(url_request_context_getter_.get()); |
| 190 url_fetcher_->SetUploadFilePath(kUploadContentType, file_path_, 0, | 238 url_fetcher_->SetUploadFilePath(kUploadContentType, file_path_, 0, |
| 191 std::numeric_limits<uint64_t>::max(), | 239 std::numeric_limits<uint64_t>::max(), |
| 192 file_task_runner_); | 240 file_task_runner_); |
| 193 url_fetcher_->Start(); | 241 url_fetcher_->Start(); |
| 194 } | 242 } |
| 195 | 243 |
| 196 void TwoPhaseUploaderImpl::Finish(int net_error, | 244 void TwoPhaseUploaderImpl::Finish(int net_error, |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 216 const FinishCallback& finish_callback) { | 264 const FinishCallback& finish_callback) { |
| 217 if (!factory_) { | 265 if (!factory_) { |
| 218 return base::WrapUnique(new TwoPhaseUploaderImpl( | 266 return base::WrapUnique(new TwoPhaseUploaderImpl( |
| 219 url_request_context_getter, file_task_runner, base_url, metadata, | 267 url_request_context_getter, file_task_runner, base_url, metadata, |
| 220 file_path, progress_callback, finish_callback)); | 268 file_path, progress_callback, finish_callback)); |
| 221 } | 269 } |
| 222 return TwoPhaseUploader::factory_->CreateTwoPhaseUploader( | 270 return TwoPhaseUploader::factory_->CreateTwoPhaseUploader( |
| 223 url_request_context_getter, file_task_runner, base_url, metadata, | 271 url_request_context_getter, file_task_runner, base_url, metadata, |
| 224 file_path, progress_callback, finish_callback); | 272 file_path, progress_callback, finish_callback); |
| 225 } | 273 } |
| OLD | NEW |