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

Side by Side Diff: net/proxy/proxy_script_fetcher_impl.cc

Issue 1224343002: Add Net.ProxyScriptFetchSuccessDuration UMA to record how long PAC script fetches take. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename UMA to Net.ProxyScriptFetcher.SuccessDuration Created 5 years, 5 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/proxy/proxy_script_fetcher_impl.h" 5 #include "net/proxy/proxy_script_fetcher_impl.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/histogram.h"
10 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
11 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
12 #include "base/thread_task_runner_handle.h" 13 #include "base/thread_task_runner_handle.h"
13 #include "net/base/data_url.h" 14 #include "net/base/data_url.h"
14 #include "net/base/io_buffer.h" 15 #include "net/base/io_buffer.h"
15 #include "net/base/load_flags.h" 16 #include "net/base/load_flags.h"
16 #include "net/base/net_errors.h" 17 #include "net/base/net_errors.h"
17 #include "net/base/net_string_util.h" 18 #include "net/base/net_string_util.h"
18 #include "net/base/request_priority.h" 19 #include "net/base/request_priority.h"
19 #include "net/cert/cert_status_flags.h" 20 #include "net/cert/cert_status_flags.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 std::string mime_type; 127 std::string mime_type;
127 std::string charset; 128 std::string charset;
128 std::string data; 129 std::string data;
129 if (!DataURL::Parse(url, &mime_type, &charset, &data)) 130 if (!DataURL::Parse(url, &mime_type, &charset, &data))
130 return ERR_FAILED; 131 return ERR_FAILED;
131 132
132 ConvertResponseToUTF16(charset, data, text); 133 ConvertResponseToUTF16(charset, data, text);
133 return OK; 134 return OK;
134 } 135 }
135 136
137 DCHECK(fetch_start_time_.is_null());
138 fetch_start_time_ = base::Time::Now();
eroman 2015/07/13 21:39:04 I suggest using base::TimeTicks over base::Time fo
139
136 cur_request_ = 140 cur_request_ =
137 url_request_context_->CreateRequest(url, DEFAULT_PRIORITY, this); 141 url_request_context_->CreateRequest(url, DEFAULT_PRIORITY, this);
138 cur_request_->set_method("GET"); 142 cur_request_->set_method("GET");
139 143
140 // Make sure that the PAC script is downloaded using a direct connection, 144 // Make sure that the PAC script is downloaded using a direct connection,
141 // to avoid circular dependencies (fetching is a part of proxy resolution). 145 // to avoid circular dependencies (fetching is a part of proxy resolution).
142 // Also disable the use of the disk cache. The cache is disabled so that if 146 // Also disable the use of the disk cache. The cache is disabled so that if
143 // the user switches networks we don't potentially use the cached response 147 // the user switches networks we don't potentially use the cached response
144 // from old network when we should in fact be re-fetching on the new network. 148 // from old network when we should in fact be re-fetching on the new network.
145 // If the PAC script is hosted on an HTTPS server we bypass revocation 149 // If the PAC script is hosted on an HTTPS server we bypass revocation
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 request->Cancel(); 279 request->Cancel();
276 return false; 280 return false;
277 } 281 }
278 282
279 bytes_read_so_far_.append(buf_->data(), num_bytes); 283 bytes_read_so_far_.append(buf_->data(), num_bytes);
280 return true; 284 return true;
281 } 285 }
282 286
283 void ProxyScriptFetcherImpl::FetchCompleted() { 287 void ProxyScriptFetcherImpl::FetchCompleted() {
284 if (result_code_ == OK) { 288 if (result_code_ == OK) {
289 // Calculate duration of time for proxy script fetch to complete.
290 DCHECK(!fetch_start_time_.is_null());
291 UMA_HISTOGRAM_TIMES("Net.ProxyScriptFetcher.SuccessDuration",
eroman 2015/07/13 21:39:04 I see you considered putting it in ProxyScriptDeci
292 base::Time::Now() - fetch_start_time_);
293
285 // The caller expects the response to be encoded as UTF16. 294 // The caller expects the response to be encoded as UTF16.
286 std::string charset; 295 std::string charset;
287 cur_request_->GetCharset(&charset); 296 cur_request_->GetCharset(&charset);
288 ConvertResponseToUTF16(charset, bytes_read_so_far_, result_text_); 297 ConvertResponseToUTF16(charset, bytes_read_so_far_, result_text_);
289 } else { 298 } else {
290 // On error, the caller expects empty string for bytes. 299 // On error, the caller expects empty string for bytes.
291 result_text_->clear(); 300 result_text_->clear();
292 } 301 }
293 302
294 int result_code = result_code_; 303 int result_code = result_code_;
295 CompletionCallback callback = callback_; 304 CompletionCallback callback = callback_;
296 305
297 ResetCurRequestState(); 306 ResetCurRequestState();
298 307
299 callback.Run(result_code); 308 callback.Run(result_code);
300 } 309 }
301 310
302 void ProxyScriptFetcherImpl::ResetCurRequestState() { 311 void ProxyScriptFetcherImpl::ResetCurRequestState() {
303 cur_request_.reset(); 312 cur_request_.reset();
304 cur_request_id_ = 0; 313 cur_request_id_ = 0;
305 callback_.Reset(); 314 callback_.Reset();
306 result_code_ = OK; 315 result_code_ = OK;
307 result_text_ = NULL; 316 result_text_ = NULL;
317 fetch_start_time_ = base::Time();
308 } 318 }
309 319
310 void ProxyScriptFetcherImpl::OnTimeout(int id) { 320 void ProxyScriptFetcherImpl::OnTimeout(int id) {
311 // Timeout tasks may outlive the URLRequest they reference. Make sure it 321 // Timeout tasks may outlive the URLRequest they reference. Make sure it
312 // is still applicable. 322 // is still applicable.
313 if (cur_request_id_ != id) 323 if (cur_request_id_ != id)
314 return; 324 return;
315 325
316 DCHECK(cur_request_.get()); 326 DCHECK(cur_request_.get());
317 result_code_ = ERR_TIMED_OUT; 327 result_code_ = ERR_TIMED_OUT;
318 cur_request_->Cancel(); 328 cur_request_->Cancel();
319 } 329 }
320 330
321 } // namespace net 331 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698