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 2715803004: Introduce ThreadableLoadingContext: make threaded loading code one step away from Document (Closed)
Patch Set: . Created 3 years, 9 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
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 18 matching lines...) Expand all
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 "bindings/core/v8/SourceLocation.h" 36 #include "bindings/core/v8/SourceLocation.h"
37 #include "core/fileapi/Blob.h" 37 #include "core/fileapi/Blob.h"
38 #include "core/fileapi/FileError.h" 38 #include "core/fileapi/FileError.h"
39 #include "core/loader/ThreadableLoadingContext.h"
39 #include "modules/ModulesExport.h" 40 #include "modules/ModulesExport.h"
40 #include "modules/websockets/WebSocketChannel.h" 41 #include "modules/websockets/WebSocketChannel.h"
41 #include "modules/websockets/WebSocketHandle.h" 42 #include "modules/websockets/WebSocketHandle.h"
42 #include "modules/websockets/WebSocketHandleClient.h" 43 #include "modules/websockets/WebSocketHandleClient.h"
43 #include "platform/WebFrameScheduler.h" 44 #include "platform/WebFrameScheduler.h"
44 #include "platform/heap/Handle.h" 45 #include "platform/heap/Handle.h"
45 #include "platform/weborigin/KURL.h" 46 #include "platform/weborigin/KURL.h"
46 #include "wtf/Deque.h" 47 #include "wtf/Deque.h"
47 #include "wtf/PassRefPtr.h" 48 #include "wtf/PassRefPtr.h"
48 #include "wtf/RefPtr.h" 49 #include "wtf/RefPtr.h"
49 #include "wtf/Vector.h" 50 #include "wtf/Vector.h"
50 #include "wtf/text/CString.h" 51 #include "wtf/text/CString.h"
51 #include "wtf/text/WTFString.h" 52 #include "wtf/text/WTFString.h"
52 53
53 namespace blink { 54 namespace blink {
54 55
55 class Document; 56 class ThreadableLoadingContext;
56 class WebSocketHandshakeRequest; 57 class WebSocketHandshakeRequest;
57 58
58 // 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
59 // DOMWindow (i.e. works in the main thread). 60 // DOMWindow (i.e. works in the main thread).
60 class MODULES_EXPORT DocumentWebSocketChannel final 61 class MODULES_EXPORT DocumentWebSocketChannel final
61 : public WebSocketChannel, 62 : public WebSocketChannel,
62 public WebSocketHandleClient { 63 public WebSocketHandleClient {
63 public: 64 public:
64 // You can specify the source file and the line number information 65 // You can specify the source file and the line number information
65 // explicitly by passing the last parameter. 66 // explicitly by passing the last parameter.
66 // 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
67 // pass it. 68 // pass it.
68 // Specify handle explicitly only in tests. 69 // Specify handle explicitly only in tests.
69 static DocumentWebSocketChannel* create( 70 static DocumentWebSocketChannel* create(
70 Document* document, 71 Document* document,
71 WebSocketChannelClient* client, 72 WebSocketChannelClient* client,
72 std::unique_ptr<SourceLocation> location, 73 std::unique_ptr<SourceLocation> location,
73 WebSocketHandle* handle = 0) { 74 WebSocketHandle* handle = 0) {
74 return new DocumentWebSocketChannel(document, client, std::move(location), 75 DCHECK(document);
75 handle); 76 return create(ThreadableLoadingContext::create(*document), client,
77 std::move(location), handle);
78 }
79 static DocumentWebSocketChannel* create(
80 ThreadableLoadingContext* loadingContext,
81 WebSocketChannelClient* client,
82 std::unique_ptr<SourceLocation> location,
83 WebSocketHandle* handle = 0) {
84 return new DocumentWebSocketChannel(loadingContext, client,
85 std::move(location), handle);
76 } 86 }
77 ~DocumentWebSocketChannel() override; 87 ~DocumentWebSocketChannel() override;
78 88
79 // WebSocketChannel functions. 89 // WebSocketChannel functions.
80 bool connect(const KURL&, const String& protocol) override; 90 bool connect(const KURL&, const String& protocol) override;
81 void send(const CString& message) override; 91 void send(const CString& message) override;
82 void send(const DOMArrayBuffer&, 92 void send(const DOMArrayBuffer&,
83 unsigned byteOffset, 93 unsigned byteOffset,
84 unsigned byteLength) override; 94 unsigned byteLength) override;
85 void send(PassRefPtr<BlobDataHandle>) override; 95 void send(PassRefPtr<BlobDataHandle>) override;
(...skipping 20 matching lines...) Expand all
106 MessageTypeTextAsCharVector, 116 MessageTypeTextAsCharVector,
107 MessageTypeBinaryAsCharVector, 117 MessageTypeBinaryAsCharVector,
108 MessageTypeClose, 118 MessageTypeClose,
109 }; 119 };
110 120
111 struct ReceivedMessage { 121 struct ReceivedMessage {
112 bool isMessageText; 122 bool isMessageText;
113 Vector<char> data; 123 Vector<char> data;
114 }; 124 };
115 125
116 DocumentWebSocketChannel(Document*, 126 DocumentWebSocketChannel(ThreadableLoadingContext*,
117 WebSocketChannelClient*, 127 WebSocketChannelClient*,
118 std::unique_ptr<SourceLocation>, 128 std::unique_ptr<SourceLocation>,
119 WebSocketHandle*); 129 WebSocketHandle*);
120 void sendInternal(WebSocketHandle::MessageType, 130 void sendInternal(WebSocketHandle::MessageType,
121 const char* data, 131 const char* data,
122 size_t totalSize, 132 size_t totalSize,
123 uint64_t* consumedBufferedAmount); 133 uint64_t* consumedBufferedAmount);
124 void processSendQueue(); 134 void processSendQueue();
125 void flowControlIfNecessary(); 135 void flowControlIfNecessary();
126 void failAsError(const String& reason) { 136 void failAsError(const String& reason) {
127 fail(reason, ErrorMessageLevel, m_locationAtConstruction->clone()); 137 fail(reason, ErrorMessageLevel, m_locationAtConstruction->clone());
128 } 138 }
129 void abortAsyncOperations(); 139 void abortAsyncOperations();
130 void handleDidClose(bool wasClean, unsigned short code, const String& reason); 140 void handleDidClose(bool wasClean, unsigned short code, const String& reason);
141 ThreadableLoadingContext* loadingContext();
142
143 // This may return nullptr.
144 // TODO(kinuko): Remove dependency to document.
131 Document* document(); 145 Document* document();
132 146
133 // WebSocketHandleClient functions. 147 // WebSocketHandleClient functions.
134 void didConnect(WebSocketHandle*, 148 void didConnect(WebSocketHandle*,
135 const String& selectedProtocol, 149 const String& selectedProtocol,
136 const String& extensions) override; 150 const String& extensions) override;
137 void didStartOpeningHandshake(WebSocketHandle*, 151 void didStartOpeningHandshake(WebSocketHandle*,
138 PassRefPtr<WebSocketHandshakeRequest>) override; 152 PassRefPtr<WebSocketHandshakeRequest>) override;
139 void didFinishOpeningHandshake(WebSocketHandle*, 153 void didFinishOpeningHandshake(WebSocketHandle*,
140 const WebSocketHandshakeResponse*) override; 154 const WebSocketHandshakeResponse*) override;
(...skipping 20 matching lines...) Expand all
161 175
162 // m_client can be deleted while this channel is alive, but this class 176 // m_client can be deleted while this channel is alive, but this class
163 // expects that disconnect() is called before the deletion. 177 // expects that disconnect() is called before the deletion.
164 Member<WebSocketChannelClient> m_client; 178 Member<WebSocketChannelClient> m_client;
165 KURL m_url; 179 KURL m_url;
166 // m_identifier > 0 means calling scriptContextExecution() returns a Document. 180 // m_identifier > 0 means calling scriptContextExecution() returns a Document.
167 unsigned long m_identifier; 181 unsigned long m_identifier;
168 Member<BlobLoader> m_blobLoader; 182 Member<BlobLoader> m_blobLoader;
169 HeapDeque<Member<Message>> m_messages; 183 HeapDeque<Member<Message>> m_messages;
170 Vector<char> m_receivingMessageData; 184 Vector<char> m_receivingMessageData;
171 Member<Document> m_document; 185 Member<ThreadableLoadingContext> m_loadingContext;
172 186
173 bool m_receivingMessageTypeIsText; 187 bool m_receivingMessageTypeIsText;
174 uint64_t m_sendingQuota; 188 uint64_t m_sendingQuota;
175 uint64_t m_receivedDataSizeForFlowControl; 189 uint64_t m_receivedDataSizeForFlowControl;
176 size_t m_sentSizeOfTopMessage; 190 size_t m_sentSizeOfTopMessage;
177 std::unique_ptr<WebFrameScheduler::ActiveConnectionHandle> 191 std::unique_ptr<WebFrameScheduler::ActiveConnectionHandle>
178 connection_handle_for_scheduler_; 192 connection_handle_for_scheduler_;
179 193
180 std::unique_ptr<SourceLocation> m_locationAtConstruction; 194 std::unique_ptr<SourceLocation> m_locationAtConstruction;
181 RefPtr<WebSocketHandshakeRequest> m_handshakeRequest; 195 RefPtr<WebSocketHandshakeRequest> m_handshakeRequest;
182 196
183 static const uint64_t receivedDataSizeForFlowControlHighWaterMark = 1 << 15; 197 static const uint64_t receivedDataSizeForFlowControlHighWaterMark = 1 << 15;
184 }; 198 };
185 199
186 std::ostream& operator<<(std::ostream&, const DocumentWebSocketChannel*); 200 std::ostream& operator<<(std::ostream&, const DocumentWebSocketChannel*);
187 201
188 } // namespace blink 202 } // namespace blink
189 203
190 #endif // DocumentWebSocketChannel_h 204 #endif // DocumentWebSocketChannel_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698