OLD | NEW |
---|---|
(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_WEBSOCKETS_WEBSOCKET_IMPL_H_ | |
6 #define CONTENT_BROWSER_WEBSOCKETS_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 } // namespace net | |
30 | |
31 namespace content { | |
32 class StoragePartition; | |
33 | |
34 // Host of net::WebSocketChannel. | |
35 class CONTENT_EXPORT WebSocketImpl | |
36 : NON_EXPORTED_BASE(public mojom::WebSocket) { | |
37 public: | |
38 class Delegate { | |
39 public: | |
40 virtual ~Delegate() {} | |
41 virtual int GetClientProcessId() = 0; | |
42 virtual StoragePartition* GetStoragePartition() = 0; | |
43 virtual void OnReceivedResponseFromServer(WebSocketImpl* impl) = 0; | |
44 virtual void OnLostConnectionToClient(WebSocketImpl* impl) = 0; | |
45 }; | |
46 | |
47 WebSocketImpl(Delegate* delegate, | |
48 mojom::WebSocketRequest request, | |
49 base::TimeDelta delay); | |
50 ~WebSocketImpl() override; | |
51 | |
52 // The renderer process is going away. | |
53 // This function is virtual for testing. | |
54 virtual void GoAway(); | |
55 | |
56 // mojom::WebSocket methods: | |
57 void AddChannelRequest(const GURL& url, | |
58 mojo::Array<mojo::String> requested_protocols, | |
59 const url::Origin& origin, | |
60 const GURL& first_party_for_cookies, | |
61 const mojo::String& user_agent_override, | |
62 int32_t render_frame_id, | |
63 mojom::WebSocketClientPtr client) override; | |
64 void SendFrame(bool fin, mojom::WebSocketMessageType type, | |
65 mojo::Array<uint8_t> data) override; | |
66 void SendFlowControl(int64_t quota) override; | |
67 void StartClosingHandshake(uint16_t code, | |
68 const mojo::String& reason) override; | |
69 | |
70 bool handshake_succeeded() const { return handshake_succeeded_; } | |
71 void OnHandshakeSucceeded() { handshake_succeeded_ = true; } | |
72 | |
73 protected: | |
74 class WebSocketEventHandler; | |
75 | |
76 void OnConnectionError(); | |
77 void AddChannel(const GURL& socket_url, | |
78 const std::vector<std::string>& requested_protocols, | |
79 const url::Origin& origin, | |
80 const GURL& first_party_for_cookies, | |
81 const std::string& user_agent_override, | |
82 int32_t render_frame_id); | |
83 | |
84 Delegate* delegate_; | |
85 mojo::Binding<mojom::WebSocket> binding_; | |
86 | |
87 mojom::WebSocketClientPtr client_; | |
88 | |
89 // The channel we use to send events to the network. | |
90 std::unique_ptr<net::WebSocketChannel> channel_; | |
91 | |
92 // Delay used for per-renderer WebSocket throttling. | |
93 base::TimeDelta delay_; | |
94 | |
95 // SendFlowControl() is delayed when OnFlowControl() is called before | |
96 // AddChannel() is called. | |
97 // Zero indicates there is no pending SendFlowControl(). | |
98 int64_t pending_flow_control_quota_; | |
99 | |
100 // handshake_succeeded_ is set and used by WebSocketDispatcherHost | |
Adam Rice
2016/07/27 02:38:54
WebSocketManager?
| |
101 // to manage counters for per-renderer WebSocket throttling. | |
102 bool handshake_succeeded_; | |
103 | |
104 base::WeakPtrFactory<WebSocketImpl> weak_ptr_factory_; | |
105 | |
106 DISALLOW_COPY_AND_ASSIGN(WebSocketImpl); | |
107 }; | |
108 | |
109 } // namespace content | |
110 | |
111 #endif // CONTENT_BROWSER_WEBSOCKETS_WEBSOCKET_IMPL_H_ | |
OLD | NEW |