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

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 net::NetworkTrafficAnnotationTag traffic_annotation =
36 NO_TRAFFIC_ANNOTATION_YET;
38 switch (service_type_) { 37 switch (service_type_) {
39 case MetricsLogUploader::UMA: 38 case MetricsLogUploader::UMA:
40 service = data_use_measurement::DataUseUserData::UMA; 39 service = data_use_measurement::DataUseUserData::UMA;
40 traffic_annotation =
41 net::DefineNetworkTrafficAnnotation("metrics_report_uma", R"(
42 semantics {
43 sender: "Metrics Log Uploader"
44 description:
45 "Report of usage statistics and crash-related data about "
46 "Chromium. Usage statistics contain information such as "
47 "preferences, button clicks, and memory usage and do not "
48 "include web page URLs or personal information. See more at "
49 "https://www.google.com/chrome/browser/privacy/ under 'Usage "
50 "statistics and crash reports'."
51 trigger:
52 "Reports are automatically generated on startup and at "
53 "intervals while Chromium is running."
54 data:
55 "A protocol buffer with usage statistics and crash related "
56 "data."
57 destination: GOOGLE_OWNED_SERVICE
58 }
59 policy {
60 cookies_allowed: false
61 setting:
62 "Users can enable or disable this feature by disabling "
63 "'Automatically send usage statistics and crash reports to "
64 "Google' in Chromium's settings under Advanced Settings, "
65 "Privacy. The feature is enabled by default."
66 policy {
67 MetricsReportingEnabled {
68 policy_options {mode: MANDATORY}
69 value: false
70 }
71 }
72 })");
41 break; 73 break;
42 case MetricsLogUploader::UKM: 74 case MetricsLogUploader::UKM:
43 service = data_use_measurement::DataUseUserData::UKM; 75 service = data_use_measurement::DataUseUserData::UKM;
76 traffic_annotation =
77 net::DefineNetworkTrafficAnnotation("metrics_report_ukm", R"(
78 semantics {
79 sender: "Metrics Log Uploader"
rkaplow 2017/03/02 00:18:28 you mention it doesn't need to be unique, but seem
Ramin Halavati 2017/03/02 06:13:16 Done.
80 description:
81 "Report of usage statistics and crash-related data about "
rkaplow 2017/03/02 00:18:28 Report of usage statistics that are keyed by URLs
82 "Chromium. Usage statistics contain information such as "
83 "preferences, button clicks, and memory usage and do not "
84 "include web page URLs or personal information. See more at "
85 "https://www.google.com/chrome/browser/privacy/ under 'Usage "
86 "statistics and crash reports'."
87 trigger:
88 "Reports are automatically generated on startup and at "
89 "intervals while Chromium is running."
rkaplow 2017/03/02 00:18:28 ... running with Sync enabled.
Ramin Halavati 2017/03/02 06:13:17 Done.
90 data:
91 "A protocol buffer with usage statistics and crash related "
rkaplow 2017/03/02 00:18:28 "A protocol buffer with usage statistics and assoc
Ramin Halavati 2017/03/02 06:13:17 Done.
92 "data."
93 destination: GOOGLE_OWNED_SERVICE
94 }
95 policy {
96 cookies_allowed: false
97 setting:
98 "Users can enable or disable this feature by disabling "
rkaplow 2017/03/02 00:18:28 Users can enable or disable this feature by disabl
Ramin Halavati 2017/03/02 06:13:16 Done.
99 "'Automatically send usage statistics and crash reports to "
100 "Google' in Chromium's settings under Advanced Settings, "
101 "Privacy. The feature is enabled by default."
102 policy {
103 MetricsReportingEnabled {
104 policy_options {mode: MANDATORY}
105 value: false
106 }
107 }
108 })");
44 break; 109 break;
45 } 110 }
111 current_fetch_ = net::URLFetcher::Create(
112 GURL(server_url_), net::URLFetcher::POST, this, traffic_annotation);
113
46 data_use_measurement::DataUseUserData::AttachToFetcher(current_fetch_.get(), 114 data_use_measurement::DataUseUserData::AttachToFetcher(current_fetch_.get(),
47 service); 115 service);
116
48 current_fetch_->SetRequestContext(request_context_getter_); 117 current_fetch_->SetRequestContext(request_context_getter_);
49 current_fetch_->SetUploadData(mime_type_, compressed_log_data); 118 current_fetch_->SetUploadData(mime_type_, compressed_log_data);
50 119
51 // Tell the server that we're uploading gzipped protobufs. 120 // Tell the server that we're uploading gzipped protobufs.
52 current_fetch_->SetExtraRequestHeaders("content-encoding: gzip"); 121 current_fetch_->SetExtraRequestHeaders("content-encoding: gzip");
53 122
54 DCHECK(!log_hash.empty()); 123 DCHECK(!log_hash.empty());
55 current_fetch_->AddExtraRequestHeader("X-Chrome-UMA-Log-SHA1: " + log_hash); 124 current_fetch_->AddExtraRequestHeader("X-Chrome-UMA-Log-SHA1: " + log_hash);
56 125
57 // Drop cookies and auth data. 126 // Drop cookies and auth data.
(...skipping 10 matching lines...) Expand all
68 DCHECK_EQ(current_fetch_.get(), source); 137 DCHECK_EQ(current_fetch_.get(), source);
69 138
70 int response_code = source->GetResponseCode(); 139 int response_code = source->GetResponseCode();
71 if (response_code == net::URLFetcher::RESPONSE_CODE_INVALID) 140 if (response_code == net::URLFetcher::RESPONSE_CODE_INVALID)
72 response_code = -1; 141 response_code = -1;
73 current_fetch_.reset(); 142 current_fetch_.reset();
74 on_upload_complete_.Run(response_code); 143 on_upload_complete_.Run(response_code);
75 } 144 }
76 145
77 } // namespace metrics 146 } // 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