| 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(int worker_route_id, |
| 62 int embedded_worker_id, |
| 62 int64 service_worker_version_id, | 63 int64 service_worker_version_id, |
| 63 const GURL& service_worker_scope, | 64 const GURL& service_worker_scope, |
| 64 const GURL& script_url) { | 65 const GURL& script_url) { |
| 65 DCHECK(!workers_.Lookup(embedded_worker_id)); | 66 DCHECK(!workers_.Lookup(embedded_worker_id)); |
| 66 scoped_ptr<WorkerWrapper> wrapper(new WorkerWrapper( | 67 scoped_ptr<WorkerWrapper> wrapper( |
| 67 blink::WebEmbeddedWorker::create( | 68 new WorkerWrapper(blink::WebEmbeddedWorker::create( |
| 68 new EmbeddedWorkerContextClient( | 69 new EmbeddedWorkerContextClient(worker_route_id, |
| 69 embedded_worker_id, | 70 embedded_worker_id, |
| 70 service_worker_version_id, | 71 service_worker_version_id, |
| 71 service_worker_scope, | 72 service_worker_scope, |
| 72 script_url), | 73 script_url), |
| 73 NULL))); | 74 NULL))); |
| 74 | 75 |
| 75 blink::WebEmbeddedWorkerStartData start_data; | 76 blink::WebEmbeddedWorkerStartData start_data; |
| 76 start_data.scriptURL = script_url; | 77 start_data.scriptURL = script_url; |
| 77 start_data.userAgent = base::UTF8ToUTF16(GetContentClient()->GetUserAgent()); | 78 start_data.userAgent = base::UTF8ToUTF16(GetContentClient()->GetUserAgent()); |
| 78 start_data.startMode = blink::WebEmbeddedWorkerStartModeDontPauseOnStart; | 79 start_data.startMode = blink::WebEmbeddedWorkerStartModeDontPauseOnStart; |
| 79 | 80 |
| 80 wrapper->worker()->startWorkerContext(start_data); | 81 wrapper->worker()->startWorkerContext(start_data); |
| 81 workers_.AddWithID(wrapper.release(), embedded_worker_id); | 82 workers_.AddWithID(wrapper.release(), embedded_worker_id); |
| 82 } | 83 } |
| 83 | 84 |
| 84 void EmbeddedWorkerDispatcher::OnStopWorker(int embedded_worker_id) { | 85 void EmbeddedWorkerDispatcher::OnStopWorker(int embedded_worker_id) { |
| 85 WorkerWrapper* wrapper = workers_.Lookup(embedded_worker_id); | 86 WorkerWrapper* wrapper = workers_.Lookup(embedded_worker_id); |
| 86 if (!wrapper) { | 87 if (!wrapper) { |
| 87 LOG(WARNING) << "Got OnStopWorker for nonexistent worker"; | 88 LOG(WARNING) << "Got OnStopWorker for nonexistent worker"; |
| 88 return; | 89 return; |
| 89 } | 90 } |
| 90 | 91 |
| 91 // This should eventually call WorkerContextDestroyed. (We may need to post | 92 // This should eventually call WorkerContextDestroyed. (We may need to post |
| 92 // a delayed task to forcibly abort the worker context if we find it | 93 // a delayed task to forcibly abort the worker context if we find it |
| 93 // necessary) | 94 // necessary) |
| 94 wrapper->worker()->terminateWorkerContext(); | 95 wrapper->worker()->terminateWorkerContext(); |
| 95 } | 96 } |
| 96 | 97 |
| 97 } // namespace content | 98 } // namespace content |
| OLD | NEW |