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

Side by Side Diff: components/domain_reliability/uploader.cc

Issue 2538313002: Fix data usage tracking for domain reliability service (Closed)
Patch Set: Rebased Created 4 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
« no previous file with comments | « components/domain_reliability/uploader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/domain_reliability/uploader.h" 5 #include "components/domain_reliability/uploader.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
12 #include "base/supports_user_data.h" 12 #include "base/supports_user_data.h"
13 #include "components/data_use_measurement/core/data_use_user_data.h"
14 #include "components/domain_reliability/util.h" 13 #include "components/domain_reliability/util.h"
15 #include "net/base/load_flags.h" 14 #include "net/base/load_flags.h"
16 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
17 #include "net/http/http_response_headers.h" 16 #include "net/http/http_response_headers.h"
18 #include "net/http/http_util.h" 17 #include "net/http/http_util.h"
19 #include "net/url_request/url_fetcher.h" 18 #include "net/url_request/url_fetcher.h"
20 #include "net/url_request/url_fetcher_delegate.h" 19 #include "net/url_request/url_fetcher_delegate.h"
21 #include "net/url_request/url_request_context_getter.h" 20 #include "net/url_request/url_request_context_getter.h"
22 21
23 namespace domain_reliability { 22 namespace domain_reliability {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 VLOG(1) << "Discarding report instead of uploading."; 75 VLOG(1) << "Discarding report instead of uploading.";
77 UploadResult result; 76 UploadResult result;
78 result.status = UploadResult::SUCCESS; 77 result.status = UploadResult::SUCCESS;
79 callback.Run(result); 78 callback.Run(result);
80 return; 79 return;
81 } 80 }
82 81
83 std::unique_ptr<net::URLFetcher> owned_fetcher = 82 std::unique_ptr<net::URLFetcher> owned_fetcher =
84 net::URLFetcher::Create(0, upload_url, net::URLFetcher::POST, this); 83 net::URLFetcher::Create(0, upload_url, net::URLFetcher::POST, this);
85 net::URLFetcher* fetcher = owned_fetcher.get(); 84 net::URLFetcher* fetcher = owned_fetcher.get();
86 data_use_measurement::DataUseUserData::AttachToFetcher(
87 fetcher, data_use_measurement::DataUseUserData::DOMAIN_RELIABILITY);
88 fetcher->SetRequestContext(url_request_context_getter_.get()); 85 fetcher->SetRequestContext(url_request_context_getter_.get());
89 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | 86 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
90 net::LOAD_DO_NOT_SAVE_COOKIES); 87 net::LOAD_DO_NOT_SAVE_COOKIES);
91 fetcher->SetUploadData(kJsonMimeType, report_json); 88 fetcher->SetUploadData(kJsonMimeType, report_json);
92 fetcher->SetAutomaticallyRetryOn5xx(false); 89 fetcher->SetAutomaticallyRetryOn5xx(false);
93 fetcher->SetURLRequestUserData( 90 fetcher->SetURLRequestUserData(
94 UploadUserData::kUserDataKey, 91 UploadUserData::kUserDataKey,
95 UploadUserData::CreateCreateDataCallback(max_upload_depth + 1)); 92 UploadUserData::CreateCreateDataCallback(max_upload_depth + 1));
96 fetcher->Start(); 93 fetcher->Start();
97 94
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 // static 168 // static
172 std::unique_ptr<DomainReliabilityUploader> DomainReliabilityUploader::Create( 169 std::unique_ptr<DomainReliabilityUploader> DomainReliabilityUploader::Create(
173 MockableTime* time, 170 MockableTime* time,
174 const scoped_refptr<net::URLRequestContextGetter>& 171 const scoped_refptr<net::URLRequestContextGetter>&
175 url_request_context_getter) { 172 url_request_context_getter) {
176 return std::unique_ptr<DomainReliabilityUploader>( 173 return std::unique_ptr<DomainReliabilityUploader>(
177 new DomainReliabilityUploaderImpl(time, url_request_context_getter)); 174 new DomainReliabilityUploaderImpl(time, url_request_context_getter));
178 } 175 }
179 176
180 // static 177 // static
178 bool DomainReliabilityUploader::OriginatedFromDomainReliability(
179 const net::URLRequest& request) {
180 return request.GetUserData(UploadUserData::kUserDataKey) != nullptr;
181 }
182
183 // static
181 int DomainReliabilityUploader::GetURLRequestUploadDepth( 184 int DomainReliabilityUploader::GetURLRequestUploadDepth(
182 const net::URLRequest& request) { 185 const net::URLRequest& request) {
183 UploadUserData* data = static_cast<UploadUserData*>( 186 UploadUserData* data = static_cast<UploadUserData*>(
184 request.GetUserData(UploadUserData::kUserDataKey)); 187 request.GetUserData(UploadUserData::kUserDataKey));
185 if (!data) 188 if (!data)
186 return 0; 189 return 0;
187 return data->depth(); 190 return data->depth();
188 } 191 }
189 192
190 } // namespace domain_reliability 193 } // namespace domain_reliability
OLDNEW
« no previous file with comments | « components/domain_reliability/uploader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698