Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(700)

Side by Side Diff: content/browser/renderer_host/websocket_host.h

Issue 2119973002: Port WebSockets to Mojo IPC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile error Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_HOST_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_HOST_H_
7
8 #include <stdint.h>
9
10 #include <memory>
11 #include <string>
12 #include <vector>
13
14 #include "base/macros.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/time/time.h"
17 #include "content/common/content_export.h"
18 #include "content/common/websocket.h"
19
20 class GURL;
21 struct WebSocketHostMsg_AddChannelRequest_Params;
22
23 namespace url {
24 class Origin;
25 } // namespace url
26
27 namespace net {
28 class WebSocketChannel;
29 class URLRequestContext;
30 } // namespace net
31
32 namespace IPC {
33 class Message;
34 } // namespace IPC
35
36 namespace content {
37
38 class WebSocketBlobSender;
39 class WebSocketDispatcherHost;
40
41 // Host of net::WebSocketChannel. The lifetime of an instance of this class is
42 // completely controlled by the WebSocketDispatcherHost object.
43 class CONTENT_EXPORT WebSocketHost {
44 public:
45 WebSocketHost(int routing_id,
46 WebSocketDispatcherHost* dispatcher,
47 net::URLRequestContext* url_request_context,
48 base::TimeDelta delay);
49 virtual ~WebSocketHost();
50
51 // The renderer process is going away.
52 // This function is virtual for testing.
53 virtual void GoAway();
54
55 // General message dispatch. WebSocketDispatcherHost::OnMessageReceived
56 // delegates to this method after looking up the |routing_id|.
57 virtual bool OnMessageReceived(const IPC::Message& message);
58
59 int routing_id() const { return routing_id_; }
60
61 bool handshake_succeeded() const { return handshake_succeeded_; }
62 void OnHandshakeSucceeded() { handshake_succeeded_ = true; }
63
64 private:
65 class WebSocketEventHandler;
66
67 // Handlers for each message type, dispatched by OnMessageReceived(), as
68 // defined in content/common/websocket_messages.h
69
70 void OnAddChannelRequest(
71 const WebSocketHostMsg_AddChannelRequest_Params& request);
72
73 void AddChannel(const GURL& socket_url,
74 const std::vector<std::string>& requested_protocols,
75 const url::Origin& origin,
76 const GURL& first_party_for_cookies,
77 const std::string& user_agent_override,
78 int render_frame_id);
79
80 void OnSendBlob(const std::string& uuid, uint64_t expected_size);
81
82 void OnSendFrame(bool fin,
83 WebSocketMessageType type,
84 const std::vector<char>& data);
85
86 void OnFlowControl(int64_t quota);
87
88 void OnDropChannel(bool was_clean, uint16_t code, const std::string& reason);
89
90 void BlobSendComplete(int result);
91
92 // non-NULL if and only if this object is currently in "blob sending mode".
93 std::unique_ptr<WebSocketBlobSender> blob_sender_;
94
95 // The channel we use to send events to the network.
96 std::unique_ptr<net::WebSocketChannel> channel_;
97
98 // The WebSocketHostDispatcher that created this object.
99 WebSocketDispatcherHost* const dispatcher_;
100
101 // The URL request context for the channel.
102 net::URLRequestContext* const url_request_context_;
103
104 // The ID used to route messages.
105 const int routing_id_;
106
107 // Delay used for per-renderer WebSocket throttling.
108 base::TimeDelta delay_;
109
110 // SendFlowControl() is delayed when OnFlowControl() is called before
111 // AddChannel() is called.
112 // Zero indicates there is no pending SendFlowControl().
113 int64_t pending_flow_control_quota_;
114
115 // handshake_succeeded_ is set and used by WebSocketDispatcherHost
116 // to manage counters for per-renderer WebSocket throttling.
117 bool handshake_succeeded_;
118
119 base::WeakPtrFactory<WebSocketHost> weak_ptr_factory_;
120
121 DISALLOW_COPY_AND_ASSIGN(WebSocketHost);
122 };
123
124 } // namespace content
125
126 #endif // CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698