preconnect.h revision c407dc5cd9bdc5668497f21b26b09d988ab439de
1// Copyright (c) 2006-2010 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// A Preconnect instance maintains state while a TCP/IP connection is made, and 6// and then released into the pool of available connections for future use. 7 8#ifndef CHROME_BROWSER_NET_PRECONNECT_H_ 9#define CHROME_BROWSER_NET_PRECONNECT_H_ 10 11#include "base/ref_counted.h" 12#include "net/base/completion_callback.h" 13#include "net/base/host_port_pair.h" 14#include "net/socket/client_socket_handle.h" 15#include "net/socket/tcp_client_socket_pool.h" 16#include "net/url_request/url_request_context.h" 17 18namespace chrome_browser_net { 19 20class Preconnect : public net::CompletionCallback { 21 public: 22 static bool PreconnectOnUIThread(const GURL& url); 23 24 static void PreconnectOnIOThread(const GURL& url); 25 26 static void SetPreconnectDespiteProxy(bool status) { 27 preconnect_despite_proxy_ = status; 28 } 29 30 private: 31 Preconnect() {} 32 33 // Supply an instance that could have been used in an IO callback, but will 34 // never actually be used (because we reset the connection so quickly). 35 static Preconnect* callback_instance_; 36 37 // IO Callback which whould be performed when the connection is established. 38 virtual void RunWithParams(const Tuple1<int>& params); 39 40 // Preconnections are currently conservative, and do nothing if there is a 41 // chance that a proxy may be used. This boolean allows proxy settings to 42 // be ignored (presumably because a user knows that the proxy won't be doing 43 // much work anway). 44 static bool preconnect_despite_proxy_; 45 46 DISALLOW_COPY_AND_ASSIGN(Preconnect); 47}; 48} // chrome_browser_net 49 50#endif // CHROME_BROWSER_NET_PRECONNECT_H_ 51