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

Side by Side Diff: chrome/browser/renderer_host/thread_hop_resource_throttle.cc

Issue 1372263002: Add a field trial to delay all resource requests by thread hops. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mmenke comments Created 5 years, 2 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/renderer_host/thread_hop_resource_throttle.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/location.h"
10 #include "base/metrics/field_trial.h"
11 #include "base/metrics/histogram_macros.h"
12 #include "base/strings/string_util.h"
13 #include "base/time/time.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/resource_controller.h"
16
17 ThreadHopResourceThrottle::ThreadHopResourceThrottle() : weak_factory_(this) {}
18
19 ThreadHopResourceThrottle::~ThreadHopResourceThrottle() {}
20
21 bool ThreadHopResourceThrottle::IsEnabled() {
22 const std::string group_name =
23 base::FieldTrialList::FindFullName("ThreadHopResourceThrottle");
24 return base::StartsWith(group_name, "Enabled", base::CompareCase::SENSITIVE);
25 }
26
27 void ThreadHopResourceThrottle::WillStartRequest(bool* defer) {
28 *defer = true;
29 ResumeAfterThreadHop();
30 }
31
32 void ThreadHopResourceThrottle::WillRedirectRequest(
33 const net::RedirectInfo& redirect_info,
34 bool* defer) {
35 *defer = true;
36 ResumeAfterThreadHop();
37 }
38
39 void ThreadHopResourceThrottle::WillProcessResponse(bool* defer) {
40 *defer = true;
41 ResumeAfterThreadHop();
42 }
43
44 const char* ThreadHopResourceThrottle::GetNameForLogging() const {
45 return "ThreadHopResourceThrottle";
46 }
47
48 void ThreadHopResourceThrottle::ResumeAfterThreadHop() {
49 content::BrowserThread::PostTaskAndReply(
50 content::BrowserThread::UI, FROM_HERE, base::Bind(&base::DoNothing),
51 base::Bind(&ThreadHopResourceThrottle::Resume, weak_factory_.GetWeakPtr(),
52 base::TimeTicks::Now()));
53 }
54
55 void ThreadHopResourceThrottle::Resume(const base::TimeTicks& time) {
56 UMA_HISTOGRAM_CUSTOM_TIMES("Net.ThreadHopResourceThrottleTime",
57 base::TimeTicks::Now() - time, base::TimeDelta(),
58 base::TimeDelta::FromMilliseconds(100), 100);
Alexei Svitkine (slow) 2015/10/02 16:42:54 Is there a reason you picked these parameters? Ha
davidben 2015/10/02 17:19:42 I picked 100 because it looked like others did thi
Alexei Svitkine (slow) 2015/10/02 17:30:43 These macros provide a exponential distribution. S
davidben 2015/10/02 17:39:39 Gotcha. UMA_HISTOGRAM_TIMES it is then!
59 controller()->Resume();
60 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698