OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/service_worker_context_client.h" | 5 #include "content/renderer/service_worker/service_worker_context_client.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 // worker run loop has been started. | 399 // worker run loop has been started. |
400 worker_task_runner_->PostTask( | 400 worker_task_runner_->PostTask( |
401 FROM_HERE, base::Bind(&ServiceWorkerContextClient::SendWorkerStarted, | 401 FROM_HERE, base::Bind(&ServiceWorkerContextClient::SendWorkerStarted, |
402 GetWeakPtr())); | 402 GetWeakPtr())); |
403 } | 403 } |
404 | 404 |
405 void ServiceWorkerContextClient::didInitializeWorkerContext( | 405 void ServiceWorkerContextClient::didInitializeWorkerContext( |
406 v8::Local<v8::Context> context) { | 406 v8::Local<v8::Context> context) { |
407 GetContentClient() | 407 GetContentClient() |
408 ->renderer() | 408 ->renderer() |
409 ->DidInitializeServiceWorkerContextOnWorkerThread(context, script_url_); | 409 ->DidInitializeServiceWorkerContextOnWorkerThread( |
| 410 context, embedded_worker_id_, script_url_); |
410 } | 411 } |
411 | 412 |
412 void ServiceWorkerContextClient::willDestroyWorkerContext( | 413 void ServiceWorkerContextClient::willDestroyWorkerContext( |
413 v8::Local<v8::Context> context) { | 414 v8::Local<v8::Context> context) { |
414 // At this point WillStopCurrentWorkerThread is already called, so | 415 // At this point WillStopCurrentWorkerThread is already called, so |
415 // worker_task_runner_->RunsTasksOnCurrentThread() returns false | 416 // worker_task_runner_->RunsTasksOnCurrentThread() returns false |
416 // (while we're still on the worker thread). | 417 // (while we're still on the worker thread). |
417 proxy_ = NULL; | 418 proxy_ = NULL; |
418 | 419 |
419 // We have to clear callbacks now, as they need to be freed on the | 420 // We have to clear callbacks now, as they need to be freed on the |
420 // same thread. | 421 // same thread. |
421 context_.reset(); | 422 context_.reset(); |
422 | 423 |
423 // This also lets the message filter stop dispatching messages to | 424 // This also lets the message filter stop dispatching messages to |
424 // this client. | 425 // this client. |
425 g_worker_client_tls.Pointer()->Set(NULL); | 426 g_worker_client_tls.Pointer()->Set(NULL); |
426 | 427 |
427 GetContentClient()->renderer()->WillDestroyServiceWorkerContextOnWorkerThread( | 428 GetContentClient()->renderer()->WillDestroyServiceWorkerContextOnWorkerThread( |
428 context, script_url_); | 429 context, embedded_worker_id_, script_url_); |
429 } | 430 } |
430 | 431 |
431 void ServiceWorkerContextClient::workerContextDestroyed() { | 432 void ServiceWorkerContextClient::workerContextDestroyed() { |
432 DCHECK(g_worker_client_tls.Pointer()->Get() == NULL); | 433 DCHECK(g_worker_client_tls.Pointer()->Get() == NULL); |
433 | 434 |
434 // Now we should be able to free the WebEmbeddedWorker container on the | 435 // Now we should be able to free the WebEmbeddedWorker container on the |
435 // main thread. | 436 // main thread. |
436 main_thread_task_runner_->PostTask( | 437 main_thread_task_runner_->PostTask( |
437 FROM_HERE, | 438 FROM_HERE, |
438 base::Bind(&CallWorkerContextDestroyedOnMainThread, | 439 base::Bind(&CallWorkerContextDestroyedOnMainThread, |
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1024 } | 1025 } |
1025 | 1026 |
1026 base::WeakPtr<ServiceWorkerContextClient> | 1027 base::WeakPtr<ServiceWorkerContextClient> |
1027 ServiceWorkerContextClient::GetWeakPtr() { | 1028 ServiceWorkerContextClient::GetWeakPtr() { |
1028 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 1029 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
1029 DCHECK(context_); | 1030 DCHECK(context_); |
1030 return context_->weak_factory.GetWeakPtr(); | 1031 return context_->weak_factory.GetWeakPtr(); |
1031 } | 1032 } |
1032 | 1033 |
1033 } // namespace content | 1034 } // namespace content |
OLD | NEW |