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

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: Created 4 years, 5 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
22 namespace url {
23 class Origin;
24 } // namespace url
25
26 namespace net {
27 class WebSocketChannel;
28 class URLRequestContext;
29 } // namespace net
30
31 namespace IPC {
32 class Message;
33 } // namespace IPC
34
35 namespace content {
36
37 class WebSocketBlobSender;
38 class WebSocketDispatcherHost;
39
40 // Host of net::WebSocketChannel. The lifetime of an instance of this class is
41 // completely controlled by the WebSocketDispatcherHost object.
42 class CONTENT_EXPORT WebSocketHost {
43 public:
44 WebSocketHost(int routing_id,
45 WebSocketDispatcherHost* dispatcher,
46 net::URLRequestContext* url_request_context,
47 base::TimeDelta delay);
48 virtual ~WebSocketHost();
49
50 // The renderer process is going away.
51 // This function is virtual for testing.
52 virtual void GoAway();
53
54 // General message dispatch. WebSocketDispatcherHost::OnMessageReceived
55 // delegates to this method after looking up the |routing_id|.
56 virtual bool OnMessageReceived(const IPC::Message& message);
57
58 int routing_id() const { return routing_id_; }
59
60 bool handshake_succeeded() const { return handshake_succeeded_; }
61 void OnHandshakeSucceeded() { handshake_succeeded_ = true; }
62
63 private:
64 class WebSocketEventHandler;
65
66 // Handlers for each message type, dispatched by OnMessageReceived(), as
67 // defined in content/common/websocket_messages.h
68
69 void OnAddChannelRequest(const GURL& socket_url,
70 const std::vector<std::string>& requested_protocols,
71 const url::Origin& origin,
72 int render_frame_id);
73
74 void AddChannel(const GURL& socket_url,
75 const std::vector<std::string>& requested_protocols,
76 const url::Origin& origin,
77 int render_frame_id);
78
79 void OnSendBlob(const std::string& uuid, uint64_t expected_size);
80
81 void OnSendFrame(bool fin,
82 WebSocketMessageType type,
83 const std::vector<char>& data);
84
85 void OnFlowControl(int64_t quota);
86
87 void OnDropChannel(bool was_clean, uint16_t code, const std::string& reason);
88
89 void BlobSendComplete(int result);
90
91 // non-NULL if and only if this object is currently in "blob sending mode".
92 std::unique_ptr<WebSocketBlobSender> blob_sender_;
93
94 // The channel we use to send events to the network.
95 std::unique_ptr<net::WebSocketChannel> channel_;
96
97 // The WebSocketHostDispatcher that created this object.
98 WebSocketDispatcherHost* const dispatcher_;
99
100 // The URL request context for the channel.
101 net::URLRequestContext* const url_request_context_;
102
103 // The ID used to route messages.
104 const int routing_id_;
105
106 // Delay used for per-renderer WebSocket throttling.
107 base::TimeDelta delay_;
108
109 // SendFlowControl() is delayed when OnFlowControl() is called before
110 // AddChannel() is called.
111 // Zero indicates there is no pending SendFlowControl().
112 int64_t pending_flow_control_quota_;
113
114 // handshake_succeeded_ is set and used by WebSocketDispatcherHost
115 // to manage counters for per-renderer WebSocket throttling.
116 bool handshake_succeeded_;
117
118 base::WeakPtrFactory<WebSocketHost> weak_ptr_factory_;
119
120 DISALLOW_COPY_AND_ASSIGN(WebSocketHost);
121 };
122
123 } // namespace content
124
125 #endif // CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698