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/url_request/url_fetcher.h" | 10 #include "net/url_request/url_fetcher.h" |
10 #include "url/gurl.h" | 11 #include "url/gurl.h" |
11 | 12 |
13 namespace { | |
14 | |
15 // Records the network connection type if upload was successful. | |
16 void RecordConnectionType(int response_code) { | |
17 if (response_code == 200) { | |
18 UMA_HISTOGRAM_ENUMERATION("UMA.LogUpload.ConnetionType", | |
19 net::NetworkChangeNotifier::GetConnectionType(), | |
20 net::NetworkChangeNotifier::CONNECTION_LAST); | |
Ilya Sherman
2015/03/25 23:10:00
If you reuse this enum, please add a comment above
gayane -on leave until 09-2017
2015/03/26 17:41:27
Done.
| |
21 } | |
22 } | |
Ilya Sherman
2015/03/25 23:10:00
nit: Please leave a blank line after this one.
gayane -on leave until 09-2017
2015/03/26 17:41:27
Done.
| |
23 } | |
Ilya Sherman
2015/03/25 23:10:00
nit: Please add a comment " // namespace"
gayane -on leave until 09-2017
2015/03/26 17:41:27
Done.
| |
24 | |
12 namespace metrics { | 25 namespace metrics { |
13 | 26 |
14 NetMetricsLogUploader::NetMetricsLogUploader( | 27 NetMetricsLogUploader::NetMetricsLogUploader( |
15 net::URLRequestContextGetter* request_context_getter, | 28 net::URLRequestContextGetter* request_context_getter, |
16 const std::string& server_url, | 29 const std::string& server_url, |
17 const std::string& mime_type, | 30 const std::string& mime_type, |
18 const base::Callback<void(int)>& on_upload_complete) | 31 const base::Callback<void(int)>& on_upload_complete) |
19 : MetricsLogUploader(server_url, mime_type, on_upload_complete), | 32 : MetricsLogUploader(server_url, mime_type, on_upload_complete), |
20 request_context_getter_(request_context_getter) { | 33 request_context_getter_(request_context_getter) { |
21 } | 34 } |
(...skipping 25 matching lines...) Expand all Loading... | |
47 void NetMetricsLogUploader::OnURLFetchComplete(const net::URLFetcher* source) { | 60 void NetMetricsLogUploader::OnURLFetchComplete(const net::URLFetcher* source) { |
48 // We're not allowed to re-use the existing |URLFetcher|s, so free them here. | 61 // We're not allowed to re-use the existing |URLFetcher|s, so free them here. |
49 // Note however that |source| is aliased to the fetcher, so we should be | 62 // Note however that |source| is aliased to the fetcher, so we should be |
50 // careful not to delete it too early. | 63 // careful not to delete it too early. |
51 DCHECK_EQ(current_fetch_.get(), source); | 64 DCHECK_EQ(current_fetch_.get(), source); |
52 | 65 |
53 int response_code = source->GetResponseCode(); | 66 int response_code = source->GetResponseCode(); |
54 if (response_code == net::URLFetcher::RESPONSE_CODE_INVALID) | 67 if (response_code == net::URLFetcher::RESPONSE_CODE_INVALID) |
55 response_code = -1; | 68 response_code = -1; |
56 current_fetch_.reset(); | 69 current_fetch_.reset(); |
70 RecordConnectionType(response_code); | |
57 on_upload_complete_.Run(response_code); | 71 on_upload_complete_.Run(response_code); |
58 } | 72 } |
59 | 73 |
60 } // namespace metrics | 74 } // namespace metrics |
OLD | NEW |