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

Side by Side Diff: third_party/WebKit/Source/modules/websockets/DocumentWebSocketChannel.h

Issue 2930263002: Add blink::WebSocketHandshakeThrottle (Closed)
Patch Set: Fixes from yhirano review Created 3 years, 6 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/websockets/DocumentWebSocketChannel.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef DocumentWebSocketChannel_h 31 #ifndef DocumentWebSocketChannel_h
32 #define DocumentWebSocketChannel_h 32 #define DocumentWebSocketChannel_h
33 33
34 #include <stdint.h> 34 #include <stdint.h>
35 #include <memory> 35 #include <memory>
36 #include <utility>
36 #include "bindings/core/v8/SourceLocation.h" 37 #include "bindings/core/v8/SourceLocation.h"
37 #include "core/fileapi/Blob.h" 38 #include "core/fileapi/Blob.h"
38 #include "core/fileapi/FileError.h" 39 #include "core/fileapi/FileError.h"
39 #include "core/loader/ThreadableLoadingContext.h" 40 #include "core/loader/ThreadableLoadingContext.h"
40 #include "modules/ModulesExport.h" 41 #include "modules/ModulesExport.h"
41 #include "modules/websockets/WebSocketChannel.h" 42 #include "modules/websockets/WebSocketChannel.h"
42 #include "modules/websockets/WebSocketHandle.h" 43 #include "modules/websockets/WebSocketHandle.h"
43 #include "modules/websockets/WebSocketHandleClient.h" 44 #include "modules/websockets/WebSocketHandleClient.h"
44 #include "platform/WebFrameScheduler.h" 45 #include "platform/WebFrameScheduler.h"
45 #include "platform/heap/Handle.h" 46 #include "platform/heap/Handle.h"
46 #include "platform/weborigin/KURL.h" 47 #include "platform/weborigin/KURL.h"
47 #include "platform/wtf/Deque.h" 48 #include "platform/wtf/Deque.h"
48 #include "platform/wtf/PassRefPtr.h" 49 #include "platform/wtf/PassRefPtr.h"
49 #include "platform/wtf/RefPtr.h" 50 #include "platform/wtf/RefPtr.h"
50 #include "platform/wtf/Vector.h" 51 #include "platform/wtf/Vector.h"
51 #include "platform/wtf/text/CString.h" 52 #include "platform/wtf/text/CString.h"
52 #include "platform/wtf/text/WTFString.h" 53 #include "platform/wtf/text/WTFString.h"
54 #include "public/platform/WebCallbacks.h"
53 55
54 namespace blink { 56 namespace blink {
55 57
56 class ThreadableLoadingContext; 58 class ThreadableLoadingContext;
57 class WebSocketHandshakeRequest; 59 class WebSocketHandshakeRequest;
60 class WebSocketHandshakeThrottle;
58 61
59 // This class is a WebSocketChannel subclass that works with a Document in a 62 // This class is a WebSocketChannel subclass that works with a Document in a
60 // DOMWindow (i.e. works in the main thread). 63 // DOMWindow (i.e. works in the main thread).
61 class MODULES_EXPORT DocumentWebSocketChannel final 64 class MODULES_EXPORT DocumentWebSocketChannel final
62 : public WebSocketChannel, 65 : public WebSocketChannel,
63 public WebSocketHandleClient { 66 public WebSocketHandleClient,
67 public WebCallbacks<void, const WebString&> {
64 public: 68 public:
65 // You can specify the source file and the line number information 69 // You can specify the source file and the line number information
66 // explicitly by passing the last parameter. 70 // explicitly by passing the last parameter.
67 // In the usual case, they are set automatically and you don't have to 71 // In the usual case, they are set automatically and you don't have to
68 // pass it. 72 // pass it.
69 // Specify handle explicitly only in tests.
70 static DocumentWebSocketChannel* Create( 73 static DocumentWebSocketChannel* Create(
71 Document* document, 74 Document* document,
72 WebSocketChannelClient* client, 75 WebSocketChannelClient* client,
73 std::unique_ptr<SourceLocation> location, 76 std::unique_ptr<SourceLocation> location) {
74 WebSocketHandle* handle = 0) {
75 DCHECK(document); 77 DCHECK(document);
76 return Create(ThreadableLoadingContext::Create(*document), client, 78 return Create(ThreadableLoadingContext::Create(*document), client,
77 std::move(location), handle); 79 std::move(location));
78 } 80 }
79 static DocumentWebSocketChannel* Create( 81 static DocumentWebSocketChannel* Create(ThreadableLoadingContext*,
80 ThreadableLoadingContext* loading_context, 82 WebSocketChannelClient*,
81 WebSocketChannelClient* client, 83 std::unique_ptr<SourceLocation>);
82 std::unique_ptr<SourceLocation> location, 84 static DocumentWebSocketChannel* CreateForTesting(
83 WebSocketHandle* handle = 0) { 85 Document*,
84 return new DocumentWebSocketChannel(loading_context, client, 86 WebSocketChannelClient*,
85 std::move(location), handle); 87 std::unique_ptr<SourceLocation>,
86 } 88 WebSocketHandle*,
89 std::unique_ptr<WebSocketHandshakeThrottle>);
90
87 ~DocumentWebSocketChannel() override; 91 ~DocumentWebSocketChannel() override;
88 92
89 // WebSocketChannel functions. 93 // WebSocketChannel functions.
90 bool Connect(const KURL&, const String& protocol) override; 94 bool Connect(const KURL&, const String& protocol) override;
91 void Send(const CString& message) override; 95 void Send(const CString& message) override;
92 void Send(const DOMArrayBuffer&, 96 void Send(const DOMArrayBuffer&,
93 unsigned byte_offset, 97 unsigned byte_offset,
94 unsigned byte_length) override; 98 unsigned byte_length) override;
95 void Send(PassRefPtr<BlobDataHandle>) override; 99 void Send(PassRefPtr<BlobDataHandle>) override;
96 void SendTextAsCharVector(std::unique_ptr<Vector<char>> data) override; 100 void SendTextAsCharVector(std::unique_ptr<Vector<char>> data) override;
97 void SendBinaryAsCharVector(std::unique_ptr<Vector<char>> data) override; 101 void SendBinaryAsCharVector(std::unique_ptr<Vector<char>> data) override;
98 // Start closing handshake. Use the CloseEventCodeNotSpecified for the code 102 // Start closing handshake. Use the CloseEventCodeNotSpecified for the code
99 // argument to omit payload. 103 // argument to omit payload.
100 void Close(int code, const String& reason) override; 104 void Close(int code, const String& reason) override;
101 void Fail(const String& reason, 105 void Fail(const String& reason,
102 MessageLevel, 106 MessageLevel,
103 std::unique_ptr<SourceLocation>) override; 107 std::unique_ptr<SourceLocation>) override;
104 void Disconnect() override; 108 void Disconnect() override;
105 109
106 DECLARE_VIRTUAL_TRACE(); 110 DECLARE_VIRTUAL_TRACE();
107 111
108 private: 112 private:
109 class BlobLoader; 113 class BlobLoader;
110 class Message; 114 class Message;
115 struct ConnectInfo;
111 116
112 enum MessageType { 117 enum MessageType {
113 kMessageTypeText, 118 kMessageTypeText,
114 kMessageTypeBlob, 119 kMessageTypeBlob,
115 kMessageTypeArrayBuffer, 120 kMessageTypeArrayBuffer,
116 kMessageTypeTextAsCharVector, 121 kMessageTypeTextAsCharVector,
117 kMessageTypeBinaryAsCharVector, 122 kMessageTypeBinaryAsCharVector,
118 kMessageTypeClose, 123 kMessageTypeClose,
119 }; 124 };
120 125
121 struct ReceivedMessage { 126 struct ReceivedMessage {
122 bool is_message_text; 127 bool is_message_text;
123 Vector<char> data; 128 Vector<char> data;
124 }; 129 };
125 130
126 DocumentWebSocketChannel(ThreadableLoadingContext*, 131 DocumentWebSocketChannel(ThreadableLoadingContext*,
127 WebSocketChannelClient*, 132 WebSocketChannelClient*,
128 std::unique_ptr<SourceLocation>, 133 std::unique_ptr<SourceLocation>,
129 WebSocketHandle*); 134 std::unique_ptr<WebSocketHandle>,
135 std::unique_ptr<WebSocketHandshakeThrottle>);
136
130 void SendInternal(WebSocketHandle::MessageType, 137 void SendInternal(WebSocketHandle::MessageType,
131 const char* data, 138 const char* data,
132 size_t total_size, 139 size_t total_size,
133 uint64_t* consumed_buffered_amount); 140 uint64_t* consumed_buffered_amount);
134 void ProcessSendQueue(); 141 void ProcessSendQueue();
135 void FlowControlIfNecessary(); 142 void FlowControlIfNecessary();
136 void FailAsError(const String& reason) { 143 void FailAsError(const String& reason) {
137 Fail(reason, kErrorMessageLevel, location_at_construction_->Clone()); 144 Fail(reason, kErrorMessageLevel, location_at_construction_->Clone());
138 } 145 }
139 void AbortAsyncOperations(); 146 void AbortAsyncOperations();
(...skipping 20 matching lines...) Expand all
160 WebSocketHandle::MessageType, 167 WebSocketHandle::MessageType,
161 const char* data, 168 const char* data,
162 size_t) override; 169 size_t) override;
163 void DidClose(WebSocketHandle*, 170 void DidClose(WebSocketHandle*,
164 bool was_clean, 171 bool was_clean,
165 unsigned short code, 172 unsigned short code,
166 const String& reason) override; 173 const String& reason) override;
167 void DidReceiveFlowControl(WebSocketHandle*, int64_t quota) override; 174 void DidReceiveFlowControl(WebSocketHandle*, int64_t quota) override;
168 void DidStartClosingHandshake(WebSocketHandle*) override; 175 void DidStartClosingHandshake(WebSocketHandle*) override;
169 176
177 // WebCallbacks<void, const WebString&> functions. These are called with the
178 // results of throttling.
179 void OnSuccess() override;
180 void OnError(const WebString& console_message) override;
181
170 // Methods for BlobLoader. 182 // Methods for BlobLoader.
171 void DidFinishLoadingBlob(DOMArrayBuffer*); 183 void DidFinishLoadingBlob(DOMArrayBuffer*);
172 void DidFailLoadingBlob(FileError::ErrorCode); 184 void DidFailLoadingBlob(FileError::ErrorCode);
173 185
174 void TearDownFailedConnection(); 186 void TearDownFailedConnection();
175 bool ShouldDisallowConnection(const KURL&); 187 bool ShouldDisallowConnection(const KURL&);
176 188
177 // m_handle is a handle of the connection. 189 // m_handle is a handle of the connection.
178 // m_handle == 0 means this channel is closed. 190 // m_handle == 0 means this channel is closed.
179 std::unique_ptr<WebSocketHandle> handle_; 191 std::unique_ptr<WebSocketHandle> handle_;
(...skipping 11 matching lines...) Expand all
191 203
192 bool receiving_message_type_is_text_; 204 bool receiving_message_type_is_text_;
193 uint64_t sending_quota_; 205 uint64_t sending_quota_;
194 uint64_t received_data_size_for_flow_control_; 206 uint64_t received_data_size_for_flow_control_;
195 size_t sent_size_of_top_message_; 207 size_t sent_size_of_top_message_;
196 std::unique_ptr<WebFrameScheduler::ActiveConnectionHandle> 208 std::unique_ptr<WebFrameScheduler::ActiveConnectionHandle>
197 connection_handle_for_scheduler_; 209 connection_handle_for_scheduler_;
198 210
199 std::unique_ptr<SourceLocation> location_at_construction_; 211 std::unique_ptr<SourceLocation> location_at_construction_;
200 RefPtr<WebSocketHandshakeRequest> handshake_request_; 212 RefPtr<WebSocketHandshakeRequest> handshake_request_;
213 std::unique_ptr<WebSocketHandshakeThrottle> handshake_throttle_;
214 // This field is only initialised if the object is still waiting for a
215 // throttle response when DidConnect is called.
216 std::unique_ptr<ConnectInfo> connect_info_;
217 bool throttle_passed_;
201 218
202 static const uint64_t kReceivedDataSizeForFlowControlHighWaterMark = 1 << 15; 219 static const uint64_t kReceivedDataSizeForFlowControlHighWaterMark = 1 << 15;
203 }; 220 };
204 221
205 std::ostream& operator<<(std::ostream&, const DocumentWebSocketChannel*); 222 std::ostream& operator<<(std::ostream&, const DocumentWebSocketChannel*);
206 223
207 } // namespace blink 224 } // namespace blink
208 225
209 #endif // DocumentWebSocketChannel_h 226 #endif // DocumentWebSocketChannel_h
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/websockets/DocumentWebSocketChannel.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698