| OLD | NEW |
| 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/url_request.h" | 9 #include "net/url_request/url_request.h" |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 : timed_cache_(base::TimeDelta::FromSeconds( | 21 : timed_cache_(base::TimeDelta::FromSeconds( |
| 22 kMaxUnusedSocketLifetimeSecondsWithoutAGet)), | 22 kMaxUnusedSocketLifetimeSecondsWithoutAGet)), |
| 23 predictor_(predictor) { | 23 predictor_(predictor) { |
| 24 DCHECK(predictor); | 24 DCHECK(predictor); |
| 25 } | 25 } |
| 26 | 26 |
| 27 ConnectInterceptor::~ConnectInterceptor() { | 27 ConnectInterceptor::~ConnectInterceptor() { |
| 28 } | 28 } |
| 29 | 29 |
| 30 net::URLRequestJob* ConnectInterceptor::MaybeIntercept( | 30 net::URLRequestJob* ConnectInterceptor::MaybeIntercept( |
| 31 net::URLRequest* request) const { | 31 net::URLRequest* request, net::NetworkDelegate* network_delegate) const { |
| 32 GURL request_scheme_host(Predictor::CanonicalizeUrl(request->url())); | 32 GURL request_scheme_host(Predictor::CanonicalizeUrl(request->url())); |
| 33 if (request_scheme_host == GURL::EmptyGURL()) | 33 if (request_scheme_host == GURL::EmptyGURL()) |
| 34 return NULL; | 34 return NULL; |
| 35 | 35 |
| 36 // Learn what URLs are likely to be needed during next startup. | 36 // Learn what URLs are likely to be needed during next startup. |
| 37 predictor_->LearnAboutInitialNavigation(request_scheme_host); | 37 predictor_->LearnAboutInitialNavigation(request_scheme_host); |
| 38 | 38 |
| 39 bool redirected_host = false; | 39 bool redirected_host = false; |
| 40 if (request->referrer().empty()) { | 40 if (request->referrer().empty()) { |
| 41 if (request->url() != request->original_url()) { | 41 if (request->url() != request->original_url()) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 81 |
| 82 // Subresources for main frames usually get predicted when we detected the | 82 // Subresources for main frames usually get predicted when we detected the |
| 83 // main frame request - way back in RenderViewHost::Navigate. So only handle | 83 // main frame request - way back in RenderViewHost::Navigate. So only handle |
| 84 // predictions now for subresources or for redirected hosts. | 84 // predictions now for subresources or for redirected hosts. |
| 85 if ((request->load_flags() & net::LOAD_SUB_FRAME) || redirected_host) | 85 if ((request->load_flags() & net::LOAD_SUB_FRAME) || redirected_host) |
| 86 predictor_->PredictFrameSubresources(request_scheme_host); | 86 predictor_->PredictFrameSubresources(request_scheme_host); |
| 87 return NULL; | 87 return NULL; |
| 88 } | 88 } |
| 89 | 89 |
| 90 net::URLRequestJob* ConnectInterceptor::MaybeInterceptResponse( | 90 net::URLRequestJob* ConnectInterceptor::MaybeInterceptResponse( |
| 91 net::URLRequest* request) const { | 91 net::URLRequest* request, net::NetworkDelegate* network_delegate) const { |
| 92 return NULL; | 92 return NULL; |
| 93 } | 93 } |
| 94 | 94 |
| 95 net::URLRequestJob* ConnectInterceptor::MaybeInterceptRedirect( | 95 net::URLRequestJob* ConnectInterceptor::MaybeInterceptRedirect( |
| 96 const GURL& location, | 96 const GURL& location, |
| 97 net::URLRequest* request) const { | 97 net::URLRequest* request, |
| 98 net::NetworkDelegate* network_delegate) const { |
| 98 return NULL; | 99 return NULL; |
| 99 } | 100 } |
| 100 | 101 |
| 101 ConnectInterceptor::TimedCache::TimedCache(const base::TimeDelta& max_duration) | 102 ConnectInterceptor::TimedCache::TimedCache(const base::TimeDelta& max_duration) |
| 102 : mru_cache_(UrlMruTimedCache::NO_AUTO_EVICT), | 103 : mru_cache_(UrlMruTimedCache::NO_AUTO_EVICT), |
| 103 max_duration_(max_duration) { | 104 max_duration_(max_duration) { |
| 104 } | 105 } |
| 105 | 106 |
| 106 // Make Clang compilation happy with explicit destructor. | 107 // Make Clang compilation happy with explicit destructor. |
| 107 ConnectInterceptor::TimedCache::~TimedCache() {} | 108 ConnectInterceptor::TimedCache::~TimedCache() {} |
| (...skipping 11 matching lines...) Expand all Loading... |
| 119 } | 120 } |
| 120 return mru_cache_.end() != mru_cache_.Peek(url); | 121 return mru_cache_.end() != mru_cache_.Peek(url); |
| 121 } | 122 } |
| 122 | 123 |
| 123 void ConnectInterceptor::TimedCache::SetRecentlySeen(const GURL& url) const { | 124 void ConnectInterceptor::TimedCache::SetRecentlySeen(const GURL& url) const { |
| 124 DCHECK_EQ(url.GetWithEmptyPath(), url); | 125 DCHECK_EQ(url.GetWithEmptyPath(), url); |
| 125 mru_cache_.Put(url, base::TimeTicks::Now()); | 126 mru_cache_.Put(url, base::TimeTicks::Now()); |
| 126 } | 127 } |
| 127 | 128 |
| 128 } // namespace chrome_browser_net | 129 } // namespace chrome_browser_net |
| OLD | NEW |