| 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 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 // worker run loop has been started. | 400 // worker run loop has been started. |
| 401 worker_task_runner_->PostTask( | 401 worker_task_runner_->PostTask( |
| 402 FROM_HERE, base::Bind(&ServiceWorkerContextClient::SendWorkerStarted, | 402 FROM_HERE, base::Bind(&ServiceWorkerContextClient::SendWorkerStarted, |
| 403 GetWeakPtr())); | 403 GetWeakPtr())); |
| 404 } | 404 } |
| 405 | 405 |
| 406 void ServiceWorkerContextClient::didInitializeWorkerContext( | 406 void ServiceWorkerContextClient::didInitializeWorkerContext( |
| 407 v8::Local<v8::Context> context) { | 407 v8::Local<v8::Context> context) { |
| 408 GetContentClient() | 408 GetContentClient() |
| 409 ->renderer() | 409 ->renderer() |
| 410 ->DidInitializeServiceWorkerContextOnWorkerThread(context, script_url_); | 410 ->DidInitializeServiceWorkerContextOnWorkerThread( |
| 411 context, embedded_worker_id_, script_url_); |
| 411 } | 412 } |
| 412 | 413 |
| 413 void ServiceWorkerContextClient::willDestroyWorkerContext( | 414 void ServiceWorkerContextClient::willDestroyWorkerContext( |
| 414 v8::Local<v8::Context> context) { | 415 v8::Local<v8::Context> context) { |
| 415 // At this point WillStopCurrentWorkerThread is already called, so | 416 // At this point WillStopCurrentWorkerThread is already called, so |
| 416 // worker_task_runner_->RunsTasksOnCurrentThread() returns false | 417 // worker_task_runner_->RunsTasksOnCurrentThread() returns false |
| 417 // (while we're still on the worker thread). | 418 // (while we're still on the worker thread). |
| 418 proxy_ = NULL; | 419 proxy_ = NULL; |
| 419 | 420 |
| 420 // We have to clear callbacks now, as they need to be freed on the | 421 // We have to clear callbacks now, as they need to be freed on the |
| 421 // same thread. | 422 // same thread. |
| 422 context_.reset(); | 423 context_.reset(); |
| 423 | 424 |
| 424 // This also lets the message filter stop dispatching messages to | 425 // This also lets the message filter stop dispatching messages to |
| 425 // this client. | 426 // this client. |
| 426 g_worker_client_tls.Pointer()->Set(NULL); | 427 g_worker_client_tls.Pointer()->Set(NULL); |
| 427 | 428 |
| 428 GetContentClient()->renderer()->WillDestroyServiceWorkerContextOnWorkerThread( | 429 GetContentClient()->renderer()->WillDestroyServiceWorkerContextOnWorkerThread( |
| 429 context, script_url_); | 430 context, embedded_worker_id_, script_url_); |
| 430 } | 431 } |
| 431 | 432 |
| 432 void ServiceWorkerContextClient::workerContextDestroyed() { | 433 void ServiceWorkerContextClient::workerContextDestroyed() { |
| 433 DCHECK(g_worker_client_tls.Pointer()->Get() == NULL); | 434 DCHECK(g_worker_client_tls.Pointer()->Get() == NULL); |
| 434 | 435 |
| 435 // Now we should be able to free the WebEmbeddedWorker container on the | 436 // Now we should be able to free the WebEmbeddedWorker container on the |
| 436 // main thread. | 437 // main thread. |
| 437 main_thread_task_runner_->PostTask( | 438 main_thread_task_runner_->PostTask( |
| 438 FROM_HERE, | 439 FROM_HERE, |
| 439 base::Bind(&CallWorkerContextDestroyedOnMainThread, | 440 base::Bind(&CallWorkerContextDestroyedOnMainThread, |
| (...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1045 } | 1046 } |
| 1046 | 1047 |
| 1047 base::WeakPtr<ServiceWorkerContextClient> | 1048 base::WeakPtr<ServiceWorkerContextClient> |
| 1048 ServiceWorkerContextClient::GetWeakPtr() { | 1049 ServiceWorkerContextClient::GetWeakPtr() { |
| 1049 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 1050 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
| 1050 DCHECK(context_); | 1051 DCHECK(context_); |
| 1051 return context_->weak_factory.GetWeakPtr(); | 1052 return context_->weak_factory.GetWeakPtr(); |
| 1052 } | 1053 } |
| 1053 | 1054 |
| 1054 } // namespace content | 1055 } // namespace content |
| OLD | NEW |