Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "modules/serviceworkers/StashedMessagePort.h" | |
| 7 | |
| 8 #include "bindings/core/v8/SerializedScriptValue.h" | |
| 9 #include "core/dom/CrossThreadTask.h" | |
| 10 #include "core/events/MessageEvent.h" | |
| 11 #include "modules/serviceworkers/ServiceWorkerGlobalScope.h" | |
| 12 #include "modules/serviceworkers/StashedPortCollection.h" | |
| 13 #include "public/platform/WebTraceLocation.h" | |
| 14 | |
| 15 namespace blink { | |
| 16 | |
| 17 PassRefPtrWillBeRawPtr<StashedMessagePort> StashedMessagePort::create(ExecutionC ontext& executionContext, PassOwnPtr<WebMessagePortChannel> remote, const String & name) | |
| 18 { | |
| 19 RefPtrWillBeRawPtr<StashedMessagePort> port = adoptRefWillBeNoop(new Stashed MessagePort(executionContext, remote, name)); | |
| 20 port->suspendIfNeeded(); | |
| 21 return port.release(); | |
| 22 } | |
| 23 | |
| 24 StashedMessagePort::StashedMessagePort(ExecutionContext& executionContext, PassO wnPtr<WebMessagePortChannel> remote, const String& name) | |
|
scheib
2015/05/06 21:44:30
definitions in the corresponding .cc file should b
Marijn Kruisselbrink
2015/05/12 06:56:40
yes, while that's true it's pretty common in at le
| |
| 25 : MessagePort(executionContext), m_weakFactory(this), m_name(name) | |
| 26 { | |
| 27 entangle(remote); | |
| 28 start(); | |
| 29 } | |
| 30 | |
| 31 StashedMessagePort::~StashedMessagePort() | |
| 32 { | |
| 33 } | |
| 34 | |
| 35 PassOwnPtrWillBeRawPtr<StashedMessagePortArray> StashedMessagePort::toStashedMes sagePortArray(ExecutionContext* context, const WebMessagePortChannelArray& webCh annels, const WebVector<WebString>& channelKeys) | |
| 36 { | |
| 37 OwnPtrWillBeRawPtr<StashedMessagePortArray> ports = adoptPtrWillBeNoop(new S tashedMessagePortArray(webChannels.size())); | |
| 38 for (size_t i = 0; i < webChannels.size(); ++i) { | |
| 39 OwnPtr<WebMessagePortChannel> channel(adoptPtr(webChannels[i])); | |
| 40 (*ports)[i] = StashedMessagePort::create(*context, channel.release(), ch annelKeys[i]); | |
| 41 } | |
| 42 return ports.release(); | |
| 43 } | |
| 44 | |
| 45 String StashedMessagePort::name() const | |
| 46 { | |
| 47 return m_name; | |
| 48 } | |
| 49 | |
| 50 DEFINE_TRACE(StashedMessagePort) | |
|
scheib
2015/05/06 21:44:30
Maybe use DEFINE_TRACE_INLINE for this in .h?
Marijn Kruisselbrink
2015/05/12 06:56:40
Done.
| |
| 51 { | |
| 52 MessagePort::trace(visitor); | |
| 53 } | |
| 54 | |
| 55 void StashedMessagePort::messageAvailable() | |
| 56 { | |
| 57 ASSERT(executionContext()); | |
| 58 executionContext()->postTask(FROM_HERE, createCrossThreadTask(&StashedMessag ePort::dispatchMessages, m_weakFactory.createWeakPtr())); | |
| 59 } | |
| 60 | |
| 61 void StashedMessagePort::dispatchMessages() | |
|
scheib
2015/05/06 21:44:30
There's no need to check the closed, started state
Marijn Kruisselbrink
2015/05/12 06:56:40
!isEntangled() implies !closed(), and for now I'm
| |
| 62 { | |
| 63 if (!isEntangled()) | |
| 64 return; | |
| 65 ASSERT(executionContext()->isServiceWorkerGlobalScope()); | |
| 66 RefPtr<StashedPortCollection> stashedPorts = toServiceWorkerGlobalScope(exec utionContext())->ports(); | |
| 67 | |
| 68 RefPtr<SerializedScriptValue> message; | |
| 69 OwnPtr<MessagePortChannelArray> channels; | |
| 70 while (tryGetMessage(message, channels)) { | |
| 71 OwnPtrWillBeRawPtr<MessagePortArray> ports = MessagePort::entanglePorts( *executionContext(), channels.release()); | |
| 72 RefPtrWillBeRawPtr<Event> evt = MessageEvent::create(ports.release(), me ssage.release(), String(), String(), this); | |
| 73 | |
| 74 stashedPorts->dispatchEvent(evt.release(), ASSERT_NO_EXCEPTION); | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 } // namespace blink | |
| 79 | |
| OLD | NEW |