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

Side by Side Diff: components/metrics/net/net_metrics_log_uploader.cc

Issue 2703363002: Network traffic annotation added to NetMetricsLogUploader. (Closed)
Patch Set: Annotation updated. Created 3 years, 10 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
« no previous file with comments | « no previous file | 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/metrics/net/net_metrics_log_uploader.h" 5 #include "components/metrics/net/net_metrics_log_uploader.h"
6 6
7 #include "base/metrics/histogram_macros.h" 7 #include "base/metrics/histogram_macros.h"
8 #include "components/data_use_measurement/core/data_use_user_data.h" 8 #include "components/data_use_measurement/core/data_use_user_data.h"
9 #include "net/base/load_flags.h" 9 #include "net/base/load_flags.h"
10 #include "net/traffic_annotation/network_traffic_annotation.h"
10 #include "net/url_request/url_fetcher.h" 11 #include "net/url_request/url_fetcher.h"
11 #include "url/gurl.h" 12 #include "url/gurl.h"
12 13
13 namespace metrics { 14 namespace metrics {
14 15
15 NetMetricsLogUploader::NetMetricsLogUploader( 16 NetMetricsLogUploader::NetMetricsLogUploader(
16 net::URLRequestContextGetter* request_context_getter, 17 net::URLRequestContextGetter* request_context_getter,
17 const std::string& server_url, 18 const std::string& server_url,
18 const std::string& mime_type, 19 const std::string& mime_type,
19 const base::Callback<void(int)>& on_upload_complete) 20 const base::Callback<void(int)>& on_upload_complete)
20 : MetricsLogUploader(server_url, mime_type, on_upload_complete), 21 : MetricsLogUploader(server_url, mime_type, on_upload_complete),
21 request_context_getter_(request_context_getter) { 22 request_context_getter_(request_context_getter) {
22 } 23 }
23 24
24 NetMetricsLogUploader::~NetMetricsLogUploader() { 25 NetMetricsLogUploader::~NetMetricsLogUploader() {
25 } 26 }
26 27
27 void NetMetricsLogUploader::UploadLog(const std::string& compressed_log_data, 28 void NetMetricsLogUploader::UploadLog(const std::string& compressed_log_data,
28 const std::string& log_hash) { 29 const std::string& log_hash) {
29 current_fetch_ = 30 net::NetworkTrafficAnnotationTag traffic_annotation =
30 net::URLFetcher::Create(GURL(server_url_), net::URLFetcher::POST, this); 31 net::DefineNetworkTrafficAnnotation("metrics_report", R"(
32 semantics {
33 sender: "Metrics Log Uploader"
34 description:
35 "Report of usage statistics and crash-related data about Google "
36 "Chrome."
Ramin Halavati 2017/02/22 11:48:08 Would you like to add any details here, like examp
Steven Holte 2017/02/22 20:10:46 The best links might be this one: https://support
Ramin Halavati 2017/02/23 06:57:12 Thanks.
37 trigger: "Reports are automatically generated."
Ramin Halavati 2017/02/22 11:48:09 Would you like to add any occasion, interval, etc.
Steven Holte 2017/02/22 20:10:47 Currently the reports are generated on startup, an
Ramin Halavati 2017/02/23 06:57:12 Done.
38 data:
39 "A protocol buffer with usage statistics and crash related data."
40 destination: GOOGLE_OWNED_SERVICE
41 }
42 policy {
43 cookies_allowed: false
44 setting:
45 "Users can enable or disable this feature by stoping "
46 "'Automatically send usage statistics and crash reports to Google' "
47 "in Chrome's settings under Advanced Settings, Privacy. The "
48 "feature is enabled by default."
49 policy {
50 MetricsReportingEnabled {
51 policy_options {mode: MANDATORY}
52 value: false
53 }
54 }
55 })");
56 current_fetch_ = net::URLFetcher::Create(
57 GURL(server_url_), net::URLFetcher::POST, this, traffic_annotation);
31 data_use_measurement::DataUseUserData::AttachToFetcher( 58 data_use_measurement::DataUseUserData::AttachToFetcher(
32 current_fetch_.get(), data_use_measurement::DataUseUserData::UMA); 59 current_fetch_.get(), data_use_measurement::DataUseUserData::UMA);
33 current_fetch_->SetRequestContext(request_context_getter_); 60 current_fetch_->SetRequestContext(request_context_getter_);
34 current_fetch_->SetUploadData(mime_type_, compressed_log_data); 61 current_fetch_->SetUploadData(mime_type_, compressed_log_data);
35 62
36 // Tell the server that we're uploading gzipped protobufs. 63 // Tell the server that we're uploading gzipped protobufs.
37 current_fetch_->SetExtraRequestHeaders("content-encoding: gzip"); 64 current_fetch_->SetExtraRequestHeaders("content-encoding: gzip");
38 65
39 DCHECK(!log_hash.empty()); 66 DCHECK(!log_hash.empty());
40 current_fetch_->AddExtraRequestHeader("X-Chrome-UMA-Log-SHA1: " + log_hash); 67 current_fetch_->AddExtraRequestHeader("X-Chrome-UMA-Log-SHA1: " + log_hash);
(...skipping 12 matching lines...) Expand all
53 DCHECK_EQ(current_fetch_.get(), source); 80 DCHECK_EQ(current_fetch_.get(), source);
54 81
55 int response_code = source->GetResponseCode(); 82 int response_code = source->GetResponseCode();
56 if (response_code == net::URLFetcher::RESPONSE_CODE_INVALID) 83 if (response_code == net::URLFetcher::RESPONSE_CODE_INVALID)
57 response_code = -1; 84 response_code = -1;
58 current_fetch_.reset(); 85 current_fetch_.reset();
59 on_upload_complete_.Run(response_code); 86 on_upload_complete_.Run(response_code);
60 } 87 }
61 88
62 } // namespace metrics 89 } // namespace metrics
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698