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

Side by Side Diff: content/browser/websocket/websocket_impl.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_WEBSOCKET_WEBSOCKET_IMPL_H_
6 #define CONTENT_BROWSER_WEBSOCKET_WEBSOCKET_IMPL_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.mojom.h"
19 #include "mojo/public/cpp/bindings/binding.h"
20
21 class GURL;
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 storage {
37 class BlobStorageContext;
38 }
39
40 namespace content {
41 class StoragePartition;
42 class WebSocketBlobSender;
43
44 // Host of net::WebSocketChannel.
45 class CONTENT_EXPORT WebSocketImpl : public mojom::WebSocket {
46 public:
47 class Delegate {
48 public:
49 virtual ~Delegate() {}
50 virtual int GetClientProcessId() = 0;
51 virtual StoragePartition* GetStoragePartition() = 0;
52 virtual storage::BlobStorageContext* GetBlobStorageContext() = 0;
53 virtual void OnReceivedResponseFromServer(WebSocketImpl* impl) = 0;
54 virtual void OnLostConnectionToClient(WebSocketImpl* impl) = 0;
55 };
56
57 WebSocketImpl(Delegate* delegate,
58 mojom::WebSocketRequest request,
59 int render_frame_id,
60 base::TimeDelta delay);
61 ~WebSocketImpl() override;
62
63 // mojom::WebSocket methods:
64
65 // The renderer process is going away.
66 // This function is virtual for testing.
67 virtual void GoAway();
68
69 // mojom::WebSocket methods:
70 void Initialize(mojom::WebSocketClientPtr client) override;
71 void AddChannelRequest(const GURL& url,
72 mojo::Array<mojo::String> requested_protocols,
73 const url::Origin& origin) override;
74 void SendBlob(const mojo::String& uuid, uint64_t expected_size) override;
75 void SendFrame(bool fin, mojom::WebSocketMessageType type,
76 mojo::Array<uint8_t> data) override;
77 void SendFlowControl(int64_t quota) override;
78 void StartClosingHandshake(uint16_t code,
79 const mojo::String& reason) override;
80
81 bool handshake_succeeded() const { return handshake_succeeded_; }
82 void OnHandshakeSucceeded() { handshake_succeeded_ = true; }
83
84 private:
85 class WebSocketEventHandler;
86
87 void OnConnectionError();
88 void AddChannel(const GURL& socket_url,
89 const std::vector<std::string>& requested_protocols,
90 const url::Origin& origin);
91 void BlobSendComplete(int result);
92
93 Delegate* delegate_;
94 mojo::Binding<mojom::WebSocket> binding_;
95
96 mojom::WebSocketClientPtr client_;
97
98 int render_frame_id_;
99
100 // non-NULL if and only if this object is currently in "blob sending mode".
101 std::unique_ptr<WebSocketBlobSender> blob_sender_;
102
103 // The channel we use to send events to the network.
104 std::unique_ptr<net::WebSocketChannel> channel_;
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<WebSocketImpl> weak_ptr_factory_;
119
120 DISALLOW_COPY_AND_ASSIGN(WebSocketImpl);
121 };
122
123 } // namespace content
124
125 #endif // CONTENT_BROWSER_WEBSOCKET_WEBSOCKET_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698