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

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

Issue 2939123002: Revert of Add blink::WebSocketHandshakeThrottle (Closed)
Patch Set: 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>
37 #include "bindings/core/v8/SourceLocation.h" 36 #include "bindings/core/v8/SourceLocation.h"
38 #include "core/fileapi/Blob.h" 37 #include "core/fileapi/Blob.h"
39 #include "core/fileapi/FileError.h" 38 #include "core/fileapi/FileError.h"
40 #include "core/loader/ThreadableLoadingContext.h" 39 #include "core/loader/ThreadableLoadingContext.h"
41 #include "modules/ModulesExport.h" 40 #include "modules/ModulesExport.h"
42 #include "modules/websockets/WebSocketChannel.h" 41 #include "modules/websockets/WebSocketChannel.h"
43 #include "modules/websockets/WebSocketHandle.h" 42 #include "modules/websockets/WebSocketHandle.h"
44 #include "modules/websockets/WebSocketHandleClient.h" 43 #include "modules/websockets/WebSocketHandleClient.h"
45 #include "platform/WebFrameScheduler.h" 44 #include "platform/WebFrameScheduler.h"
46 #include "platform/heap/Handle.h" 45 #include "platform/heap/Handle.h"
47 #include "platform/weborigin/KURL.h" 46 #include "platform/weborigin/KURL.h"
48 #include "platform/wtf/Deque.h" 47 #include "platform/wtf/Deque.h"
49 #include "platform/wtf/PassRefPtr.h" 48 #include "platform/wtf/PassRefPtr.h"
50 #include "platform/wtf/RefPtr.h" 49 #include "platform/wtf/RefPtr.h"
51 #include "platform/wtf/Vector.h" 50 #include "platform/wtf/Vector.h"
52 #include "platform/wtf/text/CString.h" 51 #include "platform/wtf/text/CString.h"
53 #include "platform/wtf/text/WTFString.h" 52 #include "platform/wtf/text/WTFString.h"
54 #include "public/platform/WebCallbacks.h"
55 53
56 namespace blink { 54 namespace blink {
57 55
58 class ThreadableLoadingContext; 56 class ThreadableLoadingContext;
59 class WebSocketHandshakeRequest; 57 class WebSocketHandshakeRequest;
60 class WebSocketHandshakeThrottle;
61 58
62 // This class is a WebSocketChannel subclass that works with a Document in a 59 // This class is a WebSocketChannel subclass that works with a Document in a
63 // DOMWindow (i.e. works in the main thread). 60 // DOMWindow (i.e. works in the main thread).
64 class MODULES_EXPORT DocumentWebSocketChannel final 61 class MODULES_EXPORT DocumentWebSocketChannel final
65 : public WebSocketChannel, 62 : public WebSocketChannel,
66 public WebSocketHandleClient, 63 public WebSocketHandleClient {
67 public WebCallbacks<void, const WebString&> {
68 public: 64 public:
69 // You can specify the source file and the line number information 65 // You can specify the source file and the line number information
70 // explicitly by passing the last parameter. 66 // explicitly by passing the last parameter.
71 // In the usual case, they are set automatically and you don't have to 67 // In the usual case, they are set automatically and you don't have to
72 // pass it. 68 // pass it.
69 // Specify handle explicitly only in tests.
73 static DocumentWebSocketChannel* Create( 70 static DocumentWebSocketChannel* Create(
74 Document* document, 71 Document* document,
75 WebSocketChannelClient* client, 72 WebSocketChannelClient* client,
76 std::unique_ptr<SourceLocation> location) { 73 std::unique_ptr<SourceLocation> location,
74 WebSocketHandle* handle = 0) {
77 DCHECK(document); 75 DCHECK(document);
78 return Create(ThreadableLoadingContext::Create(*document), client, 76 return Create(ThreadableLoadingContext::Create(*document), client,
79 std::move(location)); 77 std::move(location), handle);
80 } 78 }
81 static DocumentWebSocketChannel* Create(ThreadableLoadingContext*, 79 static DocumentWebSocketChannel* Create(
82 WebSocketChannelClient*, 80 ThreadableLoadingContext* loading_context,
83 std::unique_ptr<SourceLocation>); 81 WebSocketChannelClient* client,
84 static DocumentWebSocketChannel* CreateForTesting( 82 std::unique_ptr<SourceLocation> location,
85 Document*, 83 WebSocketHandle* handle = 0) {
86 WebSocketChannelClient*, 84 return new DocumentWebSocketChannel(loading_context, client,
87 std::unique_ptr<SourceLocation>, 85 std::move(location), handle);
88 WebSocketHandle*, 86 }
89 std::unique_ptr<WebSocketHandshakeThrottle>);
90
91 ~DocumentWebSocketChannel() override; 87 ~DocumentWebSocketChannel() override;
92 88
93 // WebSocketChannel functions. 89 // WebSocketChannel functions.
94 bool Connect(const KURL&, const String& protocol) override; 90 bool Connect(const KURL&, const String& protocol) override;
95 void Send(const CString& message) override; 91 void Send(const CString& message) override;
96 void Send(const DOMArrayBuffer&, 92 void Send(const DOMArrayBuffer&,
97 unsigned byte_offset, 93 unsigned byte_offset,
98 unsigned byte_length) override; 94 unsigned byte_length) override;
99 void Send(PassRefPtr<BlobDataHandle>) override; 95 void Send(PassRefPtr<BlobDataHandle>) override;
100 void SendTextAsCharVector(std::unique_ptr<Vector<char>> data) override; 96 void SendTextAsCharVector(std::unique_ptr<Vector<char>> data) override;
101 void SendBinaryAsCharVector(std::unique_ptr<Vector<char>> data) override; 97 void SendBinaryAsCharVector(std::unique_ptr<Vector<char>> data) override;
102 // Start closing handshake. Use the CloseEventCodeNotSpecified for the code 98 // Start closing handshake. Use the CloseEventCodeNotSpecified for the code
103 // argument to omit payload. 99 // argument to omit payload.
104 void Close(int code, const String& reason) override; 100 void Close(int code, const String& reason) override;
105 void Fail(const String& reason, 101 void Fail(const String& reason,
106 MessageLevel, 102 MessageLevel,
107 std::unique_ptr<SourceLocation>) override; 103 std::unique_ptr<SourceLocation>) override;
108 void Disconnect() override; 104 void Disconnect() override;
109 105
110 DECLARE_VIRTUAL_TRACE(); 106 DECLARE_VIRTUAL_TRACE();
111 107
112 private: 108 private:
113 class BlobLoader; 109 class BlobLoader;
114 class Message; 110 class Message;
115 struct ConnectInfo;
116 111
117 enum MessageType { 112 enum MessageType {
118 kMessageTypeText, 113 kMessageTypeText,
119 kMessageTypeBlob, 114 kMessageTypeBlob,
120 kMessageTypeArrayBuffer, 115 kMessageTypeArrayBuffer,
121 kMessageTypeTextAsCharVector, 116 kMessageTypeTextAsCharVector,
122 kMessageTypeBinaryAsCharVector, 117 kMessageTypeBinaryAsCharVector,
123 kMessageTypeClose, 118 kMessageTypeClose,
124 }; 119 };
125 120
126 struct ReceivedMessage { 121 struct ReceivedMessage {
127 bool is_message_text; 122 bool is_message_text;
128 Vector<char> data; 123 Vector<char> data;
129 }; 124 };
130 125
131 DocumentWebSocketChannel(ThreadableLoadingContext*, 126 DocumentWebSocketChannel(ThreadableLoadingContext*,
132 WebSocketChannelClient*, 127 WebSocketChannelClient*,
133 std::unique_ptr<SourceLocation>, 128 std::unique_ptr<SourceLocation>,
134 std::unique_ptr<WebSocketHandle>, 129 WebSocketHandle*);
135 std::unique_ptr<WebSocketHandshakeThrottle>);
136
137 void SendInternal(WebSocketHandle::MessageType, 130 void SendInternal(WebSocketHandle::MessageType,
138 const char* data, 131 const char* data,
139 size_t total_size, 132 size_t total_size,
140 uint64_t* consumed_buffered_amount); 133 uint64_t* consumed_buffered_amount);
141 void ProcessSendQueue(); 134 void ProcessSendQueue();
142 void FlowControlIfNecessary(); 135 void FlowControlIfNecessary();
143 void FailAsError(const String& reason) { 136 void FailAsError(const String& reason) {
144 Fail(reason, kErrorMessageLevel, location_at_construction_->Clone()); 137 Fail(reason, kErrorMessageLevel, location_at_construction_->Clone());
145 } 138 }
146 void AbortAsyncOperations(); 139 void AbortAsyncOperations();
(...skipping 20 matching lines...) Expand all
167 WebSocketHandle::MessageType, 160 WebSocketHandle::MessageType,
168 const char* data, 161 const char* data,
169 size_t) override; 162 size_t) override;
170 void DidClose(WebSocketHandle*, 163 void DidClose(WebSocketHandle*,
171 bool was_clean, 164 bool was_clean,
172 unsigned short code, 165 unsigned short code,
173 const String& reason) override; 166 const String& reason) override;
174 void DidReceiveFlowControl(WebSocketHandle*, int64_t quota) override; 167 void DidReceiveFlowControl(WebSocketHandle*, int64_t quota) override;
175 void DidStartClosingHandshake(WebSocketHandle*) override; 168 void DidStartClosingHandshake(WebSocketHandle*) override;
176 169
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
182 // Methods for BlobLoader. 170 // Methods for BlobLoader.
183 void DidFinishLoadingBlob(DOMArrayBuffer*); 171 void DidFinishLoadingBlob(DOMArrayBuffer*);
184 void DidFailLoadingBlob(FileError::ErrorCode); 172 void DidFailLoadingBlob(FileError::ErrorCode);
185 173
186 void TearDownFailedConnection(); 174 void TearDownFailedConnection();
187 bool ShouldDisallowConnection(const KURL&); 175 bool ShouldDisallowConnection(const KURL&);
188 176
189 // m_handle is a handle of the connection. 177 // m_handle is a handle of the connection.
190 // m_handle == 0 means this channel is closed. 178 // m_handle == 0 means this channel is closed.
191 std::unique_ptr<WebSocketHandle> handle_; 179 std::unique_ptr<WebSocketHandle> handle_;
(...skipping 11 matching lines...) Expand all
203 191
204 bool receiving_message_type_is_text_; 192 bool receiving_message_type_is_text_;
205 uint64_t sending_quota_; 193 uint64_t sending_quota_;
206 uint64_t received_data_size_for_flow_control_; 194 uint64_t received_data_size_for_flow_control_;
207 size_t sent_size_of_top_message_; 195 size_t sent_size_of_top_message_;
208 std::unique_ptr<WebFrameScheduler::ActiveConnectionHandle> 196 std::unique_ptr<WebFrameScheduler::ActiveConnectionHandle>
209 connection_handle_for_scheduler_; 197 connection_handle_for_scheduler_;
210 198
211 std::unique_ptr<SourceLocation> location_at_construction_; 199 std::unique_ptr<SourceLocation> location_at_construction_;
212 RefPtr<WebSocketHandshakeRequest> handshake_request_; 200 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_;
218 201
219 static const uint64_t kReceivedDataSizeForFlowControlHighWaterMark = 1 << 15; 202 static const uint64_t kReceivedDataSizeForFlowControlHighWaterMark = 1 << 15;
220 }; 203 };
221 204
222 std::ostream& operator<<(std::ostream&, const DocumentWebSocketChannel*); 205 std::ostream& operator<<(std::ostream&, const DocumentWebSocketChannel*);
223 206
224 } // namespace blink 207 } // namespace blink
225 208
226 #endif // DocumentWebSocketChannel_h 209 #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