| Index: content/browser/service_worker/embedded_worker_registry.cc
|
| diff --git a/content/browser/service_worker/embedded_worker_registry.cc b/content/browser/service_worker/embedded_worker_registry.cc
|
| index 249eab082b21ce3100114299d1da2811217b671b..db0a12818cfdea4744f6f2bc7c8b3f22e5ec1d2c 100644
|
| --- a/content/browser/service_worker/embedded_worker_registry.cc
|
| +++ b/content/browser/service_worker/embedded_worker_registry.cc
|
| @@ -7,7 +7,9 @@
|
| #include "base/stl_util.h"
|
| #include "content/browser/service_worker/embedded_worker_instance.h"
|
| #include "content/browser/service_worker/service_worker_context_core.h"
|
| +#include "content/browser/service_worker/service_worker_context_wrapper.h"
|
| #include "content/common/service_worker/embedded_worker_messages.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| #include "ipc/ipc_message.h"
|
| #include "ipc/ipc_sender.h"
|
|
|
| @@ -25,20 +27,54 @@ scoped_ptr<EmbeddedWorkerInstance> EmbeddedWorkerRegistry::CreateWorker() {
|
| return worker.Pass();
|
| }
|
|
|
| -ServiceWorkerStatusCode EmbeddedWorkerRegistry::StartWorker(
|
| - int process_id,
|
| +void EmbeddedWorkerRegistry::StartWorker(const std::vector<int>& process_ids,
|
| + int embedded_worker_id,
|
| + int64 service_worker_version_id,
|
| + const GURL& scope,
|
| + const GURL& script_url,
|
| + const StatusCallback& callback) {
|
| + BrowserThread::PostTask(
|
| + BrowserThread::UI,
|
| + FROM_HERE,
|
| + base::Bind(
|
| + &ServiceWorkerContextWrapper::IncrementWorkerRef,
|
| + context_->wrapper(),
|
| + process_ids,
|
| + script_url,
|
| + base::Bind(&EmbeddedWorkerRegistry::StartWorkerWithProcessId,
|
| + this,
|
| + embedded_worker_id,
|
| + Passed(make_scoped_ptr(new EmbeddedWorkerMsg_StartWorker(
|
| + embedded_worker_id,
|
| + service_worker_version_id,
|
| + scope,
|
| + script_url))),
|
| + callback)));
|
| +}
|
| +
|
| +void EmbeddedWorkerRegistry::StartWorkerWithProcessId(
|
| int embedded_worker_id,
|
| - int64 service_worker_version_id,
|
| - const GURL& scope,
|
| - const GURL& script_url) {
|
| - return Send(
|
| - process_id,
|
| - new EmbeddedWorkerMsg_StartWorker(
|
| - embedded_worker_id, service_worker_version_id, scope, script_url));
|
| + scoped_ptr<EmbeddedWorkerMsg_StartWorker> message,
|
| + const StatusCallback& callback,
|
| + ServiceWorkerStatusCode status,
|
| + int process_id) {
|
| + DCHECK(ContainsKey(worker_map_, embedded_worker_id));
|
| + worker_map_[embedded_worker_id]->RecordProcessId(process_id, status);
|
| +
|
| + if (status != SERVICE_WORKER_OK) {
|
| + callback.Run(status);
|
| + return;
|
| + }
|
| + DCHECK(ContainsKey(process_sender_map_, process_id));
|
| + callback.Run(Send(process_id, message.release()));
|
| }
|
|
|
| ServiceWorkerStatusCode EmbeddedWorkerRegistry::StopWorker(
|
| int process_id, int embedded_worker_id) {
|
| + BrowserThread::PostTask(
|
| + BrowserThread::UI,
|
| + FROM_HERE,
|
| + base::Bind(&ServiceWorkerContextWrapper::DecrementWorkerRef, process_id));
|
| return Send(process_id,
|
| new EmbeddedWorkerMsg_StopWorker(embedded_worker_id));
|
| }
|
| @@ -55,6 +91,14 @@ bool EmbeddedWorkerRegistry::OnMessageReceived(const IPC::Message& message) {
|
| return found->second->OnMessageReceived(message);
|
| }
|
|
|
| +void EmbeddedWorkerRegistry::Shutdown() {
|
| + for (WorkerInstanceMap::iterator it = worker_map_.begin();
|
| + it != worker_map_.end();
|
| + ++it) {
|
| + it->second->Stop();
|
| + }
|
| +}
|
| +
|
| void EmbeddedWorkerRegistry::OnWorkerStarted(
|
| int process_id, int thread_id, int embedded_worker_id) {
|
| DCHECK(!ContainsKey(worker_process_map_, process_id) ||
|
| @@ -143,7 +187,9 @@ EmbeddedWorkerInstance* EmbeddedWorkerRegistry::GetWorker(
|
| return found->second;
|
| }
|
|
|
| -EmbeddedWorkerRegistry::~EmbeddedWorkerRegistry() {}
|
| +EmbeddedWorkerRegistry::~EmbeddedWorkerRegistry() {
|
| + Shutdown();
|
| +}
|
|
|
| ServiceWorkerStatusCode EmbeddedWorkerRegistry::Send(
|
| int process_id, IPC::Message* message) {
|
|
|