| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_HOST_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_HOST_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_HOST_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_HOST_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "base/time/time.h" | |
| 14 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
| 15 #include "content/common/websocket.h" | 13 #include "content/common/websocket.h" |
| 16 | 14 |
| 17 class GURL; | 15 class GURL; |
| 18 | 16 |
| 19 namespace url { | 17 namespace url { |
| 20 class Origin; | 18 class Origin; |
| 21 } // namespace url | 19 } // namespace url |
| 22 | 20 |
| 23 namespace net { | 21 namespace net { |
| 24 class WebSocketChannel; | 22 class WebSocketChannel; |
| 25 class URLRequestContext; | 23 class URLRequestContext; |
| 26 } // namespace net | 24 } // namespace net |
| 27 | 25 |
| 28 namespace IPC { | 26 namespace IPC { |
| 29 class Message; | 27 class Message; |
| 30 } // namespace IPC | 28 } // namespace IPC |
| 31 | 29 |
| 32 namespace content { | 30 namespace content { |
| 33 | 31 |
| 34 class WebSocketDispatcherHost; | 32 class WebSocketDispatcherHost; |
| 35 | 33 |
| 36 // Host of net::WebSocketChannel. The lifetime of an instance of this class is | 34 // Host of net::WebSocketChannel. The lifetime of an instance of this class is |
| 37 // completely controlled by the WebSocketDispatcherHost object. | 35 // completely controlled by the WebSocketDispatcherHost object. |
| 38 class CONTENT_EXPORT WebSocketHost { | 36 class CONTENT_EXPORT WebSocketHost { |
| 39 public: | 37 public: |
| 40 WebSocketHost(int routing_id, | 38 WebSocketHost(int routing_id, |
| 41 WebSocketDispatcherHost* dispatcher, | 39 WebSocketDispatcherHost* dispatcher, |
| 42 net::URLRequestContext* url_request_context, | 40 net::URLRequestContext* url_request_context); |
| 43 base::TimeDelta delay); | |
| 44 virtual ~WebSocketHost(); | 41 virtual ~WebSocketHost(); |
| 45 | 42 |
| 46 // The renderer process is going away. | 43 // The renderer process is going away. |
| 47 // This function is virtual for testing. | 44 // This function is virtual for testing. |
| 48 virtual void GoAway(); | 45 virtual void GoAway(); |
| 49 | 46 |
| 50 // General message dispatch. WebSocketDispatcherHost::OnMessageReceived | 47 // General message dispatch. WebSocketDispatcherHost::OnMessageReceived |
| 51 // delegates to this method after looking up the |routing_id|. | 48 // delegates to this method after looking up the |routing_id|. |
| 52 virtual bool OnMessageReceived(const IPC::Message& message); | 49 virtual bool OnMessageReceived(const IPC::Message& message); |
| 53 | 50 |
| 54 int routing_id() const { return routing_id_; } | 51 int routing_id() const { return routing_id_; } |
| 55 | 52 |
| 56 bool handshake_succeeded() const { return handshake_succeeded_; } | |
| 57 void OnHandshakeSucceeded() { handshake_succeeded_ = true; } | |
| 58 | |
| 59 private: | 53 private: |
| 60 // Handlers for each message type, dispatched by OnMessageReceived(), as | 54 // Handlers for each message type, dispatched by OnMessageReceived(), as |
| 61 // defined in content/common/websocket_messages.h | 55 // defined in content/common/websocket_messages.h |
| 62 | 56 |
| 63 void OnAddChannelRequest(const GURL& socket_url, | 57 void OnAddChannelRequest(const GURL& socket_url, |
| 64 const std::vector<std::string>& requested_protocols, | 58 const std::vector<std::string>& requested_protocols, |
| 65 const url::Origin& origin, | 59 const url::Origin& origin, |
| 66 int render_frame_id); | 60 int render_frame_id); |
| 67 | 61 |
| 68 void AddChannel(const GURL& socket_url, | |
| 69 const std::vector<std::string>& requested_protocols, | |
| 70 const url::Origin& origin, | |
| 71 int render_frame_id); | |
| 72 | |
| 73 void OnSendFrame(bool fin, | 62 void OnSendFrame(bool fin, |
| 74 WebSocketMessageType type, | 63 WebSocketMessageType type, |
| 75 const std::vector<char>& data); | 64 const std::vector<char>& data); |
| 76 | 65 |
| 77 void OnFlowControl(int64 quota); | 66 void OnFlowControl(int64 quota); |
| 78 | 67 |
| 79 void OnDropChannel(bool was_clean, uint16 code, const std::string& reason); | 68 void OnDropChannel(bool was_clean, uint16 code, const std::string& reason); |
| 80 | 69 |
| 81 // The channel we use to send events to the network. | 70 // The channel we use to send events to the network. |
| 82 scoped_ptr<net::WebSocketChannel> channel_; | 71 scoped_ptr<net::WebSocketChannel> channel_; |
| 83 | 72 |
| 84 // The WebSocketHostDispatcher that created this object. | 73 // The WebSocketHostDispatcher that created this object. |
| 85 WebSocketDispatcherHost* const dispatcher_; | 74 WebSocketDispatcherHost* const dispatcher_; |
| 86 | 75 |
| 87 // The URL request context for the channel. | 76 // The URL request context for the channel. |
| 88 net::URLRequestContext* const url_request_context_; | 77 net::URLRequestContext* const url_request_context_; |
| 89 | 78 |
| 90 // The ID used to route messages. | 79 // The ID used to route messages. |
| 91 const int routing_id_; | 80 const int routing_id_; |
| 92 | 81 |
| 93 // Delay used for per-renderer WebSocket throttling. | |
| 94 base::TimeDelta delay_; | |
| 95 | |
| 96 // SendFlowControl() is delayed when OnFlowControl() is called before | |
| 97 // AddChannel() is called. | |
| 98 // Zero indicates there is no pending SendFlowControl(). | |
| 99 int64_t pending_flow_control_quota_; | |
| 100 | |
| 101 // handshake_succeeded_ is set and used by WebSocketDispatcherHost | |
| 102 // to manage counters for per-renderer WebSocket throttling. | |
| 103 bool handshake_succeeded_; | |
| 104 | |
| 105 base::WeakPtrFactory<WebSocketHost> weak_ptr_factory_; | |
| 106 | |
| 107 DISALLOW_COPY_AND_ASSIGN(WebSocketHost); | 82 DISALLOW_COPY_AND_ASSIGN(WebSocketHost); |
| 108 }; | 83 }; |
| 109 | 84 |
| 110 } // namespace content | 85 } // namespace content |
| 111 | 86 |
| 112 #endif // CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_HOST_H_ | 87 #endif // CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_HOST_H_ |
| OLD | NEW |