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.h" | 7 #include "base/metrics/histogram.h" |
8 #include "net/base/load_flags.h" | 8 #include "net/base/load_flags.h" |
9 #include "net/base/network_change_notifier.h" | 9 #include "net/base/network_change_notifier.h" |
10 #include "net/url_request/url_fetcher.h" | 10 #include "net/url_request/url_fetcher.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 const base::Callback<void(int)>& on_upload_complete) | 32 const base::Callback<void(int)>& on_upload_complete) |
33 : MetricsLogUploader(server_url, mime_type, on_upload_complete), | 33 : MetricsLogUploader(server_url, mime_type, on_upload_complete), |
34 request_context_getter_(request_context_getter) { | 34 request_context_getter_(request_context_getter) { |
35 } | 35 } |
36 | 36 |
37 NetMetricsLogUploader::~NetMetricsLogUploader() { | 37 NetMetricsLogUploader::~NetMetricsLogUploader() { |
38 } | 38 } |
39 | 39 |
40 bool NetMetricsLogUploader::UploadLog(const std::string& compressed_log_data, | 40 bool NetMetricsLogUploader::UploadLog(const std::string& compressed_log_data, |
41 const std::string& log_hash) { | 41 const std::string& log_hash) { |
42 current_fetch_.reset( | 42 current_fetch_ = |
43 net::URLFetcher::Create(GURL(server_url_), net::URLFetcher::POST, this)); | 43 net::URLFetcher::Create(GURL(server_url_), net::URLFetcher::POST, this); |
44 current_fetch_->SetRequestContext(request_context_getter_); | 44 current_fetch_->SetRequestContext(request_context_getter_); |
45 current_fetch_->SetUploadData(mime_type_, compressed_log_data); | 45 current_fetch_->SetUploadData(mime_type_, compressed_log_data); |
46 | 46 |
47 // Tell the server that we're uploading gzipped protobufs. | 47 // Tell the server that we're uploading gzipped protobufs. |
48 current_fetch_->SetExtraRequestHeaders("content-encoding: gzip"); | 48 current_fetch_->SetExtraRequestHeaders("content-encoding: gzip"); |
49 | 49 |
50 DCHECK(!log_hash.empty()); | 50 DCHECK(!log_hash.empty()); |
51 current_fetch_->AddExtraRequestHeader("X-Chrome-UMA-Log-SHA1: " + log_hash); | 51 current_fetch_->AddExtraRequestHeader("X-Chrome-UMA-Log-SHA1: " + log_hash); |
52 | 52 |
53 // 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 12 matching lines...) Expand all Loading... |
66 | 66 |
67 int response_code = source->GetResponseCode(); | 67 int response_code = source->GetResponseCode(); |
68 if (response_code == net::URLFetcher::RESPONSE_CODE_INVALID) | 68 if (response_code == net::URLFetcher::RESPONSE_CODE_INVALID) |
69 response_code = -1; | 69 response_code = -1; |
70 current_fetch_.reset(); | 70 current_fetch_.reset(); |
71 RecordConnectionType(response_code); | 71 RecordConnectionType(response_code); |
72 on_upload_complete_.Run(response_code); | 72 on_upload_complete_.Run(response_code); |
73 } | 73 } |
74 | 74 |
75 } // namespace metrics | 75 } // namespace metrics |
OLD | NEW |