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

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

Issue 2703363002: Network traffic annotation added to NetMetricsLogUploader. (Closed)
Patch Set: nits Created 3 years, 9 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 "components/metrics/metrics_log_uploader.h" 9 #include "components/metrics/metrics_log_uploader.h"
10 #include "net/base/load_flags.h" 10 #include "net/base/load_flags.h"
11 #include "net/traffic_annotation/network_traffic_annotation.h"
11 #include "net/url_request/url_fetcher.h" 12 #include "net/url_request/url_fetcher.h"
12 #include "url/gurl.h" 13 #include "url/gurl.h"
13 14
14 namespace metrics { 15 namespace metrics {
15 16
16 NetMetricsLogUploader::NetMetricsLogUploader( 17 NetMetricsLogUploader::NetMetricsLogUploader(
17 net::URLRequestContextGetter* request_context_getter, 18 net::URLRequestContextGetter* request_context_getter,
18 const std::string& server_url, 19 const std::string& server_url,
19 const std::string& mime_type, 20 const std::string& mime_type,
20 MetricsLogUploader::MetricServiceType service_type, 21 MetricsLogUploader::MetricServiceType service_type,
21 const base::Callback<void(int)>& on_upload_complete) 22 const base::Callback<void(int)>& on_upload_complete)
22 : MetricsLogUploader(server_url, 23 : MetricsLogUploader(server_url,
23 mime_type, 24 mime_type,
24 service_type, 25 service_type,
25 on_upload_complete), 26 on_upload_complete),
26 request_context_getter_(request_context_getter) {} 27 request_context_getter_(request_context_getter) {}
27 28
28 NetMetricsLogUploader::~NetMetricsLogUploader() { 29 NetMetricsLogUploader::~NetMetricsLogUploader() {
29 } 30 }
30 31
31 void NetMetricsLogUploader::UploadLog(const std::string& compressed_log_data, 32 void NetMetricsLogUploader::UploadLog(const std::string& compressed_log_data,
32 const std::string& log_hash) { 33 const std::string& log_hash) {
33 current_fetch_ =
34 net::URLFetcher::Create(GURL(server_url_), net::URLFetcher::POST, this);
35
36 auto service = data_use_measurement::DataUseUserData::UMA; 34 auto service = data_use_measurement::DataUseUserData::UMA;
37 35
38 switch (service_type_) { 36 switch (service_type_) {
39 case MetricsLogUploader::UMA: 37 case MetricsLogUploader::UMA: {
40 service = data_use_measurement::DataUseUserData::UMA; 38 service = data_use_measurement::DataUseUserData::UMA;
39 net::NetworkTrafficAnnotationTag traffic_annotation =
Alexei Svitkine (slow) 2017/02/27 18:24:08 Can you declare NetworkTrafficAnnotationTag traffi
Ramin Halavati 2017/02/28 08:55:39 That makes the clang tool that extracts annotation
Alexei Svitkine (slow) 2017/02/28 16:01:50 I see. Please add a comment about this - so that s
battre 2017/02/28 16:06:14 Why is this the case? Didn't we discuss that we co
Ramin Halavati 2017/03/01 05:52:49 This is a different issue, I had changed it this w
40 net::DefineNetworkTrafficAnnotation("metrics_report", R"(
41 semantics {
42 sender: "Metrics Log Uploader"
43 description:
44 "Report of usage statistics and crash-related data about "
45 "Chromium. Usage statistics contain information such as "
46 "preferences, button clicks, and memory usage and do not "
47 "include web page URLs or personal information. See more at "
48 "https://www.google.com/chrome/browser/privacy/ under 'Usage "
49 "statistics and crash reports'."
50 trigger:
51 "Reports are automatically generated on startup and at "
52 "intervals while Chromium is running."
53 data:
54 "A protocol buffer with usage statistics and crash related "
55 "data."
56 destination: GOOGLE_OWNED_SERVICE
57 }
58 policy {
59 cookies_allowed: false
60 setting:
61 "Users can enable or disable this feature by disabling "
62 "'Automatically send usage statistics and crash reports to "
63 "Google' in Chromium's settings under Advanced Settings, "
64 "Privacy. The feature is enabled by default."
65 policy {
66 MetricsReportingEnabled {
67 policy_options {mode: MANDATORY}
68 value: false
69 }
70 }
71 })");
72 current_fetch_ = net::URLFetcher::Create(
73 GURL(server_url_), net::URLFetcher::POST, this, traffic_annotation);
41 break; 74 break;
42 case MetricsLogUploader::UKM: 75 }
76 case MetricsLogUploader::UKM: {
43 service = data_use_measurement::DataUseUserData::UKM; 77 service = data_use_measurement::DataUseUserData::UKM;
78 net::NetworkTrafficAnnotationTag traffic_annotation =
79 net::DefineNetworkTrafficAnnotation("metrics_report", R"(
80 semantics {
81 sender: "Metrics Log Uploader"
rkaplow 2017/02/27 22:52:58 how is the sender field used?
Ramin Halavati 2017/02/28 08:55:39 It's used in the report stating which module is ma
82 description:
83 "Report of usage statistics and crash-related data about "
rkaplow 2017/02/27 22:52:58 this is not correct for UKM. This is the draft of
Ramin Halavati 2017/02/28 08:55:39 Yes please, thank you.
84 "Chromium. Usage statistics contain information such as "
85 "preferences, button clicks, and memory usage and do not "
86 "include web page URLs or personal information. See more at "
87 "https://www.google.com/chrome/browser/privacy/ under 'Usage "
88 "statistics and crash reports'."
89 trigger:
90 "Reports are automatically generated on startup and at "
91 "intervals while Chromium is running."
92 data:
93 "A protocol buffer with usage statistics and crash related "
94 "data."
95 destination: GOOGLE_OWNED_SERVICE
96 }
97 policy {
98 cookies_allowed: false
99 setting:
100 "Users can enable or disable this feature by disabling "
rkaplow 2017/02/27 22:52:58 this is also not fully correct, you should mention
Ramin Halavati 2017/02/28 08:55:39 Could you please suggest wording for this one as w
101 "'Automatically send usage statistics and crash reports to "
102 "Google' in Chromium's settings under Advanced Settings, "
103 "Privacy. The feature is enabled by default."
104 policy {
105 MetricsReportingEnabled {
106 policy_options {mode: MANDATORY}
107 value: false
108 }
109 }
110 })");
111 current_fetch_ = net::URLFetcher::Create(
112 GURL(server_url_), net::URLFetcher::POST, this, traffic_annotation);
44 break; 113 break;
114 }
115 default: { DCHECK(false); }
Alexei Svitkine (slow) 2017/02/27 18:24:08 Compiler will error when an enum is not covered by
Ramin Halavati 2017/02/28 08:55:39 Done.
45 } 116 }
46 data_use_measurement::DataUseUserData::AttachToFetcher(current_fetch_.get(), 117 data_use_measurement::DataUseUserData::AttachToFetcher(current_fetch_.get(),
47 service); 118 service);
119
48 current_fetch_->SetRequestContext(request_context_getter_); 120 current_fetch_->SetRequestContext(request_context_getter_);
49 current_fetch_->SetUploadData(mime_type_, compressed_log_data); 121 current_fetch_->SetUploadData(mime_type_, compressed_log_data);
50 122
51 // Tell the server that we're uploading gzipped protobufs. 123 // Tell the server that we're uploading gzipped protobufs.
52 current_fetch_->SetExtraRequestHeaders("content-encoding: gzip"); 124 current_fetch_->SetExtraRequestHeaders("content-encoding: gzip");
53 125
54 DCHECK(!log_hash.empty()); 126 DCHECK(!log_hash.empty());
55 current_fetch_->AddExtraRequestHeader("X-Chrome-UMA-Log-SHA1: " + log_hash); 127 current_fetch_->AddExtraRequestHeader("X-Chrome-UMA-Log-SHA1: " + log_hash);
56 128
57 // Drop cookies and auth data. 129 // Drop cookies and auth data.
(...skipping 10 matching lines...) Expand all
68 DCHECK_EQ(current_fetch_.get(), source); 140 DCHECK_EQ(current_fetch_.get(), source);
69 141
70 int response_code = source->GetResponseCode(); 142 int response_code = source->GetResponseCode();
71 if (response_code == net::URLFetcher::RESPONSE_CODE_INVALID) 143 if (response_code == net::URLFetcher::RESPONSE_CODE_INVALID)
72 response_code = -1; 144 response_code = -1;
73 current_fetch_.reset(); 145 current_fetch_.reset();
74 on_upload_complete_.Run(response_code); 146 on_upload_complete_.Run(response_code);
75 } 147 }
76 148
77 } // namespace metrics 149 } // 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