| 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 "components/metrics/net/compression_utils.h" | |
| 9 #include "net/base/load_flags.h" | 8 #include "net/base/load_flags.h" |
| 10 #include "net/url_request/url_fetcher.h" | 9 #include "net/url_request/url_fetcher.h" |
| 11 #include "url/gurl.h" | 10 #include "url/gurl.h" |
| 12 | 11 |
| 13 namespace metrics { | 12 namespace metrics { |
| 14 | 13 |
| 15 NetMetricsLogUploader::NetMetricsLogUploader( | 14 NetMetricsLogUploader::NetMetricsLogUploader( |
| 16 net::URLRequestContextGetter* request_context_getter, | 15 net::URLRequestContextGetter* request_context_getter, |
| 17 const std::string& server_url, | 16 const std::string& server_url, |
| 18 const std::string& mime_type, | 17 const std::string& mime_type, |
| 19 const base::Callback<void(int)>& on_upload_complete) | 18 const base::Callback<void(int)>& on_upload_complete) |
| 20 : MetricsLogUploader(server_url, mime_type, on_upload_complete), | 19 : MetricsLogUploader(server_url, mime_type, on_upload_complete), |
| 21 request_context_getter_(request_context_getter) { | 20 request_context_getter_(request_context_getter) { |
| 22 } | 21 } |
| 23 | 22 |
| 24 NetMetricsLogUploader::~NetMetricsLogUploader() { | 23 NetMetricsLogUploader::~NetMetricsLogUploader() { |
| 25 } | 24 } |
| 26 | 25 |
| 27 bool NetMetricsLogUploader::UploadLog(const std::string& log_data, | 26 bool NetMetricsLogUploader::UploadLog(const std::string& compressed_log_data, |
| 28 const std::string& log_hash) { | 27 const std::string& log_hash) { |
| 29 std::string compressed_log_data; | |
| 30 if (!GzipCompress(log_data, &compressed_log_data)) { | |
| 31 NOTREACHED(); | |
| 32 return false; | |
| 33 } | |
| 34 | |
| 35 UMA_HISTOGRAM_PERCENTAGE( | |
| 36 "UMA.ProtoCompressionRatio", | |
| 37 static_cast<int>(100 * compressed_log_data.size() / log_data.size())); | |
| 38 UMA_HISTOGRAM_CUSTOM_COUNTS( | |
| 39 "UMA.ProtoGzippedKBSaved", | |
| 40 static_cast<int>((log_data.size() - compressed_log_data.size()) / 1024), | |
| 41 1, 2000, 50); | |
| 42 | |
| 43 current_fetch_.reset( | 28 current_fetch_.reset( |
| 44 net::URLFetcher::Create(GURL(server_url_), net::URLFetcher::POST, this)); | 29 net::URLFetcher::Create(GURL(server_url_), net::URLFetcher::POST, this)); |
| 45 current_fetch_->SetRequestContext(request_context_getter_); | 30 current_fetch_->SetRequestContext(request_context_getter_); |
| 46 current_fetch_->SetUploadData(mime_type_, compressed_log_data); | 31 current_fetch_->SetUploadData(mime_type_, compressed_log_data); |
| 47 | 32 |
| 48 // Tell the server that we're uploading gzipped protobufs. | 33 // Tell the server that we're uploading gzipped protobufs. |
| 49 current_fetch_->SetExtraRequestHeaders("content-encoding: gzip"); | 34 current_fetch_->SetExtraRequestHeaders("content-encoding: gzip"); |
| 50 | 35 |
| 51 DCHECK(!log_hash.empty()); | 36 DCHECK(!log_hash.empty()); |
| 52 current_fetch_->AddExtraRequestHeader("X-Chrome-UMA-Log-SHA1: " + log_hash); | 37 current_fetch_->AddExtraRequestHeader("X-Chrome-UMA-Log-SHA1: " + log_hash); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 66 DCHECK_EQ(current_fetch_.get(), source); | 51 DCHECK_EQ(current_fetch_.get(), source); |
| 67 | 52 |
| 68 int response_code = source->GetResponseCode(); | 53 int response_code = source->GetResponseCode(); |
| 69 if (response_code == net::URLFetcher::RESPONSE_CODE_INVALID) | 54 if (response_code == net::URLFetcher::RESPONSE_CODE_INVALID) |
| 70 response_code = -1; | 55 response_code = -1; |
| 71 on_upload_complete_.Run(response_code); | 56 on_upload_complete_.Run(response_code); |
| 72 current_fetch_.reset(); | 57 current_fetch_.reset(); |
| 73 } | 58 } |
| 74 | 59 |
| 75 } // namespace metrics | 60 } // namespace metrics |
| OLD | NEW |