Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: components/domain_reliability/uploader.cc

Issue 694573003: Domain Reliability: Histogram net error codes from uploads (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Label upload response code histogram with an enum Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 switch (status.status()) {
101 case net::URLRequestStatus::SUCCESS:
102 net_error = net::OK;
103 break;
104 case net::URLRequestStatus::CANCELED:
105 net_error = net::ERR_ABORTED;
106 break;
107 case net::URLRequestStatus::FAILED:
108 net_error = status.error();
109 break;
110 default:
111 NOTREACHED();
112 net_error = net::ERR_FAILED;
113 break;
114 }
115 }
116 int http_response_code = fetcher->GetResponseCode();
117
118 VLOG(1) << "Upload finished with net error " << net_error <<
119 " and HTTP response code " << http_response_code;
97 120
98 UMA_HISTOGRAM_SPARSE_SLOWLY("DomainReliability.UploadResponseCode", 121 UMA_HISTOGRAM_SPARSE_SLOWLY("DomainReliability.UploadResponseCode",
99 fetcher->GetResponseCode()); 122 http_response_code);
123 UMA_HISTOGRAM_SPARSE_SLOWLY("DomainReliability.UploadNetError",
124 -net_error);
100 125
101 bool success = fetcher->GetResponseCode() == 200; 126 callback_it->second.Run(http_response_code == 200);
102 callback_it->second.Run(success);
103 127
104 delete callback_it->first; 128 delete callback_it->first;
105 upload_callbacks_.erase(callback_it); 129 upload_callbacks_.erase(callback_it);
106 } 130 }
107 131
108 private: 132 private:
109 using DomainReliabilityUploader::UploadCallback; 133 using DomainReliabilityUploader::UploadCallback;
110 typedef std::map<const net::URLFetcher*, UploadCallback> UploadCallbackMap; 134 typedef std::map<const net::URLFetcher*, UploadCallback> UploadCallbackMap;
111 135
112 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; 136 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
(...skipping 14 matching lines...) Expand all
127 new DomainReliabilityUploaderImpl(url_request_context_getter)); 151 new DomainReliabilityUploaderImpl(url_request_context_getter));
128 } 152 }
129 153
130 // static 154 // static
131 bool DomainReliabilityUploader::URLRequestIsUpload( 155 bool DomainReliabilityUploader::URLRequestIsUpload(
132 const net::URLRequest& request) { 156 const net::URLRequest& request) {
133 return request.GetUserData(UploadUserData::kUserDataKey) != NULL; 157 return request.GetUserData(UploadUserData::kUserDataKey) != NULL;
134 } 158 }
135 159
136 } // namespace domain_reliability 160 } // namespace domain_reliability
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698