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

Side by Side Diff: third_party/WebKit/Source/core/dom/MessagePort.cpp

Issue 2833673002: Revert of Messaging: Avoid calling non-thread-safe functions in MessagePort::messageAvailable() (Closed)
Patch Set: Created 3 years, 8 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) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 15 matching lines...) Expand all
26 26
27 #include "core/dom/MessagePort.h" 27 #include "core/dom/MessagePort.h"
28 28
29 #include <memory> 29 #include <memory>
30 #include "bindings/core/v8/ExceptionState.h" 30 #include "bindings/core/v8/ExceptionState.h"
31 #include "bindings/core/v8/ScriptState.h" 31 #include "bindings/core/v8/ScriptState.h"
32 #include "bindings/core/v8/SerializedScriptValue.h" 32 #include "bindings/core/v8/SerializedScriptValue.h"
33 #include "bindings/core/v8/SerializedScriptValueFactory.h" 33 #include "bindings/core/v8/SerializedScriptValueFactory.h"
34 #include "core/dom/ExceptionCode.h" 34 #include "core/dom/ExceptionCode.h"
35 #include "core/dom/ExecutionContext.h" 35 #include "core/dom/ExecutionContext.h"
36 #include "core/dom/ExecutionContextTask.h"
36 #include "core/dom/TaskRunnerHelper.h" 37 #include "core/dom/TaskRunnerHelper.h"
37 #include "core/events/MessageEvent.h" 38 #include "core/events/MessageEvent.h"
38 #include "core/frame/LocalDOMWindow.h" 39 #include "core/frame/LocalDOMWindow.h"
39 #include "core/workers/WorkerGlobalScope.h" 40 #include "core/workers/WorkerGlobalScope.h"
40 #include "platform/CrossThreadFunctional.h"
41 #include "platform/wtf/Atomics.h" 41 #include "platform/wtf/Atomics.h"
42 #include "platform/wtf/PtrUtil.h" 42 #include "platform/wtf/PtrUtil.h"
43 #include "platform/wtf/text/AtomicString.h" 43 #include "platform/wtf/text/AtomicString.h"
44 #include "public/platform/WebString.h" 44 #include "public/platform/WebString.h"
45 45
46 namespace blink { 46 namespace blink {
47 47
48 MessagePort* MessagePort::Create(ExecutionContext& execution_context) { 48 MessagePort* MessagePort::Create(ExecutionContext& execution_context) {
49 return new MessagePort(execution_context); 49 return new MessagePort(execution_context);
50 } 50 }
51 51
52 MessagePort::MessagePort(ExecutionContext& execution_context) 52 MessagePort::MessagePort(ExecutionContext& execution_context)
53 : ContextLifecycleObserver(&execution_context), 53 : ContextLifecycleObserver(&execution_context),
54 task_runner_(TaskRunnerHelper::Get(TaskType::kPostedMessage, 54 pending_dispatch_task_(0),
55 &execution_context)) {} 55 started_(false),
56 closed_(false) {}
56 57
57 MessagePort::~MessagePort() { 58 MessagePort::~MessagePort() {
58 DCHECK(!started_ || !IsEntangled()); 59 DCHECK(!started_ || !IsEntangled());
59 } 60 }
60 61
61 void MessagePort::postMessage(ScriptState* script_state, 62 void MessagePort::postMessage(ScriptState* script_state,
62 PassRefPtr<SerializedScriptValue> message, 63 PassRefPtr<SerializedScriptValue> message,
63 const MessagePortArray& ports, 64 const MessagePortArray& ports,
64 ExceptionState& exception_state) { 65 ExceptionState& exception_state) {
65 if (!IsEntangled()) 66 if (!IsEntangled())
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 115
115 // Invoked to notify us that there are messages available for this port. 116 // Invoked to notify us that there are messages available for this port.
116 // This code may be called from another thread, and so should not call any 117 // This code may be called from another thread, and so should not call any
117 // non-threadsafe APIs (i.e. should not call into the entangled channel or 118 // non-threadsafe APIs (i.e. should not call into the entangled channel or
118 // access mutable variables). 119 // access mutable variables).
119 void MessagePort::MessageAvailable() { 120 void MessagePort::MessageAvailable() {
120 // Don't post another task if there's an identical one pending. 121 // Don't post another task if there's an identical one pending.
121 if (AtomicTestAndSetToOne(&pending_dispatch_task_)) 122 if (AtomicTestAndSetToOne(&pending_dispatch_task_))
122 return; 123 return;
123 124
124 task_runner_->PostTask(BLINK_FROM_HERE, 125 DCHECK(GetExecutionContext());
125 CrossThreadBind(&MessagePort::DispatchMessages, 126 // TODO(tzik): Use ParentThreadTaskRunners instead of ExecutionContext here to
126 WrapCrossThreadWeakPersistent(this))); 127 // avoid touching foreign thread GCed object.
128 GetExecutionContext()->PostTask(
129 TaskType::kPostedMessage, BLINK_FROM_HERE,
130 CreateCrossThreadTask(&MessagePort::DispatchMessages,
131 WrapCrossThreadWeakPersistent(this)));
127 } 132 }
128 133
129 void MessagePort::start() { 134 void MessagePort::start() {
130 // Do nothing if we've been cloned or closed. 135 // Do nothing if we've been cloned or closed.
131 if (!IsEntangled()) 136 if (!IsEntangled())
132 return; 137 return;
133 138
134 DCHECK(GetExecutionContext()); 139 DCHECK(GetExecutionContext());
135 if (started_) 140 if (started_)
136 return; 141 return;
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 } 286 }
282 return port_array; 287 return port_array;
283 } 288 }
284 289
285 DEFINE_TRACE(MessagePort) { 290 DEFINE_TRACE(MessagePort) {
286 ContextLifecycleObserver::Trace(visitor); 291 ContextLifecycleObserver::Trace(visitor);
287 EventTargetWithInlineData::Trace(visitor); 292 EventTargetWithInlineData::Trace(visitor);
288 } 293 }
289 294
290 } // namespace blink 295 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/MessagePort.h ('k') | third_party/WebKit/Source/core/dom/TaskRunnerHelper.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698