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

Side by Side Diff: Source/core/workers/Worker.cpp

Issue 370553003: Have the Worker destructor handle non-started Workers better. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Swap lines; tidier. Created 6 years, 5 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 | 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) 2008, 2010 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008, 2010 Apple Inc. All Rights Reserved.
3 * Copyright (C) 2009 Google Inc. All Rights Reserved. 3 * Copyright (C) 2009 Google Inc. All Rights Reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 75
76 worker->m_scriptLoader = WorkerScriptLoader::create(); 76 worker->m_scriptLoader = WorkerScriptLoader::create();
77 worker->m_scriptLoader->loadAsynchronously(*context, scriptURL, DenyCrossOri ginRequests, worker.get()); 77 worker->m_scriptLoader->loadAsynchronously(*context, scriptURL, DenyCrossOri ginRequests, worker.get());
78 worker->m_contextProxy = proxyProvider->createWorkerGlobalScopeProxy(worker. get()); 78 worker->m_contextProxy = proxyProvider->createWorkerGlobalScopeProxy(worker. get());
79 return worker.release(); 79 return worker.release();
80 } 80 }
81 81
82 Worker::~Worker() 82 Worker::~Worker()
83 { 83 {
84 ASSERT(isMainThread()); 84 ASSERT(isMainThread());
85 if (!m_contextProxy)
86 return;
85 ASSERT(executionContext()); // The context is protected by worker context pr oxy, so it cannot be destroyed while a Worker exists. 87 ASSERT(executionContext()); // The context is protected by worker context pr oxy, so it cannot be destroyed while a Worker exists.
86 if (m_contextProxy) 88 m_contextProxy->workerObjectDestroyed();
87 m_contextProxy->workerObjectDestroyed();
88 } 89 }
89 90
90 const AtomicString& Worker::interfaceName() const 91 const AtomicString& Worker::interfaceName() const
91 { 92 {
92 return EventTargetNames::Worker; 93 return EventTargetNames::Worker;
93 } 94 }
94 95
95 void Worker::postMessage(PassRefPtr<SerializedScriptValue> message, const Messag ePortArray* ports, ExceptionState& exceptionState) 96 void Worker::postMessage(PassRefPtr<SerializedScriptValue> message, const Messag ePortArray* ports, ExceptionState& exceptionState)
96 { 97 {
98 ASSERT(m_contextProxy);
97 // Disentangle the port in preparation for sending it to the remote context. 99 // Disentangle the port in preparation for sending it to the remote context.
98 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(por ts, exceptionState); 100 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(por ts, exceptionState);
99 if (exceptionState.hadException()) 101 if (exceptionState.hadException())
100 return; 102 return;
101 m_contextProxy->postMessageToWorkerGlobalScope(message, channels.release()); 103 m_contextProxy->postMessageToWorkerGlobalScope(message, channels.release());
102 } 104 }
103 105
104 void Worker::terminate() 106 void Worker::terminate()
105 { 107 {
106 if (m_contextProxy) 108 if (m_contextProxy)
107 m_contextProxy->terminateWorkerGlobalScope(); 109 m_contextProxy->terminateWorkerGlobalScope();
108 } 110 }
109 111
110 void Worker::stop() 112 void Worker::stop()
111 { 113 {
112 terminate(); 114 terminate();
113 } 115 }
114 116
115 bool Worker::hasPendingActivity() const 117 bool Worker::hasPendingActivity() const
116 { 118 {
117 return m_contextProxy->hasPendingActivity() || ActiveDOMObject::hasPendingAc tivity(); 119 return (m_contextProxy && m_contextProxy->hasPendingActivity()) || ActiveDOM Object::hasPendingActivity();
118 } 120 }
119 121
120 void Worker::didReceiveResponse(unsigned long identifier, const ResourceResponse &) 122 void Worker::didReceiveResponse(unsigned long identifier, const ResourceResponse &)
121 { 123 {
122 InspectorInstrumentation::didReceiveScriptResponse(executionContext(), ident ifier); 124 InspectorInstrumentation::didReceiveScriptResponse(executionContext(), ident ifier);
123 } 125 }
124 126
125 void Worker::notifyFinished() 127 void Worker::notifyFinished()
126 { 128 {
127 if (m_scriptLoader->failed()) { 129 if (m_scriptLoader->failed()) {
128 dispatchEvent(Event::createCancelable(EventTypeNames::error)); 130 dispatchEvent(Event::createCancelable(EventTypeNames::error));
129 } else { 131 } else {
132 ASSERT(m_contextProxy);
130 WorkerThreadStartMode startMode = DontPauseWorkerGlobalScopeOnStart; 133 WorkerThreadStartMode startMode = DontPauseWorkerGlobalScopeOnStart;
131 if (InspectorInstrumentation::shouldPauseDedicatedWorkerOnStart(executio nContext())) 134 if (InspectorInstrumentation::shouldPauseDedicatedWorkerOnStart(executio nContext()))
132 startMode = PauseWorkerGlobalScopeOnStart; 135 startMode = PauseWorkerGlobalScopeOnStart;
133 m_contextProxy->startWorkerGlobalScope(m_scriptLoader->url(), executionC ontext()->userAgent(m_scriptLoader->url()), m_scriptLoader->script(), startMode) ; 136 m_contextProxy->startWorkerGlobalScope(m_scriptLoader->url(), executionC ontext()->userAgent(m_scriptLoader->url()), m_scriptLoader->script(), startMode) ;
134 InspectorInstrumentation::scriptImported(executionContext(), m_scriptLoa der->identifier(), m_scriptLoader->script()); 137 InspectorInstrumentation::scriptImported(executionContext(), m_scriptLoa der->identifier(), m_scriptLoader->script());
135 } 138 }
136 m_scriptLoader = nullptr; 139 m_scriptLoader = nullptr;
137 140
138 unsetPendingActivity(this); 141 unsetPendingActivity(this);
139 } 142 }
140 143
141 void Worker::trace(Visitor* visitor) 144 void Worker::trace(Visitor* visitor)
142 { 145 {
143 AbstractWorker::trace(visitor); 146 AbstractWorker::trace(visitor);
144 } 147 }
145 148
146 } // namespace WebCore 149 } // namespace WebCore
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698