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

Side by Side Diff: chrome/browser/net/connect_interceptor.cc

Issue 11293252: Change Interceptors into URLRequestJobFactory::ProtocolHandlers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address mmenke's first round of comments Created 8 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/net/connect_interceptor.h" 5 #include "chrome/browser/net/connect_interceptor.h"
6 6
7 #include "chrome/browser/net/predictor.h" 7 #include "chrome/browser/net/predictor.h"
8 #include "net/base/load_flags.h" 8 #include "net/base/load_flags.h"
9 #include "net/url_request/protocol_intercept_job_factory.h"
9 #include "net/url_request/url_request.h" 10 #include "net/url_request/url_request.h"
10 11
11 namespace chrome_browser_net { 12 namespace chrome_browser_net {
12 13
13 // We don't bother learning to preconnect via a GET if the original URL 14 // We don't bother learning to preconnect via a GET if the original URL
14 // navigation was so long ago, that a preconnection would have been dropped 15 // navigation was so long ago, that a preconnection would have been dropped
15 // anyway. We believe most servers will drop the connection in 10 seconds, so 16 // anyway. We believe most servers will drop the connection in 10 seconds, so
16 // we currently estimate this time-till-drop at 10 seconds. 17 // we currently estimate this time-till-drop at 10 seconds.
17 // TODO(jar): We should do a persistent field trial to validate/optimize this. 18 // TODO(jar): We should do a persistent field trial to validate/optimize this.
18 static const int kMaxUnusedSocketLifetimeSecondsWithoutAGet = 10; 19 static const int kMaxUnusedSocketLifetimeSecondsWithoutAGet = 10;
19 20
21 // static
22 scoped_ptr<net::URLRequestJobFactory>
23 ConnectInterceptor::CreateURLRequestJobFactory(
24 scoped_ptr<net::URLRequestJobFactory> base_job_factory,
25 Predictor* predictor) {
26 scoped_ptr<net::URLRequestJobFactory> top_job_factory(
27 new net::ProtocolInterceptJobFactory(
28 base_job_factory.Pass(),
29 scoped_ptr<ProtocolHandler>(new ConnectInterceptor(predictor))));
30 return top_job_factory.Pass();
31 }
32
20 ConnectInterceptor::ConnectInterceptor(Predictor* predictor) 33 ConnectInterceptor::ConnectInterceptor(Predictor* predictor)
21 : timed_cache_(base::TimeDelta::FromSeconds( 34 : timed_cache_(base::TimeDelta::FromSeconds(
22 kMaxUnusedSocketLifetimeSecondsWithoutAGet)), 35 kMaxUnusedSocketLifetimeSecondsWithoutAGet)),
23 predictor_(predictor) { 36 predictor_(predictor) {
24 DCHECK(predictor); 37 DCHECK(predictor);
25 } 38 }
26 39
27 ConnectInterceptor::~ConnectInterceptor() { 40 ConnectInterceptor::~ConnectInterceptor() {
28 } 41 }
29 42
30 net::URLRequestJob* ConnectInterceptor::MaybeIntercept( 43 net::URLRequestJob* ConnectInterceptor::MaybeCreateJob(
31 net::URLRequest* request, net::NetworkDelegate* network_delegate) const { 44 net::URLRequest* request, net::NetworkDelegate* network_delegate) const {
32 GURL request_scheme_host(Predictor::CanonicalizeUrl(request->url())); 45 GURL request_scheme_host(Predictor::CanonicalizeUrl(request->url()));
33 if (request_scheme_host == GURL::EmptyGURL()) 46 if (request_scheme_host == GURL::EmptyGURL())
34 return NULL; 47 return NULL;
35 48
36 // Learn what URLs are likely to be needed during next startup. 49 // Learn what URLs are likely to be needed during next startup.
37 predictor_->LearnAboutInitialNavigation(request_scheme_host); 50 predictor_->LearnAboutInitialNavigation(request_scheme_host);
38 51
39 bool redirected_host = false; 52 bool redirected_host = false;
40 if (request->referrer().empty()) { 53 if (request->referrer().empty()) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 timed_cache_.SetRecentlySeen(request_scheme_host); 93 timed_cache_.SetRecentlySeen(request_scheme_host);
81 94
82 // Subresources for main frames usually get predicted when we detected the 95 // Subresources for main frames usually get predicted when we detected the
83 // main frame request - way back in RenderViewHost::Navigate. So only handle 96 // main frame request - way back in RenderViewHost::Navigate. So only handle
84 // predictions now for subresources or for redirected hosts. 97 // predictions now for subresources or for redirected hosts.
85 if ((request->load_flags() & net::LOAD_SUB_FRAME) || redirected_host) 98 if ((request->load_flags() & net::LOAD_SUB_FRAME) || redirected_host)
86 predictor_->PredictFrameSubresources(request_scheme_host); 99 predictor_->PredictFrameSubresources(request_scheme_host);
87 return NULL; 100 return NULL;
88 } 101 }
89 102
90 net::URLRequestJob* ConnectInterceptor::MaybeInterceptResponse(
91 net::URLRequest* request, net::NetworkDelegate* network_delegate) const {
92 return NULL;
93 }
94
95 net::URLRequestJob* ConnectInterceptor::MaybeInterceptRedirect(
96 const GURL& location,
97 net::URLRequest* request,
98 net::NetworkDelegate* network_delegate) const {
99 return NULL;
100 }
101
102 ConnectInterceptor::TimedCache::TimedCache(const base::TimeDelta& max_duration) 103 ConnectInterceptor::TimedCache::TimedCache(const base::TimeDelta& max_duration)
103 : mru_cache_(UrlMruTimedCache::NO_AUTO_EVICT), 104 : mru_cache_(UrlMruTimedCache::NO_AUTO_EVICT),
104 max_duration_(max_duration) { 105 max_duration_(max_duration) {
105 } 106 }
106 107
107 // Make Clang compilation happy with explicit destructor. 108 // Make Clang compilation happy with explicit destructor.
108 ConnectInterceptor::TimedCache::~TimedCache() {} 109 ConnectInterceptor::TimedCache::~TimedCache() {}
109 110
110 bool ConnectInterceptor::TimedCache::WasRecentlySeen(const GURL& url) const { 111 bool ConnectInterceptor::TimedCache::WasRecentlySeen(const GURL& url) const {
111 DCHECK_EQ(url.GetWithEmptyPath(), url); 112 DCHECK_EQ(url.GetWithEmptyPath(), url);
112 // Evict any overly old entries. 113 // Evict any overly old entries.
113 base::TimeTicks now = base::TimeTicks::Now(); 114 base::TimeTicks now = base::TimeTicks::Now();
114 UrlMruTimedCache::reverse_iterator eldest = mru_cache_.rbegin(); 115 UrlMruTimedCache::reverse_iterator eldest = mru_cache_.rbegin();
115 while (!mru_cache_.empty()) { 116 while (!mru_cache_.empty()) {
116 DCHECK(eldest == mru_cache_.rbegin()); 117 DCHECK(eldest == mru_cache_.rbegin());
117 if (now - eldest->second < max_duration_) 118 if (now - eldest->second < max_duration_)
118 break; 119 break;
119 eldest = mru_cache_.Erase(eldest); 120 eldest = mru_cache_.Erase(eldest);
120 } 121 }
121 return mru_cache_.end() != mru_cache_.Peek(url); 122 return mru_cache_.end() != mru_cache_.Peek(url);
122 } 123 }
123 124
124 void ConnectInterceptor::TimedCache::SetRecentlySeen(const GURL& url) const { 125 void ConnectInterceptor::TimedCache::SetRecentlySeen(const GURL& url) const {
125 DCHECK_EQ(url.GetWithEmptyPath(), url); 126 DCHECK_EQ(url.GetWithEmptyPath(), url);
126 mru_cache_.Put(url, base::TimeTicks::Now()); 127 mru_cache_.Put(url, base::TimeTicks::Now());
127 } 128 }
128 129
129 } // namespace chrome_browser_net 130 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698