| 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 #ifndef CHROME_BROWSER_NET_CONNECT_INTERCEPTOR_H_ | 5 #ifndef CHROME_BROWSER_NET_CONNECT_INTERCEPTOR_H_ |
| 6 #define CHROME_BROWSER_NET_CONNECT_INTERCEPTOR_H_ | 6 #define CHROME_BROWSER_NET_CONNECT_INTERCEPTOR_H_ |
| 7 | 7 |
| 8 #include "base/containers/mru_cache.h" | 8 #include "base/containers/mru_cache.h" |
| 9 #include "base/gtest_prod_util.h" | 9 #include "base/gtest_prod_util.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/time.h" | 11 #include "base/time.h" |
| 11 #include "net/url_request/url_request_job_factory.h" | 12 #include "net/url_request/url_request_job_factory.h" |
| 12 | 13 |
| 13 namespace chrome_browser_net { | 14 namespace chrome_browser_net { |
| 14 | 15 |
| 15 class Predictor; | 16 class Predictor; |
| 16 | 17 |
| 17 //------------------------------------------------------------------------------ | 18 //------------------------------------------------------------------------------ |
| 18 // An interceptor to monitor URLRequests so that we can do speculative DNS | 19 // An interceptor to monitor URLRequests so that we can do speculative DNS |
| 19 // resolution and/or speculative TCP preconnections. | 20 // resolution and/or speculative TCP preconnections. |
| 20 class ConnectInterceptor : public net::URLRequestJobFactory::Interceptor { | 21 class ConnectInterceptor : public net::URLRequestJobFactory::ProtocolHandler { |
| 21 public: | 22 public: |
| 22 // Construction includes registration as an URL. | 23 // Creation includes registration as an URL. |
| 23 explicit ConnectInterceptor(Predictor* predictor); | 24 static scoped_ptr<net::URLRequestJobFactory> CreateURLRequestJobFactory( |
| 25 scoped_ptr<net::URLRequestJobFactory> base_job_factory, |
| 26 Predictor* predictor); |
| 24 // Destruction includes unregistering. | 27 // Destruction includes unregistering. |
| 25 virtual ~ConnectInterceptor(); | 28 virtual ~ConnectInterceptor(); |
| 26 | 29 |
| 27 protected: | 30 protected: |
| 28 // Overridden from net::URLRequest::Interceptor: | 31 // Overridden from net::URLRequestJobFactory::ProtocolHandler: |
| 29 // Learn about referrers, and optionally preconnect based on history. | 32 // Learn about referrers, and optionally preconnect based on history. |
| 30 virtual net::URLRequestJob* MaybeIntercept( | 33 virtual net::URLRequestJob* MaybeCreateJob( |
| 31 net::URLRequest* request, | |
| 32 net::NetworkDelegate* network_delegate) const OVERRIDE; | |
| 33 virtual net::URLRequestJob* MaybeInterceptResponse( | |
| 34 net::URLRequest* request, | |
| 35 net::NetworkDelegate* network_delegate) const OVERRIDE; | |
| 36 virtual net::URLRequestJob* MaybeInterceptRedirect( | |
| 37 const GURL& location, | |
| 38 net::URLRequest* request, | 34 net::URLRequest* request, |
| 39 net::NetworkDelegate* network_delegate) const OVERRIDE; | 35 net::NetworkDelegate* network_delegate) const OVERRIDE; |
| 40 | 36 |
| 41 private: | 37 private: |
| 38 explicit ConnectInterceptor(Predictor* predictor); |
| 39 |
| 42 // Provide access to local class TimedCache for testing. | 40 // Provide access to local class TimedCache for testing. |
| 43 FRIEND_TEST_ALL_PREFIXES(ConnectInterceptorTest, TimedCacheRecall); | 41 FRIEND_TEST_ALL_PREFIXES(ConnectInterceptorTest, TimedCacheRecall); |
| 44 FRIEND_TEST_ALL_PREFIXES(ConnectInterceptorTest, TimedCacheEviction); | 42 FRIEND_TEST_ALL_PREFIXES(ConnectInterceptorTest, TimedCacheEviction); |
| 45 | 43 |
| 46 // Define a LRU cache that recalls all navigations within the last N seconds. | 44 // Define a LRU cache that recalls all navigations within the last N seconds. |
| 47 // When we learn about subresources to possibly preconnect to, it would be a | 45 // When we learn about subresources to possibly preconnect to, it would be a |
| 48 // waste to preconnect when the original navigation was too long ago. Any | 46 // waste to preconnect when the original navigation was too long ago. Any |
| 49 // connected, but unused TCP/IP connection, will generally be reset by the | 47 // connected, but unused TCP/IP connection, will generally be reset by the |
| 50 // server if it is not used quickly (i.e., GET or POST is sent). | 48 // server if it is not used quickly (i.e., GET or POST is sent). |
| 51 class TimedCache { | 49 class TimedCache { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 77 }; | 75 }; |
| 78 TimedCache timed_cache_; | 76 TimedCache timed_cache_; |
| 79 Predictor* const predictor_; | 77 Predictor* const predictor_; |
| 80 | 78 |
| 81 DISALLOW_COPY_AND_ASSIGN(ConnectInterceptor); | 79 DISALLOW_COPY_AND_ASSIGN(ConnectInterceptor); |
| 82 }; | 80 }; |
| 83 | 81 |
| 84 } // namespace chrome_browser_net | 82 } // namespace chrome_browser_net |
| 85 | 83 |
| 86 #endif // CHROME_BROWSER_NET_CONNECT_INTERCEPTOR_H_ | 84 #endif // CHROME_BROWSER_NET_CONNECT_INTERCEPTOR_H_ |
| OLD | NEW |