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