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

Side by Side Diff: Source/modules/websockets/NewWebSocketChannelImpl.h

Issue 23464050: Implement suspend / resume in NewWebSocketChannelImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 3 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 | Source/modules/websockets/NewWebSocketChannelImpl.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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 virtual void fail(const String& reason, MessageLevel, const String&, unsigne d lineNumber) OVERRIDE; 80 virtual void fail(const String& reason, MessageLevel, const String&, unsigne d lineNumber) OVERRIDE;
81 using WebSocketChannel::fail; 81 using WebSocketChannel::fail;
82 virtual void disconnect() OVERRIDE; 82 virtual void disconnect() OVERRIDE;
83 83
84 using RefCounted<NewWebSocketChannelImpl>::ref; 84 using RefCounted<NewWebSocketChannelImpl>::ref;
85 using RefCounted<NewWebSocketChannelImpl>::deref; 85 using RefCounted<NewWebSocketChannelImpl>::deref;
86 86
87 virtual void suspend() OVERRIDE; 87 virtual void suspend() OVERRIDE;
88 virtual void resume() OVERRIDE; 88 virtual void resume() OVERRIDE;
89 89
90 void handleDidConnect();
91 void handleTextMessage(Vector<char>*);
92 void handleBinaryMessage(Vector<char>*);
93 void handleDidReceiveMessageError();
94 void handleDidClose(unsigned short code, const String& reason);
95
90 private: 96 private:
91 enum MessageType { 97 enum MessageType {
92 MessageTypeText, 98 MessageTypeText,
93 MessageTypeBlob, 99 MessageTypeBlob,
94 MessageTypeArrayBuffer, 100 MessageTypeArrayBuffer,
95 }; 101 };
102
96 struct Message { 103 struct Message {
97 explicit Message(const String&); 104 explicit Message(const String&);
98 explicit Message(const Blob&); 105 explicit Message(const Blob&);
99 explicit Message(PassRefPtr<ArrayBuffer>); 106 explicit Message(PassRefPtr<ArrayBuffer>);
100 MessageType type; 107 MessageType type;
101 CString text; 108 CString text;
102 RefPtr<Blob> blob; 109 RefPtr<Blob> blob;
103 RefPtr<ArrayBuffer> arrayBuffer; 110 RefPtr<ArrayBuffer> arrayBuffer;
104 }; 111 };
105 112
106 struct ReceivedMessage { 113 struct ReceivedMessage {
107 bool isMessageText; 114 bool isMessageText;
108 Vector<char> data; 115 Vector<char> data;
109 }; 116 };
117
110 class BlobLoader; 118 class BlobLoader;
119 class Resumer;
111 120
112 NewWebSocketChannelImpl(ScriptExecutionContext*, WebSocketChannelClient*, co nst String&, unsigned); 121 NewWebSocketChannelImpl(ScriptExecutionContext*, WebSocketChannelClient*, co nst String&, unsigned);
113 void sendInternal(); 122 void sendInternal();
114 void flowControlIfNecessary(); 123 void flowControlIfNecessary();
115 void failAsError(const String& reason) { fail(reason, ErrorMessageLevel, "", 0); } 124 void failAsError(const String& reason) { fail(reason, ErrorMessageLevel, "", 0); }
116 void abortAsyncOperations(); 125 void abortAsyncOperations();
117 126
118 // WebSocketHandleClient functions. 127 // WebSocketHandleClient functions.
119 virtual void didConnect(WebKit::WebSocketHandle*, bool succeed, const WebKit ::WebString& selectedProtocol, const WebKit::WebString& extensions) OVERRIDE; 128 virtual void didConnect(WebKit::WebSocketHandle*, bool succeed, const WebKit ::WebString& selectedProtocol, const WebKit::WebString& extensions) OVERRIDE;
120 virtual void didReceiveData(WebKit::WebSocketHandle*, WebKit::WebSocketHandl e::MessageType, const char* data, size_t /* size */, bool fin) OVERRIDE; 129 virtual void didReceiveData(WebKit::WebSocketHandle*, WebKit::WebSocketHandl e::MessageType, const char* data, size_t /* size */, bool fin) OVERRIDE;
121 virtual void didClose(WebKit::WebSocketHandle*, unsigned short code, const W ebKit::WebString& reason) OVERRIDE; 130 virtual void didClose(WebKit::WebSocketHandle*, unsigned short code, const W ebKit::WebString& reason) OVERRIDE;
122 virtual void didReceiveFlowControl(WebKit::WebSocketHandle*, int64_t quota) OVERRIDE { m_sendingQuota += quota; } 131 virtual void didReceiveFlowControl(WebKit::WebSocketHandle*, int64_t quota) OVERRIDE { m_sendingQuota += quota; }
123 132
124 void handleTextMessage(Vector<char>*);
125 void handleBinaryMessage(Vector<char>*);
126 void handleDidClose(unsigned short code, const String& reason);
127
128 // Methods for BlobLoader. 133 // Methods for BlobLoader.
129 void didFinishLoadingBlob(PassRefPtr<ArrayBuffer>); 134 void didFinishLoadingBlob(PassRefPtr<ArrayBuffer>);
130 void didFailLoadingBlob(FileError::ErrorCode); 135 void didFailLoadingBlob(FileError::ErrorCode);
131 136
132 // WebSocketChannel functions. 137 // WebSocketChannel functions.
133 virtual void refWebSocketChannel() OVERRIDE { ref(); } 138 virtual void refWebSocketChannel() OVERRIDE { ref(); }
134 virtual void derefWebSocketChannel() OVERRIDE { deref(); } 139 virtual void derefWebSocketChannel() OVERRIDE { deref(); }
135 140
136 // LifecycleObserver functions. 141 // LifecycleObserver functions.
137 // This object must be destroyed before the context. 142 // This object must be destroyed before the context.
138 virtual void contextDestroyed() OVERRIDE { ASSERT_NOT_REACHED(); } 143 virtual void contextDestroyed() OVERRIDE { ASSERT_NOT_REACHED(); }
139 144
140 // m_handle is a handle of the connection. 145 // m_handle is a handle of the connection.
141 // m_handle == 0 means this channel is closed. 146 // m_handle == 0 means this channel is closed.
142 OwnPtr<WebKit::WebSocketHandle> m_handle; 147 OwnPtr<WebKit::WebSocketHandle> m_handle;
143 148
144 // m_client can be deleted while this channel is alive, but this class 149 // m_client can be deleted while this channel is alive, but this class
145 // expects that disconnect() is called before the deletion. 150 // expects that disconnect() is called before the deletion.
146 WebSocketChannelClient* m_client; 151 WebSocketChannelClient* m_client;
147 KURL m_url; 152 KURL m_url;
148 OwnPtr<BlobLoader> m_blobLoader; 153 OwnPtr<BlobLoader> m_blobLoader;
154 OwnPtr<Resumer> m_resumer;
155 bool m_isSuspended;
149 Deque<Message> m_messages; 156 Deque<Message> m_messages;
150 Vector<char> m_receivingMessageData; 157 Vector<char> m_receivingMessageData;
151 158
152 bool m_receivingMessageTypeIsText; 159 bool m_receivingMessageTypeIsText;
153 int64_t m_sendingQuota; 160 int64_t m_sendingQuota;
154 int64_t m_receivedDataSizeForFlowControl; 161 int64_t m_receivedDataSizeForFlowControl;
155 unsigned long m_bufferedAmount; 162 unsigned long m_bufferedAmount;
156 size_t m_sentSizeOfTopMessage; 163 size_t m_sentSizeOfTopMessage;
157 String m_subprotocol; 164 String m_subprotocol;
158 String m_extensions; 165 String m_extensions;
159 166
160 static const int64_t receivedDataSizeForFlowControlHighWaterMark = 1 << 15; 167 static const int64_t receivedDataSizeForFlowControlHighWaterMark = 1 << 15;
161 }; 168 };
162 169
163 } // namespace WebCore 170 } // namespace WebCore
164 171
165 #endif // NewWebSocketChannelImpl_h 172 #endif // NewWebSocketChannelImpl_h
OLDNEW
« no previous file with comments | « no previous file | Source/modules/websockets/NewWebSocketChannelImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698