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