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 "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. Usage statistics contain information such as preferences, " | |
37 "button clicks, and memory usage and do not include web page URLs " | |
38 "or personal information. See more at " | |
39 "https://www.google.com/chrome/browser/privacy/ under 'Usage " | |
40 "statistics and crash reports'." | |
41 trigger: | |
42 "Reports are automatically generated on startup and at intervals " | |
43 "while chrome is running." | |
Alexei Svitkine (slow)
2017/02/23 19:32:25
Capitalize Chrome
Ramin Halavati
2017/02/24 06:23:46
Done.
| |
44 data: | |
45 "A protocol buffer with usage statistics and crash related data." | |
46 destination: GOOGLE_OWNED_SERVICE | |
47 } | |
48 policy { | |
49 cookies_allowed: false | |
50 setting: | |
51 "Users can enable or disable this feature by stoping " | |
52 "'Automatically send usage statistics and crash reports to Google' " | |
53 "in Chrome's settings under Advanced Settings, Privacy. The " | |
54 "feature is enabled by default." | |
55 policy { | |
56 MetricsReportingEnabled { | |
57 policy_options {mode: MANDATORY} | |
58 value: false | |
59 } | |
60 } | |
61 })"); | |
62 current_fetch_ = net::URLFetcher::Create( | |
63 GURL(server_url_), net::URLFetcher::POST, this, traffic_annotation); | |
31 data_use_measurement::DataUseUserData::AttachToFetcher( | 64 data_use_measurement::DataUseUserData::AttachToFetcher( |
32 current_fetch_.get(), data_use_measurement::DataUseUserData::UMA); | 65 current_fetch_.get(), data_use_measurement::DataUseUserData::UMA); |
33 current_fetch_->SetRequestContext(request_context_getter_); | 66 current_fetch_->SetRequestContext(request_context_getter_); |
34 current_fetch_->SetUploadData(mime_type_, compressed_log_data); | 67 current_fetch_->SetUploadData(mime_type_, compressed_log_data); |
35 | 68 |
36 // Tell the server that we're uploading gzipped protobufs. | 69 // Tell the server that we're uploading gzipped protobufs. |
37 current_fetch_->SetExtraRequestHeaders("content-encoding: gzip"); | 70 current_fetch_->SetExtraRequestHeaders("content-encoding: gzip"); |
38 | 71 |
39 DCHECK(!log_hash.empty()); | 72 DCHECK(!log_hash.empty()); |
40 current_fetch_->AddExtraRequestHeader("X-Chrome-UMA-Log-SHA1: " + log_hash); | 73 current_fetch_->AddExtraRequestHeader("X-Chrome-UMA-Log-SHA1: " + log_hash); |
(...skipping 12 matching lines...) Expand all Loading... | |
53 DCHECK_EQ(current_fetch_.get(), source); | 86 DCHECK_EQ(current_fetch_.get(), source); |
54 | 87 |
55 int response_code = source->GetResponseCode(); | 88 int response_code = source->GetResponseCode(); |
56 if (response_code == net::URLFetcher::RESPONSE_CODE_INVALID) | 89 if (response_code == net::URLFetcher::RESPONSE_CODE_INVALID) |
57 response_code = -1; | 90 response_code = -1; |
58 current_fetch_.reset(); | 91 current_fetch_.reset(); |
59 on_upload_complete_.Run(response_code); | 92 on_upload_complete_.Run(response_code); |
60 } | 93 } |
61 | 94 |
62 } // namespace metrics | 95 } // namespace metrics |
OLD | NEW |