Home | History | Annotate | Download | only in net
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_NET_CONNECT_INTERCEPTOR_H_
      6 #define CHROME_BROWSER_NET_CONNECT_INTERCEPTOR_H_
      7 
      8 #include "base/gtest_prod_util.h"
      9 #include "base/memory/scoped_ptr.h"
     10 #include "chrome/browser/net/timed_cache.h"
     11 
     12 class GURL;
     13 
     14 namespace net {
     15 class URLRequest;
     16 }
     17 
     18 namespace chrome_browser_net {
     19 
     20 class Predictor;
     21 
     22 //------------------------------------------------------------------------------
     23 // An interceptor to monitor URLRequests so that we can do speculative DNS
     24 // resolution and/or speculative TCP preconnections.
     25 class ConnectInterceptor {
     26  public:
     27   // Construction includes registration as an URL.
     28   explicit ConnectInterceptor(Predictor* predictor);
     29   // Destruction includes unregistering.
     30   virtual ~ConnectInterceptor();
     31 
     32   // Learn about referrers, and optionally preconnect based on history.
     33   void WitnessURLRequest(net::URLRequest* request);
     34 
     35  private:
     36   // Provide access to local class TimedCache for testing.
     37   FRIEND_TEST_ALL_PREFIXES(ConnectInterceptorTest, TimedCacheRecall);
     38   FRIEND_TEST_ALL_PREFIXES(ConnectInterceptorTest, TimedCacheEviction);
     39 
     40   TimedCache timed_cache_;
     41   Predictor* const predictor_;
     42 
     43   DISALLOW_COPY_AND_ASSIGN(ConnectInterceptor);
     44 };
     45 
     46 }  // namespace chrome_browser_net
     47 
     48 #endif  // CHROME_BROWSER_NET_CONNECT_INTERCEPTOR_H_
     49