OLD | NEW |
| (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_TIMES("Net.ThreadHopResourceThrottleTime", | |
57 base::TimeTicks::Now() - time); | |
58 controller()->Resume(); | |
59 } | |
OLD | NEW |