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

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

Issue 2080623002: Revert "Remove OwnPtr from Blink." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
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 25 matching lines...) Expand all
36 #include "core/fileapi/Blob.h" 36 #include "core/fileapi/Blob.h"
37 #include "core/fileapi/FileError.h" 37 #include "core/fileapi/FileError.h"
38 #include "modules/ModulesExport.h" 38 #include "modules/ModulesExport.h"
39 #include "modules/websockets/WebSocketChannel.h" 39 #include "modules/websockets/WebSocketChannel.h"
40 #include "platform/heap/Handle.h" 40 #include "platform/heap/Handle.h"
41 #include "platform/v8_inspector/public/ConsoleTypes.h" 41 #include "platform/v8_inspector/public/ConsoleTypes.h"
42 #include "platform/weborigin/KURL.h" 42 #include "platform/weborigin/KURL.h"
43 #include "public/platform/modules/websockets/WebSocketHandle.h" 43 #include "public/platform/modules/websockets/WebSocketHandle.h"
44 #include "public/platform/modules/websockets/WebSocketHandleClient.h" 44 #include "public/platform/modules/websockets/WebSocketHandleClient.h"
45 #include "wtf/Deque.h" 45 #include "wtf/Deque.h"
46 #include "wtf/OwnPtr.h"
47 #include "wtf/PassOwnPtr.h"
46 #include "wtf/PassRefPtr.h" 48 #include "wtf/PassRefPtr.h"
47 #include "wtf/RefPtr.h" 49 #include "wtf/RefPtr.h"
48 #include "wtf/Vector.h" 50 #include "wtf/Vector.h"
49 #include "wtf/text/CString.h" 51 #include "wtf/text/CString.h"
50 #include "wtf/text/WTFString.h" 52 #include "wtf/text/WTFString.h"
51 #include <memory>
52 #include <stdint.h> 53 #include <stdint.h>
53 54
54 namespace blink { 55 namespace blink {
55 56
56 class Document; 57 class Document;
57 class WebSocketHandshakeRequest; 58 class WebSocketHandshakeRequest;
58 class WebSocketHandshakeRequestInfo; 59 class WebSocketHandshakeRequestInfo;
59 class WebSocketHandshakeResponseInfo; 60 class WebSocketHandshakeResponseInfo;
60 61
61 // 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
62 // DOMWindow (i.e. works in the main thread). 63 // DOMWindow (i.e. works in the main thread).
63 class MODULES_EXPORT DocumentWebSocketChannel final : public WebSocketChannel, p ublic WebSocketHandleClient, public ContextLifecycleObserver { 64 class MODULES_EXPORT DocumentWebSocketChannel final : public WebSocketChannel, p ublic WebSocketHandleClient, public ContextLifecycleObserver {
64 USING_GARBAGE_COLLECTED_MIXIN(DocumentWebSocketChannel); 65 USING_GARBAGE_COLLECTED_MIXIN(DocumentWebSocketChannel);
65 public: 66 public:
66 // You can specify the source file and the line number information 67 // You can specify the source file and the line number information
67 // explicitly by passing the last parameter. 68 // explicitly by passing the last parameter.
68 // In the usual case, they are set automatically and you don't have to 69 // In the usual case, they are set automatically and you don't have to
69 // pass it. 70 // pass it.
70 // Specify handle explicitly only in tests. 71 // Specify handle explicitly only in tests.
71 static DocumentWebSocketChannel* create(Document* document, WebSocketChannel Client* client, std::unique_ptr<SourceLocation> location, WebSocketHandle *handl e = 0) 72 static DocumentWebSocketChannel* create(Document* document, WebSocketChannel Client* client, PassOwnPtr<SourceLocation> location, WebSocketHandle *handle = 0 )
72 { 73 {
73 return new DocumentWebSocketChannel(document, client, std::move(location ), handle); 74 return new DocumentWebSocketChannel(document, client, std::move(location ), handle);
74 } 75 }
75 ~DocumentWebSocketChannel() override; 76 ~DocumentWebSocketChannel() override;
76 77
77 // WebSocketChannel functions. 78 // WebSocketChannel functions.
78 bool connect(const KURL&, const String& protocol) override; 79 bool connect(const KURL&, const String& protocol) override;
79 void send(const CString& message) override; 80 void send(const CString& message) override;
80 void send(const DOMArrayBuffer&, unsigned byteOffset, unsigned byteLength) o verride; 81 void send(const DOMArrayBuffer&, unsigned byteOffset, unsigned byteLength) o verride;
81 void send(PassRefPtr<BlobDataHandle>) override; 82 void send(PassRefPtr<BlobDataHandle>) override;
82 void sendTextAsCharVector(std::unique_ptr<Vector<char>> data) override; 83 void sendTextAsCharVector(PassOwnPtr<Vector<char>> data) override;
83 void sendBinaryAsCharVector(std::unique_ptr<Vector<char>> data) override; 84 void sendBinaryAsCharVector(PassOwnPtr<Vector<char>> data) override;
84 // Start closing handshake. Use the CloseEventCodeNotSpecified for the code 85 // Start closing handshake. Use the CloseEventCodeNotSpecified for the code
85 // argument to omit payload. 86 // argument to omit payload.
86 void close(int code, const String& reason) override; 87 void close(int code, const String& reason) override;
87 void fail(const String& reason, MessageLevel, std::unique_ptr<SourceLocation >) override; 88 void fail(const String& reason, MessageLevel, PassOwnPtr<SourceLocation>) ov erride;
88 void disconnect() override; 89 void disconnect() override;
89 90
90 DECLARE_VIRTUAL_TRACE(); 91 DECLARE_VIRTUAL_TRACE();
91 92
92 private: 93 private:
93 class BlobLoader; 94 class BlobLoader;
94 class Message; 95 class Message;
95 96
96 enum MessageType { 97 enum MessageType {
97 MessageTypeText, 98 MessageTypeText,
98 MessageTypeBlob, 99 MessageTypeBlob,
99 MessageTypeArrayBuffer, 100 MessageTypeArrayBuffer,
100 MessageTypeTextAsCharVector, 101 MessageTypeTextAsCharVector,
101 MessageTypeBinaryAsCharVector, 102 MessageTypeBinaryAsCharVector,
102 MessageTypeClose, 103 MessageTypeClose,
103 }; 104 };
104 105
105 struct ReceivedMessage { 106 struct ReceivedMessage {
106 bool isMessageText; 107 bool isMessageText;
107 Vector<char> data; 108 Vector<char> data;
108 }; 109 };
109 110
110 DocumentWebSocketChannel(Document*, WebSocketChannelClient*, std::unique_ptr <SourceLocation>, WebSocketHandle*); 111 DocumentWebSocketChannel(Document*, WebSocketChannelClient*, PassOwnPtr<Sour ceLocation>, WebSocketHandle*);
111 void sendInternal(WebSocketHandle::MessageType, const char* data, size_t tot alSize, uint64_t* consumedBufferedAmount); 112 void sendInternal(WebSocketHandle::MessageType, const char* data, size_t tot alSize, uint64_t* consumedBufferedAmount);
112 void processSendQueue(); 113 void processSendQueue();
113 void flowControlIfNecessary(); 114 void flowControlIfNecessary();
114 void failAsError(const String& reason) { fail(reason, ErrorMessageLevel, m_l ocationAtConstruction->clone()); } 115 void failAsError(const String& reason) { fail(reason, ErrorMessageLevel, m_l ocationAtConstruction->clone()); }
115 void abortAsyncOperations(); 116 void abortAsyncOperations();
116 void handleDidClose(bool wasClean, unsigned short code, const String& reason ); 117 void handleDidClose(bool wasClean, unsigned short code, const String& reason );
117 Document* document(); 118 Document* document();
118 119
119 // WebSocketHandleClient functions. 120 // WebSocketHandleClient functions.
120 void didConnect(WebSocketHandle*, const WebString& selectedProtocol, const W ebString& extensions) override; 121 void didConnect(WebSocketHandle*, const WebString& selectedProtocol, const W ebString& extensions) override;
121 void didStartOpeningHandshake(WebSocketHandle*, const WebSocketHandshakeRequ estInfo&) override; 122 void didStartOpeningHandshake(WebSocketHandle*, const WebSocketHandshakeRequ estInfo&) override;
122 void didFinishOpeningHandshake(WebSocketHandle*, const WebSocketHandshakeRes ponseInfo&) override; 123 void didFinishOpeningHandshake(WebSocketHandle*, const WebSocketHandshakeRes ponseInfo&) override;
123 void didFail(WebSocketHandle*, const WebString& message) override; 124 void didFail(WebSocketHandle*, const WebString& message) override;
124 void didReceiveData(WebSocketHandle*, bool fin, WebSocketHandle::MessageType , const char* data, size_t /* size */) override; 125 void didReceiveData(WebSocketHandle*, bool fin, WebSocketHandle::MessageType , const char* data, size_t /* size */) override;
125 void didClose(WebSocketHandle*, bool wasClean, unsigned short code, const We bString& reason) override; 126 void didClose(WebSocketHandle*, bool wasClean, unsigned short code, const We bString& reason) override;
126 void didReceiveFlowControl(WebSocketHandle*, int64_t quota) override; 127 void didReceiveFlowControl(WebSocketHandle*, int64_t quota) override;
127 void didStartClosingHandshake(WebSocketHandle*) override; 128 void didStartClosingHandshake(WebSocketHandle*) override;
128 129
129 // Methods for BlobLoader. 130 // Methods for BlobLoader.
130 void didFinishLoadingBlob(DOMArrayBuffer*); 131 void didFinishLoadingBlob(DOMArrayBuffer*);
131 void didFailLoadingBlob(FileError::ErrorCode); 132 void didFailLoadingBlob(FileError::ErrorCode);
132 133
133 // m_handle is a handle of the connection. 134 // m_handle is a handle of the connection.
134 // m_handle == 0 means this channel is closed. 135 // m_handle == 0 means this channel is closed.
135 std::unique_ptr<WebSocketHandle> m_handle; 136 OwnPtr<WebSocketHandle> m_handle;
136 137
137 // m_client can be deleted while this channel is alive, but this class 138 // m_client can be deleted while this channel is alive, but this class
138 // expects that disconnect() is called before the deletion. 139 // expects that disconnect() is called before the deletion.
139 Member<WebSocketChannelClient> m_client; 140 Member<WebSocketChannelClient> m_client;
140 KURL m_url; 141 KURL m_url;
141 // m_identifier > 0 means calling scriptContextExecution() returns a Documen t. 142 // m_identifier > 0 means calling scriptContextExecution() returns a Documen t.
142 unsigned long m_identifier; 143 unsigned long m_identifier;
143 Member<BlobLoader> m_blobLoader; 144 Member<BlobLoader> m_blobLoader;
144 HeapDeque<Member<Message>> m_messages; 145 HeapDeque<Member<Message>> m_messages;
145 Vector<char> m_receivingMessageData; 146 Vector<char> m_receivingMessageData;
146 147
147 bool m_receivingMessageTypeIsText; 148 bool m_receivingMessageTypeIsText;
148 uint64_t m_sendingQuota; 149 uint64_t m_sendingQuota;
149 uint64_t m_receivedDataSizeForFlowControl; 150 uint64_t m_receivedDataSizeForFlowControl;
150 size_t m_sentSizeOfTopMessage; 151 size_t m_sentSizeOfTopMessage;
151 152
152 std::unique_ptr<SourceLocation> m_locationAtConstruction; 153 OwnPtr<SourceLocation> m_locationAtConstruction;
153 RefPtr<WebSocketHandshakeRequest> m_handshakeRequest; 154 RefPtr<WebSocketHandshakeRequest> m_handshakeRequest;
154 155
155 static const uint64_t receivedDataSizeForFlowControlHighWaterMark = 1 << 15; 156 static const uint64_t receivedDataSizeForFlowControlHighWaterMark = 1 << 15;
156 }; 157 };
157 158
158 } // namespace blink 159 } // namespace blink
159 160
160 #endif // DocumentWebSocketChannel_h 161 #endif // DocumentWebSocketChannel_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698