Chromium Code Reviews| 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 "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 // so that at the time we send it we can be sure that the | 382 // so that at the time we send it we can be sure that the |
| 383 // worker run loop has been started. | 383 // worker run loop has been started. |
| 384 worker_task_runner_->PostTask( | 384 worker_task_runner_->PostTask( |
| 385 FROM_HERE, base::Bind(&ServiceWorkerContextClient::SendWorkerStarted, | 385 FROM_HERE, base::Bind(&ServiceWorkerContextClient::SendWorkerStarted, |
| 386 GetWeakPtr())); | 386 GetWeakPtr())); |
| 387 } | 387 } |
| 388 | 388 |
| 389 void ServiceWorkerContextClient::didInitializeWorkerContext( | 389 void ServiceWorkerContextClient::didInitializeWorkerContext( |
| 390 v8::Local<v8::Context> context, | 390 v8::Local<v8::Context> context, |
| 391 const blink::WebURL& url) { | 391 const blink::WebURL& url) { |
| 392 // TODO(annekao): Remove WebURL parameter from Blink (since url and script_url | 392 // TODO(annekao): Remove WebURL parameter from Blink, it's at best redundant |
| 393 // are equal). Also remove m_documentURL from ServiceWorkerGlobalScopeProxy. | 393 // given |script_url_|, and may be empty in the future. |
| 394 DCHECK_EQ(script_url_, GURL(url)); | 394 // Also remove m_documentURL from ServiceWorkerGlobalScopeProxy. |
|
not at google - send to devlin
2015/08/26 01:17:07
I removed this DCHECK because in order to address
| |
| 395 GetContentClient() | 395 GetContentClient() |
| 396 ->renderer() | 396 ->renderer() |
| 397 ->DidInitializeServiceWorkerContextOnWorkerThread(context, script_url_); | 397 ->DidInitializeServiceWorkerContextOnWorkerThread(context, script_url_); |
| 398 } | 398 } |
| 399 | 399 |
| 400 void ServiceWorkerContextClient::willDestroyWorkerContext() { | 400 void ServiceWorkerContextClient::willDestroyWorkerContext( |
| 401 v8::Local<v8::Context> context) { | |
|
kinuko
2015/08/26 09:04:18
Looking into https://codereview.chromium.org/13108
not at google - send to devlin
2015/08/26 17:29:02
A raw pointer of a v8::Context? How would that hel
kinuko
2015/08/27 00:36:55
I was thinking about using a pointer to 'this', Se
not at google - send to devlin
2015/08/27 15:11:50
I would need to move this into content/public for
| |
| 401 // At this point OnWorkerRunLoopStopped is already called, so | 402 // At this point OnWorkerRunLoopStopped is already called, so |
| 402 // worker_task_runner_->RunsTasksOnCurrentThread() returns false | 403 // worker_task_runner_->RunsTasksOnCurrentThread() returns false |
| 403 // (while we're still on the worker thread). | 404 // (while we're still on the worker thread). |
| 404 proxy_ = NULL; | 405 proxy_ = NULL; |
| 405 | 406 |
| 406 // We have to clear callbacks now, as they need to be freed on the | 407 // We have to clear callbacks now, as they need to be freed on the |
| 407 // same thread. | 408 // same thread. |
| 408 context_.reset(); | 409 context_.reset(); |
| 409 | 410 |
| 410 // This also lets the message filter stop dispatching messages to | 411 // This also lets the message filter stop dispatching messages to |
| 411 // this client. | 412 // this client. |
| 412 g_worker_client_tls.Pointer()->Set(NULL); | 413 g_worker_client_tls.Pointer()->Set(NULL); |
| 413 | 414 |
| 414 GetContentClient()->renderer()->WillDestroyServiceWorkerContextOnWorkerThread( | 415 GetContentClient()->renderer()->WillDestroyServiceWorkerContextOnWorkerThread( |
| 415 script_url_); | 416 context, script_url_); |
| 416 } | 417 } |
| 417 | 418 |
| 418 void ServiceWorkerContextClient::workerContextDestroyed() { | 419 void ServiceWorkerContextClient::workerContextDestroyed() { |
| 419 DCHECK(g_worker_client_tls.Pointer()->Get() == NULL); | 420 DCHECK(g_worker_client_tls.Pointer()->Get() == NULL); |
| 420 | 421 |
| 421 // Now we should be able to free the WebEmbeddedWorker container on the | 422 // Now we should be able to free the WebEmbeddedWorker container on the |
| 422 // main thread. | 423 // main thread. |
| 423 main_thread_task_runner_->PostTask( | 424 main_thread_task_runner_->PostTask( |
| 424 FROM_HERE, | 425 FROM_HERE, |
| 425 base::Bind(&CallWorkerContextDestroyedOnMainThread, | 426 base::Bind(&CallWorkerContextDestroyedOnMainThread, |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 973 } | 974 } |
| 974 | 975 |
| 975 base::WeakPtr<ServiceWorkerContextClient> | 976 base::WeakPtr<ServiceWorkerContextClient> |
| 976 ServiceWorkerContextClient::GetWeakPtr() { | 977 ServiceWorkerContextClient::GetWeakPtr() { |
| 977 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 978 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
| 978 DCHECK(context_); | 979 DCHECK(context_); |
| 979 return context_->weak_factory.GetWeakPtr(); | 980 return context_->weak_factory.GetWeakPtr(); |
| 980 } | 981 } |
| 981 | 982 |
| 982 } // namespace content | 983 } // namespace content |
| OLD | NEW |