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

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::NetworkTrafficAnnotationTag traffic_annotation =
34 net::URLFetcher::Create(GURL(server_url_), net::URLFetcher::POST, this); 35 net::DefineNetworkTrafficAnnotation("metrics_report", R"(
Alexei Svitkine (slow) 2017/02/27 15:42:56 This is only correct for the MetricsLogUploader::U
Ramin Halavati 2017/02/27 18:17:23 I separate the two cases.
36 semantics {
37 sender: "Metrics Log Uploader"
38 description:
39 "Report of usage statistics and crash-related data about Google "
40 "Chrome. Usage statistics contain information such as preferences, "
41 "button clicks, and memory usage and do not include web page URLs "
42 "or personal information. See more at "
43 "https://www.google.com/chrome/browser/privacy/ under 'Usage "
44 "statistics and crash reports'."
45 trigger:
46 "Reports are automatically generated on startup and at intervals "
47 "while Chrome is running."
48 data:
49 "A protocol buffer with usage statistics and crash related data."
50 destination: GOOGLE_OWNED_SERVICE
51 }
52 policy {
53 cookies_allowed: false
54 setting:
55 "Users can enable or disable this feature by disabling "
56 "'Automatically send usage statistics and crash reports to Google' "
57 "in Chrome's settings under Advanced Settings, Privacy. The "
58 "feature is enabled by default."
59 policy {
60 MetricsReportingEnabled {
61 policy_options {mode: MANDATORY}
62 value: false
63 }
64 }
65 })");
66 current_fetch_ = net::URLFetcher::Create(
67 GURL(server_url_), net::URLFetcher::POST, this, traffic_annotation);
35 68
36 auto service = data_use_measurement::DataUseUserData::UMA; 69 auto service = data_use_measurement::DataUseUserData::UMA;
37 70
38 switch (service_type_) { 71 switch (service_type_) {
39 case MetricsLogUploader::UMA: 72 case MetricsLogUploader::UMA:
40 service = data_use_measurement::DataUseUserData::UMA; 73 service = data_use_measurement::DataUseUserData::UMA;
41 break; 74 break;
42 case MetricsLogUploader::UKM: 75 case MetricsLogUploader::UKM:
43 service = data_use_measurement::DataUseUserData::UKM; 76 service = data_use_measurement::DataUseUserData::UKM;
44 break; 77 break;
45 } 78 }
46 data_use_measurement::DataUseUserData::AttachToFetcher(current_fetch_.get(), 79 data_use_measurement::DataUseUserData::AttachToFetcher(current_fetch_.get(),
47 service); 80 service);
81
48 current_fetch_->SetRequestContext(request_context_getter_); 82 current_fetch_->SetRequestContext(request_context_getter_);
49 current_fetch_->SetUploadData(mime_type_, compressed_log_data); 83 current_fetch_->SetUploadData(mime_type_, compressed_log_data);
50 84
51 // Tell the server that we're uploading gzipped protobufs. 85 // Tell the server that we're uploading gzipped protobufs.
52 current_fetch_->SetExtraRequestHeaders("content-encoding: gzip"); 86 current_fetch_->SetExtraRequestHeaders("content-encoding: gzip");
53 87
54 DCHECK(!log_hash.empty()); 88 DCHECK(!log_hash.empty());
55 current_fetch_->AddExtraRequestHeader("X-Chrome-UMA-Log-SHA1: " + log_hash); 89 current_fetch_->AddExtraRequestHeader("X-Chrome-UMA-Log-SHA1: " + log_hash);
56 90
57 // Drop cookies and auth data. 91 // Drop cookies and auth data.
(...skipping 10 matching lines...) Expand all
68 DCHECK_EQ(current_fetch_.get(), source); 102 DCHECK_EQ(current_fetch_.get(), source);
69 103
70 int response_code = source->GetResponseCode(); 104 int response_code = source->GetResponseCode();
71 if (response_code == net::URLFetcher::RESPONSE_CODE_INVALID) 105 if (response_code == net::URLFetcher::RESPONSE_CODE_INVALID)
72 response_code = -1; 106 response_code = -1;
73 current_fetch_.reset(); 107 current_fetch_.reset();
74 on_upload_complete_.Run(response_code); 108 on_upload_complete_.Run(response_code);
75 } 109 }
76 110
77 } // namespace metrics 111 } // 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