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