OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/shared_worker/shared_worker_host.h" | 5 #include "content/browser/shared_worker/shared_worker_host.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "content/browser/devtools/embedded_worker_devtools_manager.h" | 8 #include "content/browser/devtools/embedded_worker_devtools_manager.h" |
9 #include "content/browser/frame_host/render_frame_host_delegate.h" | 9 #include "content/browser/frame_host/render_frame_host_delegate.h" |
10 #include "content/browser/frame_host/render_frame_host_impl.h" | 10 #include "content/browser/frame_host/render_frame_host_impl.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 namespace { | 24 namespace { |
25 | 25 |
26 // Notifies RenderViewHost that one or more worker objects crashed. | 26 // Notifies RenderViewHost that one or more worker objects crashed. |
27 void WorkerCrashCallback(int render_process_unique_id, int render_frame_id) { | 27 void WorkerCrashCallback(int render_process_unique_id, int render_frame_id) { |
28 RenderFrameHostImpl* host = | 28 RenderFrameHostImpl* host = |
29 RenderFrameHostImpl::FromID(render_process_unique_id, render_frame_id); | 29 RenderFrameHostImpl::FromID(render_process_unique_id, render_frame_id); |
30 if (host) | 30 if (host) |
31 host->delegate()->WorkerCrashed(host); | 31 host->delegate()->WorkerCrashed(host); |
32 } | 32 } |
33 | 33 |
34 void NotifyWorkerScriptLoadedOnUI(int worker_process_id, int worker_route_id) { | 34 void NotifyWorkerContextStarted(int worker_process_id, int worker_route_id) { |
35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 35 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 36 BrowserThread::PostTask( |
| 37 BrowserThread::UI, |
| 38 FROM_HERE, |
| 39 base::Bind( |
| 40 NotifyWorkerContextStarted, worker_process_id, worker_route_id)); |
| 41 return; |
| 42 } |
36 EmbeddedWorkerDevToolsManager::GetInstance()->WorkerContextStarted( | 43 EmbeddedWorkerDevToolsManager::GetInstance()->WorkerContextStarted( |
37 worker_process_id, worker_route_id); | 44 worker_process_id, worker_route_id); |
38 } | 45 } |
39 | 46 |
40 void NotifyWorkerDestroyedOnUI(int worker_process_id, int worker_route_id) { | 47 void NotifyWorkerDestroyed(int worker_process_id, int worker_route_id) { |
41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 48 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 49 BrowserThread::PostTask( |
| 50 BrowserThread::UI, |
| 51 FROM_HERE, |
| 52 base::Bind(NotifyWorkerDestroyed, worker_process_id, worker_route_id)); |
| 53 return; |
| 54 } |
42 EmbeddedWorkerDevToolsManager::GetInstance()->WorkerDestroyed( | 55 EmbeddedWorkerDevToolsManager::GetInstance()->WorkerDestroyed( |
43 worker_process_id, worker_route_id); | 56 worker_process_id, worker_route_id); |
44 } | 57 } |
45 | 58 |
46 } // namespace | 59 } // namespace |
47 | 60 |
48 SharedWorkerHost::SharedWorkerHost(SharedWorkerInstance* instance, | 61 SharedWorkerHost::SharedWorkerHost(SharedWorkerInstance* instance, |
49 SharedWorkerMessageFilter* filter, | 62 SharedWorkerMessageFilter* filter, |
50 int worker_route_id) | 63 int worker_route_id) |
51 : instance_(instance), | 64 : instance_(instance), |
(...skipping 19 matching lines...) Expand all Loading... |
71 parents.begin(); | 84 parents.begin(); |
72 parent_iter != parents.end(); | 85 parent_iter != parents.end(); |
73 ++parent_iter) { | 86 ++parent_iter) { |
74 BrowserThread::PostTask(BrowserThread::UI, | 87 BrowserThread::PostTask(BrowserThread::UI, |
75 FROM_HERE, | 88 FROM_HERE, |
76 base::Bind(&WorkerCrashCallback, | 89 base::Bind(&WorkerCrashCallback, |
77 parent_iter->render_process_id(), | 90 parent_iter->render_process_id(), |
78 parent_iter->render_frame_id())); | 91 parent_iter->render_frame_id())); |
79 } | 92 } |
80 } | 93 } |
81 BrowserThread::PostTask( | 94 if (!closed_) |
82 BrowserThread::UI, | 95 NotifyWorkerDestroyed(worker_process_id_, worker_route_id_); |
83 FROM_HERE, | |
84 base::Bind( | |
85 &NotifyWorkerDestroyedOnUI, worker_process_id_, worker_route_id_)); | |
86 SharedWorkerServiceImpl::GetInstance()->NotifyWorkerDestroyed( | 96 SharedWorkerServiceImpl::GetInstance()->NotifyWorkerDestroyed( |
87 worker_process_id_, worker_route_id_); | 97 worker_process_id_, worker_route_id_); |
88 } | 98 } |
89 | 99 |
90 bool SharedWorkerHost::Send(IPC::Message* message) { | 100 bool SharedWorkerHost::Send(IPC::Message* message) { |
91 if (!container_render_filter_) { | 101 if (!container_render_filter_) { |
92 delete message; | 102 delete message; |
93 return false; | 103 return false; |
94 } | 104 } |
95 return container_render_filter_->Send(message); | 105 return container_render_filter_->Send(message); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 } | 157 } |
148 } | 158 } |
149 | 159 |
150 void SharedWorkerHost::WorkerContextClosed() { | 160 void SharedWorkerHost::WorkerContextClosed() { |
151 if (!instance_) | 161 if (!instance_) |
152 return; | 162 return; |
153 // Set the closed flag - this will stop any further messages from | 163 // Set the closed flag - this will stop any further messages from |
154 // being sent to the worker (messages can still be sent from the worker, | 164 // being sent to the worker (messages can still be sent from the worker, |
155 // for exception reporting, etc). | 165 // for exception reporting, etc). |
156 closed_ = true; | 166 closed_ = true; |
| 167 NotifyWorkerDestroyed(worker_process_id_, worker_route_id_); |
157 } | 168 } |
158 | 169 |
159 void SharedWorkerHost::WorkerContextDestroyed() { | 170 void SharedWorkerHost::WorkerContextDestroyed() { |
160 if (!instance_) | 171 if (!instance_) |
161 return; | 172 return; |
162 instance_.reset(); | 173 instance_.reset(); |
163 worker_document_set_ = NULL; | 174 worker_document_set_ = NULL; |
164 } | 175 } |
165 | 176 |
166 void SharedWorkerHost::WorkerScriptLoaded() { | 177 void SharedWorkerHost::WorkerScriptLoaded() { |
167 UMA_HISTOGRAM_TIMES("SharedWorker.TimeToScriptLoaded", | 178 UMA_HISTOGRAM_TIMES("SharedWorker.TimeToScriptLoaded", |
168 base::TimeTicks::Now() - creation_time_); | 179 base::TimeTicks::Now() - creation_time_); |
169 BrowserThread::PostTask( | 180 NotifyWorkerContextStarted(worker_process_id_, worker_route_id_); |
170 BrowserThread::UI, | |
171 FROM_HERE, | |
172 base::Bind( | |
173 &NotifyWorkerScriptLoadedOnUI, worker_process_id_, worker_route_id_)); | |
174 } | 181 } |
175 | 182 |
176 void SharedWorkerHost::WorkerScriptLoadFailed() { | 183 void SharedWorkerHost::WorkerScriptLoadFailed() { |
177 UMA_HISTOGRAM_TIMES("SharedWorker.TimeToScriptLoadFailed", | 184 UMA_HISTOGRAM_TIMES("SharedWorker.TimeToScriptLoadFailed", |
178 base::TimeTicks::Now() - creation_time_); | 185 base::TimeTicks::Now() - creation_time_); |
179 if (!instance_) | 186 if (!instance_) |
180 return; | 187 return; |
181 load_failed_ = true; | 188 load_failed_ = true; |
182 for (FilterList::const_iterator i = filters_.begin(); i != filters_.end(); | 189 for (FilterList::const_iterator i = filters_.begin(); i != filters_.end(); |
183 ++i) { | 190 ++i) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 int message_port_id) { | 327 int message_port_id) { |
321 for (FilterList::iterator i = filters_.begin(); i != filters_.end(); ++i) { | 328 for (FilterList::iterator i = filters_.begin(); i != filters_.end(); ++i) { |
322 if (i->filter() == filter && i->route_id() == route_id) { | 329 if (i->filter() == filter && i->route_id() == route_id) { |
323 i->set_message_port_id(message_port_id); | 330 i->set_message_port_id(message_port_id); |
324 return; | 331 return; |
325 } | 332 } |
326 } | 333 } |
327 } | 334 } |
328 | 335 |
329 } // namespace content | 336 } // namespace content |
OLD | NEW |