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

Side by Side Diff: third_party/WebKit/Source/modules/websockets/WorkerWebSocketChannel.cpp

Issue 2325983002: Replace ASSERT*() with DCHECK*() in modules/websockets (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove ALLOW_UNUSED_LOCAL() Created 4 years, 2 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 | « third_party/WebKit/Source/modules/websockets/WorkerWebSocketChannel.h ('k') | no next file » | 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) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 }; 96 };
97 97
98 WorkerWebSocketChannel::WorkerWebSocketChannel(WorkerGlobalScope& workerGlobalSc ope, WebSocketChannelClient* client, std::unique_ptr<SourceLocation> location) 98 WorkerWebSocketChannel::WorkerWebSocketChannel(WorkerGlobalScope& workerGlobalSc ope, WebSocketChannelClient* client, std::unique_ptr<SourceLocation> location)
99 : m_bridge(new Bridge(client, workerGlobalScope)) 99 : m_bridge(new Bridge(client, workerGlobalScope))
100 , m_locationAtConnection(std::move(location)) 100 , m_locationAtConnection(std::move(location))
101 { 101 {
102 } 102 }
103 103
104 WorkerWebSocketChannel::~WorkerWebSocketChannel() 104 WorkerWebSocketChannel::~WorkerWebSocketChannel()
105 { 105 {
106 ASSERT(!m_bridge); 106 DCHECK(!m_bridge);
107 } 107 }
108 108
109 bool WorkerWebSocketChannel::connect(const KURL& url, const String& protocol) 109 bool WorkerWebSocketChannel::connect(const KURL& url, const String& protocol)
110 { 110 {
111 ASSERT(m_bridge); 111 DCHECK(m_bridge);
112 return m_bridge->connect(m_locationAtConnection->clone(), url, protocol); 112 return m_bridge->connect(m_locationAtConnection->clone(), url, protocol);
113 } 113 }
114 114
115 void WorkerWebSocketChannel::send(const CString& message) 115 void WorkerWebSocketChannel::send(const CString& message)
116 { 116 {
117 ASSERT(m_bridge); 117 DCHECK(m_bridge);
118 m_bridge->send(message); 118 m_bridge->send(message);
119 } 119 }
120 120
121 void WorkerWebSocketChannel::send(const DOMArrayBuffer& binaryData, unsigned byt eOffset, unsigned byteLength) 121 void WorkerWebSocketChannel::send(const DOMArrayBuffer& binaryData, unsigned byt eOffset, unsigned byteLength)
122 { 122 {
123 ASSERT(m_bridge); 123 DCHECK(m_bridge);
124 m_bridge->send(binaryData, byteOffset, byteLength); 124 m_bridge->send(binaryData, byteOffset, byteLength);
125 } 125 }
126 126
127 void WorkerWebSocketChannel::send(PassRefPtr<BlobDataHandle> blobData) 127 void WorkerWebSocketChannel::send(PassRefPtr<BlobDataHandle> blobData)
128 { 128 {
129 ASSERT(m_bridge); 129 DCHECK(m_bridge);
130 m_bridge->send(std::move(blobData)); 130 m_bridge->send(std::move(blobData));
131 } 131 }
132 132
133 void WorkerWebSocketChannel::close(int code, const String& reason) 133 void WorkerWebSocketChannel::close(int code, const String& reason)
134 { 134 {
135 ASSERT(m_bridge); 135 DCHECK(m_bridge);
136 m_bridge->close(code, reason); 136 m_bridge->close(code, reason);
137 } 137 }
138 138
139 void WorkerWebSocketChannel::fail(const String& reason, MessageLevel level, std: :unique_ptr<SourceLocation> location) 139 void WorkerWebSocketChannel::fail(const String& reason, MessageLevel level, std: :unique_ptr<SourceLocation> location)
140 { 140 {
141 if (!m_bridge) 141 if (!m_bridge)
142 return; 142 return;
143 143
144 std::unique_ptr<SourceLocation> capturedLocation = SourceLocation::capture() ; 144 std::unique_ptr<SourceLocation> capturedLocation = SourceLocation::capture() ;
145 if (!capturedLocation->isUnknown()) { 145 if (!capturedLocation->isUnknown()) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 DCHECK(isMainThread()); 177 DCHECK(isMainThread());
178 } 178 }
179 179
180 Peer::~Peer() 180 Peer::~Peer()
181 { 181 {
182 DCHECK(isMainThread()); 182 DCHECK(isMainThread());
183 } 183 }
184 184
185 bool Peer::initialize(std::unique_ptr<SourceLocation> location, ExecutionContext * context) 185 bool Peer::initialize(std::unique_ptr<SourceLocation> location, ExecutionContext * context)
186 { 186 {
187 ASSERT(isMainThread()); 187 DCHECK(isMainThread());
188 if (wasContextDestroyedBeforeObserverCreation()) 188 if (wasContextDestroyedBeforeObserverCreation())
189 return false; 189 return false;
190 Document* document = toDocument(context); 190 Document* document = toDocument(context);
191 m_mainWebSocketChannel = DocumentWebSocketChannel::create(document, this, st d::move(location)); 191 m_mainWebSocketChannel = DocumentWebSocketChannel::create(document, this, st d::move(location));
192 return true; 192 return true;
193 } 193 }
194 194
195 bool Peer::connect(const KURL& url, const String& protocol) 195 bool Peer::connect(const KURL& url, const String& protocol)
196 { 196 {
197 ASSERT(isMainThread()); 197 DCHECK(isMainThread());
198 if (!m_mainWebSocketChannel) 198 if (!m_mainWebSocketChannel)
199 return false; 199 return false;
200 return m_mainWebSocketChannel->connect(url, protocol); 200 return m_mainWebSocketChannel->connect(url, protocol);
201 } 201 }
202 202
203 void Peer::sendTextAsCharVector(std::unique_ptr<Vector<char>> data) 203 void Peer::sendTextAsCharVector(std::unique_ptr<Vector<char>> data)
204 { 204 {
205 ASSERT(isMainThread()); 205 DCHECK(isMainThread());
206 if (m_mainWebSocketChannel) 206 if (m_mainWebSocketChannel)
207 m_mainWebSocketChannel->sendTextAsCharVector(std::move(data)); 207 m_mainWebSocketChannel->sendTextAsCharVector(std::move(data));
208 } 208 }
209 209
210 void Peer::sendBinaryAsCharVector(std::unique_ptr<Vector<char>> data) 210 void Peer::sendBinaryAsCharVector(std::unique_ptr<Vector<char>> data)
211 { 211 {
212 ASSERT(isMainThread()); 212 DCHECK(isMainThread());
213 if (m_mainWebSocketChannel) 213 if (m_mainWebSocketChannel)
214 m_mainWebSocketChannel->sendBinaryAsCharVector(std::move(data)); 214 m_mainWebSocketChannel->sendBinaryAsCharVector(std::move(data));
215 } 215 }
216 216
217 void Peer::sendBlob(PassRefPtr<BlobDataHandle> blobData) 217 void Peer::sendBlob(PassRefPtr<BlobDataHandle> blobData)
218 { 218 {
219 ASSERT(isMainThread()); 219 DCHECK(isMainThread());
220 if (m_mainWebSocketChannel) 220 if (m_mainWebSocketChannel)
221 m_mainWebSocketChannel->send(std::move(blobData)); 221 m_mainWebSocketChannel->send(std::move(blobData));
222 } 222 }
223 223
224 void Peer::close(int code, const String& reason) 224 void Peer::close(int code, const String& reason)
225 { 225 {
226 ASSERT(isMainThread()); 226 DCHECK(isMainThread());
227 if (!m_mainWebSocketChannel) 227 if (!m_mainWebSocketChannel)
228 return; 228 return;
229 m_mainWebSocketChannel->close(code, reason); 229 m_mainWebSocketChannel->close(code, reason);
230 } 230 }
231 231
232 void Peer::fail(const String& reason, MessageLevel level, std::unique_ptr<Source Location> location) 232 void Peer::fail(const String& reason, MessageLevel level, std::unique_ptr<Source Location> location)
233 { 233 {
234 ASSERT(isMainThread()); 234 DCHECK(isMainThread());
235 if (!m_mainWebSocketChannel) 235 if (!m_mainWebSocketChannel)
236 return; 236 return;
237 m_mainWebSocketChannel->fail(reason, level, std::move(location)); 237 m_mainWebSocketChannel->fail(reason, level, std::move(location));
238 } 238 }
239 239
240 void Peer::disconnect() 240 void Peer::disconnect()
241 { 241 {
242 ASSERT(isMainThread()); 242 DCHECK(isMainThread());
243 if (!m_mainWebSocketChannel) 243 if (!m_mainWebSocketChannel)
244 return; 244 return;
245 m_mainWebSocketChannel->disconnect(); 245 m_mainWebSocketChannel->disconnect();
246 m_mainWebSocketChannel = nullptr; 246 m_mainWebSocketChannel = nullptr;
247 } 247 }
248 248
249 static void workerGlobalScopeDidConnect(Bridge* bridge, const String& subprotoco l, const String& extensions, ExecutionContext* context) 249 static void workerGlobalScopeDidConnect(Bridge* bridge, const String& subprotoco l, const String& extensions, ExecutionContext* context)
250 { 250 {
251 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); 251 DCHECK(context->isWorkerGlobalScope());
252 if (bridge && bridge->client()) 252 if (bridge && bridge->client())
253 bridge->client()->didConnect(subprotocol, extensions); 253 bridge->client()->didConnect(subprotocol, extensions);
254 } 254 }
255 255
256 void Peer::didConnect(const String& subprotocol, const String& extensions) 256 void Peer::didConnect(const String& subprotocol, const String& extensions)
257 { 257 {
258 ASSERT(isMainThread()); 258 DCHECK(isMainThread());
259 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidConnect, m_bridge, subprotocol, extensions)); 259 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidConnect, m_bridge, subprotocol, extensions));
260 } 260 }
261 261
262 static void workerGlobalScopeDidReceiveTextMessage(Bridge* bridge, const String& payload, ExecutionContext* context) 262 static void workerGlobalScopeDidReceiveTextMessage(Bridge* bridge, const String& payload, ExecutionContext* context)
263 { 263 {
264 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); 264 DCHECK(context->isWorkerGlobalScope());
265 if (bridge && bridge->client()) 265 if (bridge && bridge->client())
266 bridge->client()->didReceiveTextMessage(payload); 266 bridge->client()->didReceiveTextMessage(payload);
267 } 267 }
268 268
269 void Peer::didReceiveTextMessage(const String& payload) 269 void Peer::didReceiveTextMessage(const String& payload)
270 { 270 {
271 ASSERT(isMainThread()); 271 DCHECK(isMainThread());
272 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidReceiveTextMessage, m_bridge, payload)); 272 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidReceiveTextMessage, m_bridge, payload));
273 } 273 }
274 274
275 static void workerGlobalScopeDidReceiveBinaryMessage(Bridge* bridge, std::unique _ptr<Vector<char>> payload, ExecutionContext* context) 275 static void workerGlobalScopeDidReceiveBinaryMessage(Bridge* bridge, std::unique _ptr<Vector<char>> payload, ExecutionContext* context)
276 { 276 {
277 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); 277 DCHECK(context->isWorkerGlobalScope());
278 if (bridge && bridge->client()) 278 if (bridge && bridge->client())
279 bridge->client()->didReceiveBinaryMessage(std::move(payload)); 279 bridge->client()->didReceiveBinaryMessage(std::move(payload));
280 } 280 }
281 281
282 void Peer::didReceiveBinaryMessage(std::unique_ptr<Vector<char>> payload) 282 void Peer::didReceiveBinaryMessage(std::unique_ptr<Vector<char>> payload)
283 { 283 {
284 ASSERT(isMainThread()); 284 DCHECK(isMainThread());
285 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidReceiveBinaryMessage, m_bridge, passed(std::move(payl oad)))); 285 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidReceiveBinaryMessage, m_bridge, passed(std::move(payl oad))));
286 } 286 }
287 287
288 static void workerGlobalScopeDidConsumeBufferedAmount(Bridge* bridge, uint64_t c onsumed, ExecutionContext* context) 288 static void workerGlobalScopeDidConsumeBufferedAmount(Bridge* bridge, uint64_t c onsumed, ExecutionContext* context)
289 { 289 {
290 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); 290 DCHECK(context->isWorkerGlobalScope());
291 if (bridge && bridge->client()) 291 if (bridge && bridge->client())
292 bridge->client()->didConsumeBufferedAmount(consumed); 292 bridge->client()->didConsumeBufferedAmount(consumed);
293 } 293 }
294 294
295 void Peer::didConsumeBufferedAmount(uint64_t consumed) 295 void Peer::didConsumeBufferedAmount(uint64_t consumed)
296 { 296 {
297 ASSERT(isMainThread()); 297 DCHECK(isMainThread());
298 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidConsumeBufferedAmount, m_bridge, consumed)); 298 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidConsumeBufferedAmount, m_bridge, consumed));
299 } 299 }
300 300
301 static void workerGlobalScopeDidStartClosingHandshake(Bridge* bridge, ExecutionC ontext* context) 301 static void workerGlobalScopeDidStartClosingHandshake(Bridge* bridge, ExecutionC ontext* context)
302 { 302 {
303 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); 303 DCHECK(context->isWorkerGlobalScope());
304 if (bridge && bridge->client()) 304 if (bridge && bridge->client())
305 bridge->client()->didStartClosingHandshake(); 305 bridge->client()->didStartClosingHandshake();
306 } 306 }
307 307
308 void Peer::didStartClosingHandshake() 308 void Peer::didStartClosingHandshake()
309 { 309 {
310 ASSERT(isMainThread()); 310 DCHECK(isMainThread());
311 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidStartClosingHandshake, m_bridge)); 311 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidStartClosingHandshake, m_bridge));
312 } 312 }
313 313
314 static void workerGlobalScopeDidClose(Bridge* bridge, WebSocketChannelClient::Cl osingHandshakeCompletionStatus closingHandshakeCompletion, unsigned short code, const String& reason, ExecutionContext* context) 314 static void workerGlobalScopeDidClose(Bridge* bridge, WebSocketChannelClient::Cl osingHandshakeCompletionStatus closingHandshakeCompletion, unsigned short code, const String& reason, ExecutionContext* context)
315 { 315 {
316 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); 316 DCHECK(context->isWorkerGlobalScope());
317 if (bridge && bridge->client()) 317 if (bridge && bridge->client())
318 bridge->client()->didClose(closingHandshakeCompletion, code, reason); 318 bridge->client()->didClose(closingHandshakeCompletion, code, reason);
319 } 319 }
320 320
321 void Peer::didClose(ClosingHandshakeCompletionStatus closingHandshakeCompletion, unsigned short code, const String& reason) 321 void Peer::didClose(ClosingHandshakeCompletionStatus closingHandshakeCompletion, unsigned short code, const String& reason)
322 { 322 {
323 ASSERT(isMainThread()); 323 DCHECK(isMainThread());
324 if (m_mainWebSocketChannel) { 324 if (m_mainWebSocketChannel) {
325 m_mainWebSocketChannel->disconnect(); 325 m_mainWebSocketChannel->disconnect();
326 m_mainWebSocketChannel = nullptr; 326 m_mainWebSocketChannel = nullptr;
327 } 327 }
328 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidClose, m_bridge, closingHandshakeCompletion, code, re ason)); 328 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidClose, m_bridge, closingHandshakeCompletion, code, re ason));
329 } 329 }
330 330
331 static void workerGlobalScopeDidError(Bridge* bridge, ExecutionContext* context) 331 static void workerGlobalScopeDidError(Bridge* bridge, ExecutionContext* context)
332 { 332 {
333 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); 333 DCHECK(context->isWorkerGlobalScope());
334 if (bridge && bridge->client()) 334 if (bridge && bridge->client())
335 bridge->client()->didError(); 335 bridge->client()->didError();
336 } 336 }
337 337
338 void Peer::didError() 338 void Peer::didError()
339 { 339 {
340 ASSERT(isMainThread()); 340 DCHECK(isMainThread());
341 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidError, m_bridge)); 341 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidError, m_bridge));
342 } 342 }
343 343
344 void Peer::contextDestroyed() 344 void Peer::contextDestroyed()
345 { 345 {
346 DCHECK(isMainThread()); 346 DCHECK(isMainThread());
347 if (m_mainWebSocketChannel) { 347 if (m_mainWebSocketChannel) {
348 m_mainWebSocketChannel->disconnect(); 348 m_mainWebSocketChannel->disconnect();
349 m_mainWebSocketChannel = nullptr; 349 m_mainWebSocketChannel = nullptr;
350 } 350 }
351 m_bridge = nullptr; 351 m_bridge = nullptr;
352 } 352 }
353 353
354 DEFINE_TRACE(Peer) 354 DEFINE_TRACE(Peer)
355 { 355 {
356 visitor->trace(m_mainWebSocketChannel); 356 visitor->trace(m_mainWebSocketChannel);
357 WebSocketChannelClient::trace(visitor); 357 WebSocketChannelClient::trace(visitor);
358 WorkerThreadLifecycleObserver::trace(visitor); 358 WorkerThreadLifecycleObserver::trace(visitor);
359 } 359 }
360 360
361 Bridge::Bridge(WebSocketChannelClient* client, WorkerGlobalScope& workerGlobalSc ope) 361 Bridge::Bridge(WebSocketChannelClient* client, WorkerGlobalScope& workerGlobalSc ope)
362 : m_client(client) 362 : m_client(client)
363 , m_workerGlobalScope(workerGlobalScope) 363 , m_workerGlobalScope(workerGlobalScope)
364 , m_loaderProxy(m_workerGlobalScope->thread()->workerLoaderProxy()) 364 , m_loaderProxy(m_workerGlobalScope->thread()->workerLoaderProxy())
365 { 365 {
366 } 366 }
367 367
368 Bridge::~Bridge() 368 Bridge::~Bridge()
369 { 369 {
370 ASSERT(!m_peer); 370 DCHECK(!m_peer);
371 } 371 }
372 372
373 void Bridge::connectOnMainThread(std::unique_ptr<SourceLocation> location, Worke rThreadLifecycleContext* workerThreadLifecycleContext, const KURL& url, const St ring& protocol, WebSocketChannelSyncHelper* syncHelper, ExecutionContext* contex t) 373 void Bridge::connectOnMainThread(std::unique_ptr<SourceLocation> location, Worke rThreadLifecycleContext* workerThreadLifecycleContext, const KURL& url, const St ring& protocol, WebSocketChannelSyncHelper* syncHelper, ExecutionContext* contex t)
374 { 374 {
375 DCHECK(isMainThread()); 375 DCHECK(isMainThread());
376 DCHECK(!m_peer); 376 DCHECK(!m_peer);
377 Peer* peer = new Peer(this, m_loaderProxy, workerThreadLifecycleContext); 377 Peer* peer = new Peer(this, m_loaderProxy, workerThreadLifecycleContext);
378 if (peer->initialize(std::move(location), context)) { 378 if (peer->initialize(std::move(location), context)) {
379 m_peer = peer; 379 m_peer = peer;
380 syncHelper->setConnectRequestResult(m_peer->connect(url, protocol)); 380 syncHelper->setConnectRequestResult(m_peer->connect(url, protocol));
381 } 381 }
382 syncHelper->signalWorkerThread(); 382 syncHelper->signalWorkerThread();
383 } 383 }
384 384
385 bool Bridge::connect(std::unique_ptr<SourceLocation> location, const KURL& url, const String& protocol) 385 bool Bridge::connect(std::unique_ptr<SourceLocation> location, const KURL& url, const String& protocol)
386 { 386 {
387 // Wait for completion of the task on the main thread because the mixed 387 // Wait for completion of the task on the main thread because the mixed
388 // content check must synchronously be conducted. 388 // content check must synchronously be conducted.
389 WebSocketChannelSyncHelper syncHelper; 389 WebSocketChannelSyncHelper syncHelper;
390 m_loaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask(&Brid ge::connectOnMainThread, wrapCrossThreadPersistent(this), passed(location->clone ()), wrapCrossThreadPersistent(m_workerGlobalScope->thread()->getWorkerThreadLif ecycleContext()), url, protocol, crossThreadUnretained(&syncHelper))); 390 m_loaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask(&Brid ge::connectOnMainThread, wrapCrossThreadPersistent(this), passed(location->clone ()), wrapCrossThreadPersistent(m_workerGlobalScope->thread()->getWorkerThreadLif ecycleContext()), url, protocol, crossThreadUnretained(&syncHelper)));
391 syncHelper.wait(); 391 syncHelper.wait();
392 return syncHelper.connectRequestResult(); 392 return syncHelper.connectRequestResult();
393 } 393 }
394 394
395 void Bridge::send(const CString& message) 395 void Bridge::send(const CString& message)
396 { 396 {
397 ASSERT(m_peer); 397 DCHECK(m_peer);
398 std::unique_ptr<Vector<char>> data = wrapUnique(new Vector<char>(message.len gth())); 398 std::unique_ptr<Vector<char>> data = wrapUnique(new Vector<char>(message.len gth()));
399 if (message.length()) 399 if (message.length())
400 memcpy(data->data(), static_cast<const char*>(message.data()), message.l ength()); 400 memcpy(data->data(), static_cast<const char*>(message.data()), message.l ength());
401 401
402 m_loaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask(&Peer ::sendTextAsCharVector, m_peer, passed(std::move(data)))); 402 m_loaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask(&Peer ::sendTextAsCharVector, m_peer, passed(std::move(data))));
403 } 403 }
404 404
405 void Bridge::send(const DOMArrayBuffer& binaryData, unsigned byteOffset, unsigne d byteLength) 405 void Bridge::send(const DOMArrayBuffer& binaryData, unsigned byteOffset, unsigne d byteLength)
406 { 406 {
407 ASSERT(m_peer); 407 DCHECK(m_peer);
408 // ArrayBuffer isn't thread-safe, hence the content of ArrayBuffer is copied into Vector<char>. 408 // ArrayBuffer isn't thread-safe, hence the content of ArrayBuffer is copied into Vector<char>.
409 std::unique_ptr<Vector<char>> data = wrapUnique(new Vector<char>(byteLength) ); 409 std::unique_ptr<Vector<char>> data = wrapUnique(new Vector<char>(byteLength) );
410 if (binaryData.byteLength()) 410 if (binaryData.byteLength())
411 memcpy(data->data(), static_cast<const char*>(binaryData.data()) + byteO ffset, byteLength); 411 memcpy(data->data(), static_cast<const char*>(binaryData.data()) + byteO ffset, byteLength);
412 412
413 m_loaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask(&Peer ::sendBinaryAsCharVector, m_peer, passed(std::move(data)))); 413 m_loaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask(&Peer ::sendBinaryAsCharVector, m_peer, passed(std::move(data))));
414 } 414 }
415 415
416 void Bridge::send(PassRefPtr<BlobDataHandle> data) 416 void Bridge::send(PassRefPtr<BlobDataHandle> data)
417 { 417 {
418 ASSERT(m_peer); 418 DCHECK(m_peer);
419 m_loaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask(&Peer ::sendBlob, m_peer, std::move(data))); 419 m_loaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask(&Peer ::sendBlob, m_peer, std::move(data)));
420 } 420 }
421 421
422 void Bridge::close(int code, const String& reason) 422 void Bridge::close(int code, const String& reason)
423 { 423 {
424 ASSERT(m_peer); 424 DCHECK(m_peer);
425 m_loaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask(&Peer ::close, m_peer, code, reason)); 425 m_loaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask(&Peer ::close, m_peer, code, reason));
426 } 426 }
427 427
428 void Bridge::fail(const String& reason, MessageLevel level, std::unique_ptr<Sour ceLocation> location) 428 void Bridge::fail(const String& reason, MessageLevel level, std::unique_ptr<Sour ceLocation> location)
429 { 429 {
430 ASSERT(m_peer); 430 DCHECK(m_peer);
431 m_loaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask(&Peer ::fail, m_peer, reason, level, passed(location->clone()))); 431 m_loaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask(&Peer ::fail, m_peer, reason, level, passed(location->clone())));
432 } 432 }
433 433
434 void Bridge::disconnect() 434 void Bridge::disconnect()
435 { 435 {
436 if (!m_peer) 436 if (!m_peer)
437 return; 437 return;
438 438
439 m_loaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask(&Peer ::disconnect, m_peer)); 439 m_loaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask(&Peer ::disconnect, m_peer));
440 440
441 m_client = nullptr; 441 m_client = nullptr;
442 m_peer = nullptr; 442 m_peer = nullptr;
443 m_workerGlobalScope.clear(); 443 m_workerGlobalScope.clear();
444 } 444 }
445 445
446 DEFINE_TRACE(Bridge) 446 DEFINE_TRACE(Bridge)
447 { 447 {
448 visitor->trace(m_client); 448 visitor->trace(m_client);
449 visitor->trace(m_workerGlobalScope); 449 visitor->trace(m_workerGlobalScope);
450 } 450 }
451 451
452 } // namespace blink 452 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/websockets/WorkerWebSocketChannel.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698