OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/service_worker/embedded_worker_instance.h" | 5 #include "content/browser/service_worker/embedded_worker_instance.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 BrowserThread::PostTask( | 50 BrowserThread::PostTask( |
51 BrowserThread::UI, | 51 BrowserThread::UI, |
52 FROM_HERE, | 52 FROM_HERE, |
53 base::Bind(NotifyWorkerDestroyed, worker_process_id, worker_route_id)); | 53 base::Bind(NotifyWorkerDestroyed, worker_process_id, worker_route_id)); |
54 return; | 54 return; |
55 } | 55 } |
56 EmbeddedWorkerDevToolsManager::GetInstance()->WorkerDestroyed( | 56 EmbeddedWorkerDevToolsManager::GetInstance()->WorkerDestroyed( |
57 worker_process_id, worker_route_id); | 57 worker_process_id, worker_route_id); |
58 } | 58 } |
59 | 59 |
60 void NotifyWorkerStopIgnored(int worker_process_id, int worker_route_id) { | |
61 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
pfeldman
2014/12/15 05:57:04
This implies it can be called multiple threads, bu
pfeldman
2014/12/15 06:11:08
I can see you are following a pattern here, but th
kinuko
2014/12/15 06:39:14
This pattern is used pretty widely in content/brow
pfeldman
2014/12/15 07:05:04
Hm, I am surprised how widely it has spread. I thi
pfeldman
2014/12/15 07:18:42
I looked at the usages of the pattern and found ou
kinuko
2014/12/15 07:41:18
Is the reason you think so because this pattern gi
| |
62 BrowserThread::PostTask(BrowserThread::UI, | |
63 FROM_HERE, | |
64 base::Bind(NotifyWorkerStopIgnored, | |
65 worker_process_id, | |
66 worker_route_id)); | |
67 return; | |
68 } | |
69 EmbeddedWorkerDevToolsManager::GetInstance()->WorkerStopIgnored( | |
70 worker_process_id, worker_route_id); | |
71 } | |
72 | |
73 | |
60 void RegisterToWorkerDevToolsManager( | 74 void RegisterToWorkerDevToolsManager( |
61 int process_id, | 75 int process_id, |
62 const ServiceWorkerContextCore* service_worker_context, | 76 const ServiceWorkerContextCore* service_worker_context, |
63 base::WeakPtr<ServiceWorkerContextCore> service_worker_context_weak, | 77 base::WeakPtr<ServiceWorkerContextCore> service_worker_context_weak, |
64 int64 service_worker_version_id, | 78 int64 service_worker_version_id, |
65 const GURL& url, | 79 const GURL& url, |
66 const base::Callback<void(int worker_devtools_agent_route_id, | 80 const base::Callback<void(int worker_devtools_agent_route_id, |
67 bool wait_for_debugger)>& callback) { | 81 bool wait_for_debugger)>& callback) { |
68 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 82 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
69 BrowserThread::PostTask(BrowserThread::UI, | 83 BrowserThread::PostTask(BrowserThread::UI, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 | 162 |
149 ServiceWorkerStatusCode EmbeddedWorkerInstance::Stop() { | 163 ServiceWorkerStatusCode EmbeddedWorkerInstance::Stop() { |
150 DCHECK(status_ == STARTING || status_ == RUNNING); | 164 DCHECK(status_ == STARTING || status_ == RUNNING); |
151 ServiceWorkerStatusCode status = | 165 ServiceWorkerStatusCode status = |
152 registry_->StopWorker(process_id_, embedded_worker_id_); | 166 registry_->StopWorker(process_id_, embedded_worker_id_); |
153 if (status == SERVICE_WORKER_OK) | 167 if (status == SERVICE_WORKER_OK) |
154 status_ = STOPPING; | 168 status_ = STOPPING; |
155 return status; | 169 return status; |
156 } | 170 } |
157 | 171 |
172 void EmbeddedWorkerInstance::StopIfIdle() { | |
173 if (devtools_attached_) { | |
174 NotifyWorkerStopIgnored(process_id_, worker_devtools_agent_route_id_); | |
175 return; | |
176 } | |
177 Stop(); | |
178 } | |
179 | |
158 void EmbeddedWorkerInstance::ResumeAfterDownload() { | 180 void EmbeddedWorkerInstance::ResumeAfterDownload() { |
159 DCHECK_EQ(STARTING, status_); | 181 DCHECK_EQ(STARTING, status_); |
160 registry_->Send( | 182 registry_->Send( |
161 process_id_, | 183 process_id_, |
162 new EmbeddedWorkerMsg_ResumeAfterDownload(embedded_worker_id_)); | 184 new EmbeddedWorkerMsg_ResumeAfterDownload(embedded_worker_id_)); |
163 } | 185 } |
164 | 186 |
165 ServiceWorkerStatusCode EmbeddedWorkerInstance::SendMessage( | 187 ServiceWorkerStatusCode EmbeddedWorkerInstance::SendMessage( |
166 const IPC::Message& message) { | 188 const IPC::Message& message) { |
167 DCHECK_NE(kInvalidEmbeddedWorkerThreadId, thread_id_); | 189 DCHECK_NE(kInvalidEmbeddedWorkerThreadId, thread_id_); |
168 if (status_ != RUNNING && status_ != STARTING) | 190 if (status_ != RUNNING && status_ != STARTING) |
169 return SERVICE_WORKER_ERROR_IPC_FAILED; | 191 return SERVICE_WORKER_ERROR_IPC_FAILED; |
170 return registry_->Send(process_id_, | 192 return registry_->Send(process_id_, |
171 new EmbeddedWorkerContextMsg_MessageToWorker( | 193 new EmbeddedWorkerContextMsg_MessageToWorker( |
172 thread_id_, embedded_worker_id_, message)); | 194 thread_id_, embedded_worker_id_, message)); |
173 } | 195 } |
174 | 196 |
175 EmbeddedWorkerInstance::EmbeddedWorkerInstance( | 197 EmbeddedWorkerInstance::EmbeddedWorkerInstance( |
176 base::WeakPtr<ServiceWorkerContextCore> context, | 198 base::WeakPtr<ServiceWorkerContextCore> context, |
177 int embedded_worker_id) | 199 int embedded_worker_id) |
178 : context_(context), | 200 : context_(context), |
179 registry_(context->embedded_worker_registry()), | 201 registry_(context->embedded_worker_registry()), |
180 embedded_worker_id_(embedded_worker_id), | 202 embedded_worker_id_(embedded_worker_id), |
181 status_(STOPPED), | 203 status_(STOPPED), |
182 process_id_(-1), | 204 process_id_(-1), |
183 thread_id_(kInvalidEmbeddedWorkerThreadId), | 205 thread_id_(kInvalidEmbeddedWorkerThreadId), |
184 worker_devtools_agent_route_id_(MSG_ROUTING_NONE), | 206 worker_devtools_agent_route_id_(MSG_ROUTING_NONE), |
207 devtools_attached_(false), | |
185 weak_factory_(this) { | 208 weak_factory_(this) { |
186 } | 209 } |
187 | 210 |
188 // static | 211 // static |
189 void EmbeddedWorkerInstance::RunProcessAllocated( | 212 void EmbeddedWorkerInstance::RunProcessAllocated( |
190 base::WeakPtr<EmbeddedWorkerInstance> instance, | 213 base::WeakPtr<EmbeddedWorkerInstance> instance, |
191 base::WeakPtr<ServiceWorkerContextCore> context, | 214 base::WeakPtr<ServiceWorkerContextCore> context, |
192 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params, | 215 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params, |
193 const EmbeddedWorkerInstance::StatusCallback& callback, | 216 const EmbeddedWorkerInstance::StatusCallback& callback, |
194 ServiceWorkerStatusCode status, | 217 ServiceWorkerStatusCode status, |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
348 | 371 |
349 void EmbeddedWorkerInstance::AddListener(Listener* listener) { | 372 void EmbeddedWorkerInstance::AddListener(Listener* listener) { |
350 listener_list_.AddObserver(listener); | 373 listener_list_.AddObserver(listener); |
351 } | 374 } |
352 | 375 |
353 void EmbeddedWorkerInstance::RemoveListener(Listener* listener) { | 376 void EmbeddedWorkerInstance::RemoveListener(Listener* listener) { |
354 listener_list_.RemoveObserver(listener); | 377 listener_list_.RemoveObserver(listener); |
355 } | 378 } |
356 | 379 |
357 } // namespace content | 380 } // namespace content |
OLD | NEW |