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 "net/base/load_flags.h" | 9 #include "net/base/load_flags.h" |
9 #include "net/base/network_change_notifier.h" | 10 #include "net/base/network_change_notifier.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 { | 14 namespace { |
14 | 15 |
15 // Records the network connection type if upload was successful. | 16 // Records the network connection type if upload was successful. |
16 void RecordConnectionType(int response_code) { | 17 void RecordConnectionType(int response_code) { |
17 if (response_code == 200) { | 18 if (response_code == 200) { |
(...skipping 16 matching lines...) Expand all Loading... |
34 request_context_getter_(request_context_getter) { | 35 request_context_getter_(request_context_getter) { |
35 } | 36 } |
36 | 37 |
37 NetMetricsLogUploader::~NetMetricsLogUploader() { | 38 NetMetricsLogUploader::~NetMetricsLogUploader() { |
38 } | 39 } |
39 | 40 |
40 void NetMetricsLogUploader::UploadLog(const std::string& compressed_log_data, | 41 void NetMetricsLogUploader::UploadLog(const std::string& compressed_log_data, |
41 const std::string& log_hash) { | 42 const std::string& log_hash) { |
42 current_fetch_ = | 43 current_fetch_ = |
43 net::URLFetcher::Create(GURL(server_url_), net::URLFetcher::POST, this); | 44 net::URLFetcher::Create(GURL(server_url_), net::URLFetcher::POST, this); |
| 45 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 46 current_fetch_.get(), data_use_measurement::DataUseUserData::UMA); |
44 current_fetch_->SetRequestContext(request_context_getter_); | 47 current_fetch_->SetRequestContext(request_context_getter_); |
45 current_fetch_->SetUploadData(mime_type_, compressed_log_data); | 48 current_fetch_->SetUploadData(mime_type_, compressed_log_data); |
46 | 49 |
47 // Tell the server that we're uploading gzipped protobufs. | 50 // Tell the server that we're uploading gzipped protobufs. |
48 current_fetch_->SetExtraRequestHeaders("content-encoding: gzip"); | 51 current_fetch_->SetExtraRequestHeaders("content-encoding: gzip"); |
49 | 52 |
50 DCHECK(!log_hash.empty()); | 53 DCHECK(!log_hash.empty()); |
51 current_fetch_->AddExtraRequestHeader("X-Chrome-UMA-Log-SHA1: " + log_hash); | 54 current_fetch_->AddExtraRequestHeader("X-Chrome-UMA-Log-SHA1: " + log_hash); |
52 | 55 |
53 // We already drop cookies server-side, but we might as well strip them out | 56 // We already drop cookies server-side, but we might as well strip them out |
(...skipping 11 matching lines...) Expand all Loading... |
65 | 68 |
66 int response_code = source->GetResponseCode(); | 69 int response_code = source->GetResponseCode(); |
67 if (response_code == net::URLFetcher::RESPONSE_CODE_INVALID) | 70 if (response_code == net::URLFetcher::RESPONSE_CODE_INVALID) |
68 response_code = -1; | 71 response_code = -1; |
69 current_fetch_.reset(); | 72 current_fetch_.reset(); |
70 RecordConnectionType(response_code); | 73 RecordConnectionType(response_code); |
71 on_upload_complete_.Run(response_code); | 74 on_upload_complete_.Run(response_code); |
72 } | 75 } |
73 | 76 |
74 } // namespace metrics | 77 } // namespace metrics |
OLD | NEW |