| OLD | NEW |
| 1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 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 | 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 // A Preconnect instance maintains state while a TCP/IP connection is made, and | 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. | 6 // and then released into the pool of available connections for future use. |
| 7 | 7 |
| 8 #ifndef CHROME_BROWSER_NET_PRECONNECT_H_ | 8 #ifndef CHROME_BROWSER_NET_PRECONNECT_H_ |
| 9 #define CHROME_BROWSER_NET_PRECONNECT_H_ | 9 #define CHROME_BROWSER_NET_PRECONNECT_H_ |
| 10 #pragma once | 10 #pragma once |
| 11 | 11 |
| 12 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
| 13 #include "chrome/browser/net/url_info.h" | 13 #include "chrome/browser/net/url_info.h" |
| 14 #include "net/base/completion_callback.h" | 14 #include "net/base/completion_callback.h" |
| 15 #include "net/base/host_port_pair.h" | 15 #include "net/base/host_port_pair.h" |
| 16 #include "net/socket/client_socket_handle.h" | 16 #include "net/socket/client_socket_handle.h" |
| 17 #include "net/socket/tcp_client_socket_pool.h" | 17 #include "net/socket/tcp_client_socket_pool.h" |
| 18 #include "net/url_request/url_request_context.h" | 18 #include "net/url_request/url_request_context.h" |
| 19 | 19 |
| 20 namespace chrome_browser_net { | 20 namespace chrome_browser_net { |
| 21 | 21 |
| 22 class Preconnect : public net::CompletionCallback { | 22 class Preconnect : public net::CompletionCallback, |
| 23 public base::RefCountedThreadSafe<Preconnect> { |
| 23 public: | 24 public: |
| 24 // Try to preconnect. Typically motivated by OMNIBOX to reach search service. | 25 // Try to preconnect. Typically motivated by OMNIBOX to reach search service. |
| 25 static void PreconnectOnUIThread(const GURL& url, | 26 static void PreconnectOnUIThread(const GURL& url, |
| 26 UrlInfo::ResolutionMotivation motivation); | 27 UrlInfo::ResolutionMotivation motivation); |
| 27 | 28 |
| 28 // Try to preconnect. Typically used by predictor when a subresource probably | 29 // Try to preconnect. Typically used by predictor when a subresource probably |
| 29 // needs a connection. | 30 // needs a connection. |
| 30 static void PreconnectOnIOThread(const GURL& url, | 31 static void PreconnectOnIOThread(const GURL& url, |
| 31 UrlInfo::ResolutionMotivation motivation); | 32 UrlInfo::ResolutionMotivation motivation); |
| 32 | 33 |
| 33 static void SetPreconnectDespiteProxy(bool status) { | 34 static void SetPreconnectDespiteProxy(bool status) { |
| 34 preconnect_despite_proxy_ = status; | 35 preconnect_despite_proxy_ = status; |
| 35 } | 36 } |
| 36 | 37 |
| 37 private: | 38 private: |
| 38 Preconnect() {} | 39 friend class base::RefCountedThreadSafe<Preconnect>; |
| 39 | 40 |
| 40 // Supply an instance that could have been used in an IO callback, but will | 41 explicit Preconnect(UrlInfo::ResolutionMotivation motivation) |
| 41 // never actually be used (because we reset the connection so quickly). | 42 : motivation_(motivation) { |
| 42 static Preconnect* callback_instance_; | 43 } |
| 44 ~Preconnect(); |
| 45 |
| 46 // Request actual connection. |
| 47 void Connect(const GURL& url); |
| 43 | 48 |
| 44 // IO Callback which whould be performed when the connection is established. | 49 // IO Callback which whould be performed when the connection is established. |
| 45 virtual void RunWithParams(const Tuple1<int>& params); | 50 virtual void RunWithParams(const Tuple1<int>& params); |
| 46 | 51 |
| 47 // Preconnections are currently conservative, and do nothing if there is a | 52 // Preconnections are currently conservative, and do nothing if there is a |
| 48 // chance that a proxy may be used. This boolean allows proxy settings to | 53 // chance that a proxy may be used. This boolean allows proxy settings to |
| 49 // be ignored (presumably because a user knows that the proxy won't be doing | 54 // be ignored (presumably because a user knows that the proxy won't be doing |
| 50 // much work anway). | 55 // much work anway). |
| 51 static bool preconnect_despite_proxy_; | 56 static bool preconnect_despite_proxy_; |
| 52 | 57 |
| 58 // The handle holding the request. We need this so that we can mark the |
| 59 // request as speculative when an actual socket is bound to it. |
| 60 net::ClientSocketHandle handle_; |
| 61 |
| 62 // Generally either LEARNED_REFERAL_MOTIVATED or OMNIBOX_MOTIVATED to indicate |
| 63 // why we were trying to do a preconnection. |
| 64 const UrlInfo::ResolutionMotivation motivation_; |
| 65 |
| 66 |
| 53 DISALLOW_COPY_AND_ASSIGN(Preconnect); | 67 DISALLOW_COPY_AND_ASSIGN(Preconnect); |
| 54 }; | 68 }; |
| 55 } // chrome_browser_net | 69 } // chrome_browser_net |
| 56 | 70 |
| 57 #endif // CHROME_BROWSER_NET_PRECONNECT_H_ | 71 #endif // CHROME_BROWSER_NET_PRECONNECT_H_ |
| OLD | NEW |