| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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_EXTENSIONS_EXTENSION_WEB_SOCKET_PROXY_PRIVATE_API_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WEB_SOCKET_PROXY_PRIVATE_API_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "base/timer.h" | |
| 10 #include "chrome/browser/extensions/extension_function.h" | |
| 11 #include "content/public/browser/notification_observer.h" | |
| 12 #include "content/public/browser/notification_registrar.h" | |
| 13 #include "net/base/address_list.h" | |
| 14 | |
| 15 class IOThread; | |
| 16 | |
| 17 namespace net { | |
| 18 class SingleRequestHostResolver; | |
| 19 } | |
| 20 | |
| 21 // Base class for web socket proxy functions. | |
| 22 class WebSocketProxyPrivate | |
| 23 : public AsyncExtensionFunction, public content::NotificationObserver { | |
| 24 public: | |
| 25 WebSocketProxyPrivate(); | |
| 26 | |
| 27 protected: | |
| 28 virtual ~WebSocketProxyPrivate(); | |
| 29 | |
| 30 // Custom finalization. | |
| 31 virtual void CustomFinalize() = 0; | |
| 32 | |
| 33 // ExtensionFunction implementation. | |
| 34 virtual bool RunImpl() OVERRIDE; | |
| 35 | |
| 36 // content::NotificationObserver implementation. | |
| 37 virtual void Observe( | |
| 38 int type, const content::NotificationSource& source, | |
| 39 const content::NotificationDetails& details) OVERRIDE; | |
| 40 | |
| 41 // Destination hostname. | |
| 42 std::string hostname_; | |
| 43 // Destination IP address. | |
| 44 net::AddressList addr_; | |
| 45 // Destination port. | |
| 46 int port_; | |
| 47 // Proxy accepts websocket connections on this port. | |
| 48 int listening_port_; | |
| 49 // Whether TLS should be used. | |
| 50 bool do_tls_; | |
| 51 // Requested parameters of connection. | |
| 52 std::map<std::string, std::string> map_; | |
| 53 | |
| 54 private: | |
| 55 // Finalizes and sends respond. Overwrite 'CustomFinalize' in inherited | |
| 56 // classes. | |
| 57 void Finalize(); | |
| 58 | |
| 59 // Callback for DNS resolution. | |
| 60 void OnHostResolution(int result); | |
| 61 | |
| 62 // Posts task to the IO thread, which will make dns resolution. | |
| 63 void ResolveHost(); | |
| 64 // Executes on IO thread. Performs DNS resolution. | |
| 65 void ResolveHostIOPart(IOThread* io_thread); | |
| 66 | |
| 67 // Used to signal timeout (when waiting for proxy initial launch). | |
| 68 base::OneShotTimer<WebSocketProxyPrivate> timer_; | |
| 69 // Used to register for notifications. | |
| 70 content::NotificationRegistrar registrar_; | |
| 71 // Used to cancel host resolution when out of scope. | |
| 72 scoped_ptr<net::SingleRequestHostResolver> resolver_; | |
| 73 // Callback which is called when host is resolved. | |
| 74 bool is_finalized_; | |
| 75 }; | |
| 76 | |
| 77 // New API function for web socket proxy, which should be used. | |
| 78 class WebSocketProxyPrivateGetURLForTCPFunction | |
| 79 : public WebSocketProxyPrivate { | |
| 80 public: | |
| 81 DECLARE_EXTENSION_FUNCTION_NAME("webSocketProxyPrivate.getURLForTCP") | |
| 82 | |
| 83 WebSocketProxyPrivateGetURLForTCPFunction(); | |
| 84 | |
| 85 protected: | |
| 86 virtual ~WebSocketProxyPrivateGetURLForTCPFunction(); | |
| 87 | |
| 88 // ExtensionFunction implementation. | |
| 89 virtual bool RunImpl() OVERRIDE; | |
| 90 | |
| 91 // WebSocketProxyPrivate implementation: | |
| 92 virtual void CustomFinalize() OVERRIDE; | |
| 93 }; | |
| 94 | |
| 95 // Legacy API function for web socket proxy, to be eliminated. | |
| 96 class WebSocketProxyPrivateGetPassportForTCPFunction | |
| 97 : public WebSocketProxyPrivate { | |
| 98 public: | |
| 99 DECLARE_EXTENSION_FUNCTION_NAME("webSocketProxyPrivate.getPassportForTCP") | |
| 100 | |
| 101 WebSocketProxyPrivateGetPassportForTCPFunction(); | |
| 102 | |
| 103 protected: | |
| 104 virtual ~WebSocketProxyPrivateGetPassportForTCPFunction(); | |
| 105 | |
| 106 // WebSocketProxyPrivate implementation: | |
| 107 virtual void CustomFinalize() OVERRIDE; | |
| 108 }; | |
| 109 | |
| 110 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEB_SOCKET_PROXY_PRIVATE_API_H_ | |
| OLD | NEW |