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/domain_reliability/uploader.h" | 5 #include "components/domain_reliability/uploader.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "base/metrics/sparse_histogram.h" | 10 #include "base/metrics/sparse_histogram.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/supports_user_data.h" | 12 #include "base/supports_user_data.h" |
13 #include "net/base/load_flags.h" | 13 #include "net/base/load_flags.h" |
14 #include "net/base/net_errors.h" | |
14 #include "net/url_request/url_fetcher.h" | 15 #include "net/url_request/url_fetcher.h" |
15 #include "net/url_request/url_fetcher_delegate.h" | 16 #include "net/url_request/url_fetcher_delegate.h" |
16 #include "net/url_request/url_request_context_getter.h" | 17 #include "net/url_request/url_request_context_getter.h" |
17 | 18 |
18 namespace domain_reliability { | 19 namespace domain_reliability { |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 const char* kJsonMimeType = "application/json; charset=utf-8"; | 23 const char* kJsonMimeType = "application/json; charset=utf-8"; |
23 | 24 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 VLOG(1) << "Setting discard_uploads to " << discard_uploads; | 87 VLOG(1) << "Setting discard_uploads to " << discard_uploads; |
87 } | 88 } |
88 | 89 |
89 // net::URLFetcherDelegate implementation: | 90 // net::URLFetcherDelegate implementation: |
90 void OnURLFetchComplete(const net::URLFetcher* fetcher) override { | 91 void OnURLFetchComplete(const net::URLFetcher* fetcher) override { |
91 DCHECK(fetcher); | 92 DCHECK(fetcher); |
92 | 93 |
93 UploadCallbackMap::iterator callback_it = upload_callbacks_.find(fetcher); | 94 UploadCallbackMap::iterator callback_it = upload_callbacks_.find(fetcher); |
94 DCHECK(callback_it != upload_callbacks_.end()); | 95 DCHECK(callback_it != upload_callbacks_.end()); |
95 | 96 |
96 VLOG(1) << "Upload finished with " << fetcher->GetResponseCode(); | 97 int net_error; |
98 { | |
99 const net::URLRequestStatus& status = fetcher->GetStatus(); | |
100 if (status.status() == net::URLRequestStatus::FAILED) | |
101 net_error = status.error(); | |
102 else | |
103 net_error = net::OK; | |
davidben
2014/10/30 22:26:55
+mmenke: FYI, here's another one of these. We real
mmenke
2014/10/30 22:42:59
I'd like to get rid of the double-value status ent
Deprecated (see juliatuttle)
2014/10/31 18:54:01
Why does ERR_ABORTED not count?
mmenke
2014/10/31 18:55:55
The same reason you're not counting net::URLReques
Deprecated (see juliatuttle)
2014/10/31 21:25:39
Alright, I'm counting CANCELED as ERR_ABORTED.
| |
104 } | |
105 int http_response_code = fetcher->GetResponseCode(); | |
106 | |
107 VLOG(1) << "Upload finished with net error " << net_error << | |
108 " and HTTP response code " << http_response_code; | |
97 | 109 |
98 UMA_HISTOGRAM_SPARSE_SLOWLY("DomainReliability.UploadResponseCode", | 110 UMA_HISTOGRAM_SPARSE_SLOWLY("DomainReliability.UploadResponseCode", |
99 fetcher->GetResponseCode()); | 111 http_response_code); |
112 UMA_HISTOGRAM_SPARSE_SLOWLY("DomainReliability.UploadNetError", | |
113 -net_error); | |
davidben
2014/10/30 22:26:55
Should this be
UMA_HISTOGRAM_CUSTOM_ENUMERATION("
Deprecated (see juliatuttle)
2014/10/31 18:54:01
This is rare enough that I think a sparse one will
| |
100 | 114 |
101 bool success = fetcher->GetResponseCode() == 200; | 115 callback_it->second.Run(http_response_code == 200); |
102 callback_it->second.Run(success); | |
103 | 116 |
104 delete callback_it->first; | 117 delete callback_it->first; |
105 upload_callbacks_.erase(callback_it); | 118 upload_callbacks_.erase(callback_it); |
106 } | 119 } |
107 | 120 |
108 private: | 121 private: |
109 using DomainReliabilityUploader::UploadCallback; | 122 using DomainReliabilityUploader::UploadCallback; |
110 typedef std::map<const net::URLFetcher*, UploadCallback> UploadCallbackMap; | 123 typedef std::map<const net::URLFetcher*, UploadCallback> UploadCallbackMap; |
111 | 124 |
112 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | 125 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
(...skipping 14 matching lines...) Expand all Loading... | |
127 new DomainReliabilityUploaderImpl(url_request_context_getter)); | 140 new DomainReliabilityUploaderImpl(url_request_context_getter)); |
128 } | 141 } |
129 | 142 |
130 // static | 143 // static |
131 bool DomainReliabilityUploader::URLRequestIsUpload( | 144 bool DomainReliabilityUploader::URLRequestIsUpload( |
132 const net::URLRequest& request) { | 145 const net::URLRequest& request) { |
133 return request.GetUserData(UploadUserData::kUserDataKey) != NULL; | 146 return request.GetUserData(UploadUserData::kUserDataKey) != NULL; |
134 } | 147 } |
135 | 148 |
136 } // namespace domain_reliability | 149 } // namespace domain_reliability |
OLD | NEW |