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

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

Issue 2276933003: Add data usage tracking for safe browsing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 2 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
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 <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 "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
16 #include "net/base/net_errors.h" 17 #include "net/base/net_errors.h"
17 #include "net/http/http_response_headers.h" 18 #include "net/http/http_response_headers.h"
18 #include "net/url_request/url_fetcher.h" 19 #include "net/url_request/url_fetcher.h"
19 #include "net/url_request/url_fetcher_delegate.h" 20 #include "net/url_request/url_fetcher_delegate.h"
20 #include "net/url_request/url_request_status.h" 21 #include "net/url_request/url_request_status.h"
21 22
22 namespace { 23 namespace {
23 24
24 // Header sent on initial request to start the two phase upload process. 25 // Header sent on initial request to start the two phase upload process.
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 << "/" << total; 163 << "/" << total;
163 if (state_ == UPLOAD_FILE && !progress_callback_.is_null()) 164 if (state_ == UPLOAD_FILE && !progress_callback_.is_null())
164 progress_callback_.Run(current, total); 165 progress_callback_.Run(current, total);
165 } 166 }
166 167
167 void TwoPhaseUploaderImpl::UploadMetadata() { 168 void TwoPhaseUploaderImpl::UploadMetadata() {
168 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 169 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
169 state_ = UPLOAD_METADATA; 170 state_ = UPLOAD_METADATA;
170 url_fetcher_ = 171 url_fetcher_ =
171 net::URLFetcher::Create(base_url_, net::URLFetcher::POST, this); 172 net::URLFetcher::Create(base_url_, net::URLFetcher::POST, this);
173 data_use_measurement::DataUseUserData::AttachToFetcher(
174 url_fetcher_.get(), data_use_measurement::DataUseUserData::SAFE_BROWSING);
172 url_fetcher_->SetRequestContext(url_request_context_getter_.get()); 175 url_fetcher_->SetRequestContext(url_request_context_getter_.get());
173 url_fetcher_->SetExtraRequestHeaders(kStartHeader); 176 url_fetcher_->SetExtraRequestHeaders(kStartHeader);
174 url_fetcher_->SetUploadData(kUploadContentType, metadata_); 177 url_fetcher_->SetUploadData(kUploadContentType, metadata_);
175 url_fetcher_->Start(); 178 url_fetcher_->Start();
176 } 179 }
177 180
178 void TwoPhaseUploaderImpl::UploadFile() { 181 void TwoPhaseUploaderImpl::UploadFile() {
179 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 182 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
180 state_ = UPLOAD_FILE; 183 state_ = UPLOAD_FILE;
181 184
182 url_fetcher_ = 185 url_fetcher_ =
183 net::URLFetcher::Create(upload_url_, net::URLFetcher::PUT, this); 186 net::URLFetcher::Create(upload_url_, net::URLFetcher::PUT, this);
187 data_use_measurement::DataUseUserData::AttachToFetcher(
188 url_fetcher_.get(), data_use_measurement::DataUseUserData::SAFE_BROWSING);
184 url_fetcher_->SetRequestContext(url_request_context_getter_.get()); 189 url_fetcher_->SetRequestContext(url_request_context_getter_.get());
185 url_fetcher_->SetUploadFilePath(kUploadContentType, file_path_, 0, 190 url_fetcher_->SetUploadFilePath(kUploadContentType, file_path_, 0,
186 std::numeric_limits<uint64_t>::max(), 191 std::numeric_limits<uint64_t>::max(),
187 file_task_runner_); 192 file_task_runner_);
188 url_fetcher_->Start(); 193 url_fetcher_->Start();
189 } 194 }
190 195
191 void TwoPhaseUploaderImpl::Finish(int net_error, 196 void TwoPhaseUploaderImpl::Finish(int net_error,
192 int response_code, 197 int response_code,
193 const std::string& response) { 198 const std::string& response) {
(...skipping 17 matching lines...) Expand all
211 const FinishCallback& finish_callback) { 216 const FinishCallback& finish_callback) {
212 if (!factory_) { 217 if (!factory_) {
213 return base::WrapUnique(new TwoPhaseUploaderImpl( 218 return base::WrapUnique(new TwoPhaseUploaderImpl(
214 url_request_context_getter, file_task_runner, base_url, metadata, 219 url_request_context_getter, file_task_runner, base_url, metadata,
215 file_path, progress_callback, finish_callback)); 220 file_path, progress_callback, finish_callback));
216 } 221 }
217 return TwoPhaseUploader::factory_->CreateTwoPhaseUploader( 222 return TwoPhaseUploader::factory_->CreateTwoPhaseUploader(
218 url_request_context_getter, file_task_runner, base_url, metadata, 223 url_request_context_getter, file_task_runner, base_url, metadata,
219 file_path, progress_callback, finish_callback); 224 file_path, progress_callback, finish_callback);
220 } 225 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/threat_details_cache.cc ('k') | components/data_use_measurement/core/data_use_user_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698