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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 | 164 |
165 void EmbeddedWorkerInstance::ResumeAfterDownload() { | 165 void EmbeddedWorkerInstance::ResumeAfterDownload() { |
166 DCHECK_EQ(STARTING, status_); | 166 DCHECK_EQ(STARTING, status_); |
167 registry_->Send( | 167 registry_->Send( |
168 process_id_, | 168 process_id_, |
169 new EmbeddedWorkerMsg_ResumeAfterDownload(embedded_worker_id_)); | 169 new EmbeddedWorkerMsg_ResumeAfterDownload(embedded_worker_id_)); |
170 } | 170 } |
171 | 171 |
172 ServiceWorkerStatusCode EmbeddedWorkerInstance::SendMessage( | 172 ServiceWorkerStatusCode EmbeddedWorkerInstance::SendMessage( |
173 const IPC::Message& message) { | 173 const IPC::Message& message) { |
174 DCHECK(status_ == RUNNING); | 174 DCHECK_NE(-1, thread_id_); |
dominicc (has gone to gerrit)
2014/08/21 04:04:23
kInvalidThreadId or something grepable for this?
| |
175 if (status_ != RUNNING && status_ != STARTING) | |
176 return SERVICE_WORKER_ERROR_IPC_FAILED; | |
175 return registry_->Send(process_id_, | 177 return registry_->Send(process_id_, |
176 new EmbeddedWorkerContextMsg_MessageToWorker( | 178 new EmbeddedWorkerContextMsg_MessageToWorker( |
177 thread_id_, embedded_worker_id_, message)); | 179 thread_id_, embedded_worker_id_, message)); |
178 } | 180 } |
179 | 181 |
180 void EmbeddedWorkerInstance::AddProcessReference(int process_id) { | 182 void EmbeddedWorkerInstance::AddProcessReference(int process_id) { |
181 ProcessRefMap::iterator found = process_refs_.find(process_id); | 183 ProcessRefMap::iterator found = process_refs_.find(process_id); |
182 if (found == process_refs_.end()) | 184 if (found == process_refs_.end()) |
183 found = process_refs_.insert(std::make_pair(process_id, 0)).first; | 185 found = process_refs_.insert(std::make_pair(process_id, 0)).first; |
184 ++found->second; | 186 ++found->second; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 params->wait_for_debugger = wait_for_debugger; | 269 params->wait_for_debugger = wait_for_debugger; |
268 registry_->SendStartWorker(params.Pass(), callback, process_id_); | 270 registry_->SendStartWorker(params.Pass(), callback, process_id_); |
269 } | 271 } |
270 | 272 |
271 void EmbeddedWorkerInstance::OnReadyForInspection() { | 273 void EmbeddedWorkerInstance::OnReadyForInspection() { |
272 if (worker_devtools_agent_route_id_ != MSG_ROUTING_NONE) | 274 if (worker_devtools_agent_route_id_ != MSG_ROUTING_NONE) |
273 NotifyWorkerReadyForInspection(process_id_, | 275 NotifyWorkerReadyForInspection(process_id_, |
274 worker_devtools_agent_route_id_); | 276 worker_devtools_agent_route_id_); |
275 } | 277 } |
276 | 278 |
277 void EmbeddedWorkerInstance::OnScriptLoaded() { | 279 void EmbeddedWorkerInstance::OnScriptLoaded(int thread_id) { |
280 thread_id_ = thread_id; | |
278 if (worker_devtools_agent_route_id_ != MSG_ROUTING_NONE) | 281 if (worker_devtools_agent_route_id_ != MSG_ROUTING_NONE) |
279 NotifyWorkerContextStarted(process_id_, worker_devtools_agent_route_id_); | 282 NotifyWorkerContextStarted(process_id_, worker_devtools_agent_route_id_); |
280 } | 283 } |
281 | 284 |
282 void EmbeddedWorkerInstance::OnScriptLoadFailed() { | 285 void EmbeddedWorkerInstance::OnScriptLoadFailed() { |
283 } | 286 } |
284 | 287 |
285 void EmbeddedWorkerInstance::OnStarted(int thread_id) { | 288 void EmbeddedWorkerInstance::OnStarted() { |
286 // Stop is requested before OnStarted is sent back from the worker. | 289 // Stop is requested before OnStarted is sent back from the worker. |
287 if (status_ == STOPPING) | 290 if (status_ == STOPPING) |
288 return; | 291 return; |
289 DCHECK(status_ == STARTING); | 292 DCHECK(status_ == STARTING); |
290 status_ = RUNNING; | 293 status_ = RUNNING; |
291 thread_id_ = thread_id; | |
292 FOR_EACH_OBSERVER(Listener, listener_list_, OnStarted()); | 294 FOR_EACH_OBSERVER(Listener, listener_list_, OnStarted()); |
293 } | 295 } |
294 | 296 |
295 void EmbeddedWorkerInstance::OnStopped() { | 297 void EmbeddedWorkerInstance::OnStopped() { |
296 if (worker_devtools_agent_route_id_ != MSG_ROUTING_NONE) | 298 if (worker_devtools_agent_route_id_ != MSG_ROUTING_NONE) |
297 NotifyWorkerDestroyed(process_id_, worker_devtools_agent_route_id_); | 299 NotifyWorkerDestroyed(process_id_, worker_devtools_agent_route_id_); |
298 if (context_) | 300 if (context_) |
299 context_->process_manager()->ReleaseWorkerProcess(embedded_worker_id_); | 301 context_->process_manager()->ReleaseWorkerProcess(embedded_worker_id_); |
300 status_ = STOPPED; | 302 status_ = STOPPED; |
301 process_id_ = -1; | 303 process_id_ = -1; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
369 // Sort descending by the reference count. | 371 // Sort descending by the reference count. |
370 std::sort(counted.begin(), counted.end(), SecondGreater()); | 372 std::sort(counted.begin(), counted.end(), SecondGreater()); |
371 | 373 |
372 std::vector<int> result(counted.size()); | 374 std::vector<int> result(counted.size()); |
373 for (size_t i = 0; i < counted.size(); ++i) | 375 for (size_t i = 0; i < counted.size(); ++i) |
374 result[i] = counted[i].first; | 376 result[i] = counted[i].first; |
375 return result; | 377 return result; |
376 } | 378 } |
377 | 379 |
378 } // namespace content | 380 } // namespace content |
OLD | NEW |