| 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/renderer/service_worker/embedded_worker_dispatcher.h" | 5 #include "content/renderer/service_worker/embedded_worker_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "content/child/child_process.h" | 10 #include "content/child/child_process.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 return handled; | 51 return handled; |
| 52 } | 52 } |
| 53 | 53 |
| 54 void EmbeddedWorkerDispatcher::WorkerContextDestroyed( | 54 void EmbeddedWorkerDispatcher::WorkerContextDestroyed( |
| 55 int embedded_worker_id) { | 55 int embedded_worker_id) { |
| 56 RenderThreadImpl::current()->thread_safe_sender()->Send( | 56 RenderThreadImpl::current()->thread_safe_sender()->Send( |
| 57 new EmbeddedWorkerHostMsg_WorkerStopped(embedded_worker_id)); | 57 new EmbeddedWorkerHostMsg_WorkerStopped(embedded_worker_id)); |
| 58 workers_.Remove(embedded_worker_id); | 58 workers_.Remove(embedded_worker_id); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void EmbeddedWorkerDispatcher::OnStartWorker(int embedded_worker_id, | 61 void EmbeddedWorkerDispatcher::OnStartWorker( |
| 62 int64 service_worker_version_id, | 62 const EmbeddedWorkerMsg_StartWorker_Params& params) { |
| 63 const GURL& service_worker_scope, | 63 DCHECK(!workers_.Lookup(params.embedded_worker_id)); |
| 64 const GURL& script_url) { | |
| 65 DCHECK(!workers_.Lookup(embedded_worker_id)); | |
| 66 RenderThread::Get()->EnsureWebKitInitialized(); | 64 RenderThread::Get()->EnsureWebKitInitialized(); |
| 67 scoped_ptr<WorkerWrapper> wrapper(new WorkerWrapper( | 65 scoped_ptr<WorkerWrapper> wrapper( |
| 68 blink::WebEmbeddedWorker::create( | 66 new WorkerWrapper(blink::WebEmbeddedWorker::create( |
| 69 new EmbeddedWorkerContextClient( | 67 new EmbeddedWorkerContextClient( |
| 70 embedded_worker_id, | 68 params.embedded_worker_id, |
| 71 service_worker_version_id, | 69 params.service_worker_version_id, |
| 72 service_worker_scope, | 70 params.scope, |
| 73 script_url), | 71 params.script_url, |
| 72 params.worker_devtools_agent_route_id), |
| 74 NULL))); | 73 NULL))); |
| 75 | 74 |
| 76 blink::WebEmbeddedWorkerStartData start_data; | 75 blink::WebEmbeddedWorkerStartData start_data; |
| 77 start_data.scriptURL = script_url; | 76 start_data.scriptURL = params.script_url; |
| 78 start_data.userAgent = base::UTF8ToUTF16(GetContentClient()->GetUserAgent()); | 77 start_data.userAgent = base::UTF8ToUTF16(GetContentClient()->GetUserAgent()); |
| 79 start_data.startMode = blink::WebEmbeddedWorkerStartModeDontPauseOnStart; | 78 start_data.startMode = blink::WebEmbeddedWorkerStartModeDontPauseOnStart; |
| 80 | 79 |
| 81 wrapper->worker()->startWorkerContext(start_data); | 80 wrapper->worker()->startWorkerContext(start_data); |
| 82 workers_.AddWithID(wrapper.release(), embedded_worker_id); | 81 workers_.AddWithID(wrapper.release(), params.embedded_worker_id); |
| 83 } | 82 } |
| 84 | 83 |
| 85 void EmbeddedWorkerDispatcher::OnStopWorker(int embedded_worker_id) { | 84 void EmbeddedWorkerDispatcher::OnStopWorker(int embedded_worker_id) { |
| 86 WorkerWrapper* wrapper = workers_.Lookup(embedded_worker_id); | 85 WorkerWrapper* wrapper = workers_.Lookup(embedded_worker_id); |
| 87 if (!wrapper) { | 86 if (!wrapper) { |
| 88 LOG(WARNING) << "Got OnStopWorker for nonexistent worker"; | 87 LOG(WARNING) << "Got OnStopWorker for nonexistent worker"; |
| 89 return; | 88 return; |
| 90 } | 89 } |
| 91 | 90 |
| 92 // This should eventually call WorkerContextDestroyed. (We may need to post | 91 // This should eventually call WorkerContextDestroyed. (We may need to post |
| 93 // a delayed task to forcibly abort the worker context if we find it | 92 // a delayed task to forcibly abort the worker context if we find it |
| 94 // necessary) | 93 // necessary) |
| 95 wrapper->worker()->terminateWorkerContext(); | 94 wrapper->worker()->terminateWorkerContext(); |
| 96 } | 95 } |
| 97 | 96 |
| 98 } // namespace content | 97 } // namespace content |
| OLD | NEW |