OLD | NEW |
---|---|
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 |
15 namespace { | |
16 | |
17 net::NetworkTrafficAnnotationTag GetNetworkTrafficAnnotation( | |
18 const metrics::MetricsLogUploader::MetricServiceType& service_type) { | |
19 // The code in this function should remain so that we won't need a default | |
20 // case that does not have meaningful annotation. | |
21 if (service_type == metrics::MetricsLogUploader::UMA) { | |
22 return net::DefineNetworkTrafficAnnotation("metrics_report_uma", R"( | |
23 semantics { | |
24 sender: "Metrics UMA Log Uploader" | |
25 description: | |
26 "Report of usage statistics and crash-related data about Chromium. " | |
27 "Usage statistics contain information such as preferences, button " | |
28 "clicks, and memory usage and do not include web page URLs or " | |
29 "personal information. See more at " | |
30 "https://www.google.com/chrome/browser/privacy/ under 'Usage " | |
31 "statistics and crash reports'. Usage statistics are tied to a " | |
32 "pseudonymous machine identifier and not to your email address." | |
33 trigger: | |
34 "Reports are automatically generated on startup and at intervals " | |
35 "while Chromium is running." | |
36 data: | |
37 "A protocol buffer with usage statistics and crash related data." | |
38 destination: GOOGLE_OWNED_SERVICE | |
39 } | |
40 policy { | |
41 cookies_allowed: false | |
42 setting: | |
43 "Users can enable or disable this feature by disabling " | |
44 "'Automatically send usage statistics and crash reports to Google' " | |
45 "in Chromium's settings under Advanced Settings, Privacy. The " | |
46 "feature is enabled by default." | |
47 chrome_policy { | |
48 MetricsReportingEnabled { | |
49 policy_options {mode: MANDATORY} | |
50 MetricsReportingEnabled: false | |
51 } | |
52 } | |
53 })"); | |
54 } else { | |
55 DCHECK(service_type == metrics::MetricsLogUploader::UKM); | |
Alexei Svitkine (slow)
2017/03/09 15:51:02
Can this be DCHECK_EQ?
| |
56 return net::DefineNetworkTrafficAnnotation("metrics_report_ukm", R"( | |
57 semantics { | |
58 sender: "Metrics UKM Log Uploader" | |
59 description: | |
60 "Report of usage statistics that are keyed by URLs to Chromium, " | |
61 "sent only if the profile has History Sync. This includes " | |
62 "information about the web pages you visit and your usage of them, " | |
63 "such as page load speed. This will also include URLs and " | |
64 "statistics related to downloaded files. If Extension Sync is " | |
65 "enabled, these statistics will also include information about " | |
66 "the extensions that have been installed from Chrome Web Store. " | |
67 "Google only stores usage statistics associated with published " | |
68 "extensions, and URLs that are known by Google’s search index. " | |
69 "Usage statistics are tied to a pseudonymous machine identifier " | |
70 "and not to your email address." | |
71 trigger: | |
72 "Reports are automatically generated on startup and at intervals " | |
73 "while Chromium is running with Sync enabled." | |
74 data: | |
75 "A protocol buffer with usage statistics and associated URLs." | |
76 destination: GOOGLE_OWNED_SERVICE | |
77 } | |
78 policy { | |
79 cookies_allowed: false | |
80 setting: | |
81 "Users can enable or disable this feature by disabling " | |
82 "'Automatically send usage statistics and crash reports to Google' " | |
83 "in Chromium's settings under Advanced Settings, Privacy. This is " | |
84 "only enabled if all active profiles have History/Extension Sync " | |
85 "enabled without a Sync passphrase." | |
86 chrome_policy { | |
87 MetricsReportingEnabled { | |
88 policy_options {mode: MANDATORY} | |
89 MetricsReportingEnabled: false | |
90 } | |
91 } | |
92 })"); | |
93 } | |
94 } | |
95 | |
96 } // namespace | |
97 | |
14 namespace metrics { | 98 namespace metrics { |
15 | 99 |
16 NetMetricsLogUploader::NetMetricsLogUploader( | 100 NetMetricsLogUploader::NetMetricsLogUploader( |
17 net::URLRequestContextGetter* request_context_getter, | 101 net::URLRequestContextGetter* request_context_getter, |
18 base::StringPiece server_url, | 102 base::StringPiece server_url, |
19 base::StringPiece mime_type, | 103 base::StringPiece mime_type, |
20 MetricsLogUploader::MetricServiceType service_type, | 104 MetricsLogUploader::MetricServiceType service_type, |
21 const base::Callback<void(int)>& on_upload_complete) | 105 const base::Callback<void(int)>& on_upload_complete) |
22 : request_context_getter_(request_context_getter), | 106 : request_context_getter_(request_context_getter), |
23 server_url_(server_url), | 107 server_url_(server_url), |
24 mime_type_(mime_type.data(), mime_type.size()), | 108 mime_type_(mime_type.data(), mime_type.size()), |
25 service_type_(service_type), | 109 service_type_(service_type), |
26 on_upload_complete_(on_upload_complete) {} | 110 on_upload_complete_(on_upload_complete) {} |
27 | 111 |
28 NetMetricsLogUploader::~NetMetricsLogUploader() { | 112 NetMetricsLogUploader::~NetMetricsLogUploader() { |
29 } | 113 } |
30 | 114 |
31 void NetMetricsLogUploader::UploadLog(const std::string& compressed_log_data, | 115 void NetMetricsLogUploader::UploadLog(const std::string& compressed_log_data, |
32 const std::string& log_hash) { | 116 const std::string& log_hash) { |
33 current_fetch_ = | 117 current_fetch_ = |
34 net::URLFetcher::Create(GURL(server_url_), net::URLFetcher::POST, this); | 118 net::URLFetcher::Create(GURL(server_url_), net::URLFetcher::POST, this, |
119 GetNetworkTrafficAnnotation(service_type_)); | |
35 | 120 |
36 auto service = data_use_measurement::DataUseUserData::UMA; | 121 auto service = data_use_measurement::DataUseUserData::UMA; |
37 | 122 |
38 switch (service_type_) { | 123 switch (service_type_) { |
39 case MetricsLogUploader::UMA: | 124 case MetricsLogUploader::UMA: |
40 service = data_use_measurement::DataUseUserData::UMA; | 125 service = data_use_measurement::DataUseUserData::UMA; |
41 break; | 126 break; |
42 case MetricsLogUploader::UKM: | 127 case MetricsLogUploader::UKM: |
43 service = data_use_measurement::DataUseUserData::UKM; | 128 service = data_use_measurement::DataUseUserData::UKM; |
44 break; | 129 break; |
(...skipping 23 matching lines...) Expand all Loading... | |
68 DCHECK_EQ(current_fetch_.get(), source); | 153 DCHECK_EQ(current_fetch_.get(), source); |
69 | 154 |
70 int response_code = source->GetResponseCode(); | 155 int response_code = source->GetResponseCode(); |
71 if (response_code == net::URLFetcher::RESPONSE_CODE_INVALID) | 156 if (response_code == net::URLFetcher::RESPONSE_CODE_INVALID) |
72 response_code = -1; | 157 response_code = -1; |
73 current_fetch_.reset(); | 158 current_fetch_.reset(); |
74 on_upload_complete_.Run(response_code); | 159 on_upload_complete_.Run(response_code); |
75 } | 160 } |
76 | 161 |
77 } // namespace metrics | 162 } // namespace metrics |
OLD | NEW |