| 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/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 { | |
| 15 | |
| 16 // Records the network connection type if upload was successful. | |
| 17 void RecordConnectionType(int response_code) { | |
| 18 if (response_code == 200) { | |
| 19 UMA_HISTOGRAM_ENUMERATION("UMA.LogUpload.ConnetionType", | |
| 20 net::NetworkChangeNotifier::GetConnectionType(), | |
| 21 net::NetworkChangeNotifier::CONNECTION_LAST); | |
| 22 } | |
| 23 } | |
| 24 | |
| 25 } // namespace | |
| 26 | |
| 27 namespace metrics { | 13 namespace metrics { |
| 28 | 14 |
| 29 NetMetricsLogUploader::NetMetricsLogUploader( | 15 NetMetricsLogUploader::NetMetricsLogUploader( |
| 30 net::URLRequestContextGetter* request_context_getter, | 16 net::URLRequestContextGetter* request_context_getter, |
| 31 const std::string& server_url, | 17 const std::string& server_url, |
| 32 const std::string& mime_type, | 18 const std::string& mime_type, |
| 33 const base::Callback<void(int)>& on_upload_complete) | 19 const base::Callback<void(int)>& on_upload_complete) |
| 34 : MetricsLogUploader(server_url, mime_type, on_upload_complete), | 20 : MetricsLogUploader(server_url, mime_type, on_upload_complete), |
| 35 request_context_getter_(request_context_getter) { | 21 request_context_getter_(request_context_getter) { |
| 36 } | 22 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 63 void NetMetricsLogUploader::OnURLFetchComplete(const net::URLFetcher* source) { | 49 void NetMetricsLogUploader::OnURLFetchComplete(const net::URLFetcher* source) { |
| 64 // We're not allowed to re-use the existing |URLFetcher|s, so free them here. | 50 // We're not allowed to re-use the existing |URLFetcher|s, so free them here. |
| 65 // Note however that |source| is aliased to the fetcher, so we should be | 51 // Note however that |source| is aliased to the fetcher, so we should be |
| 66 // careful not to delete it too early. | 52 // careful not to delete it too early. |
| 67 DCHECK_EQ(current_fetch_.get(), source); | 53 DCHECK_EQ(current_fetch_.get(), source); |
| 68 | 54 |
| 69 int response_code = source->GetResponseCode(); | 55 int response_code = source->GetResponseCode(); |
| 70 if (response_code == net::URLFetcher::RESPONSE_CODE_INVALID) | 56 if (response_code == net::URLFetcher::RESPONSE_CODE_INVALID) |
| 71 response_code = -1; | 57 response_code = -1; |
| 72 current_fetch_.reset(); | 58 current_fetch_.reset(); |
| 73 RecordConnectionType(response_code); | |
| 74 on_upload_complete_.Run(response_code); | 59 on_upload_complete_.Run(response_code); |
| 75 } | 60 } |
| 76 | 61 |
| 77 } // namespace metrics | 62 } // namespace metrics |
| OLD | NEW |