Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: content/renderer/service_worker/service_worker_context_client.cc

Issue 2166523003: Add ref count to service workers for extension API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments from Devlin + MichaelN Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 worker_task_runner_->PostTask( 448 worker_task_runner_->PostTask(
449 FROM_HERE, base::Bind(&ServiceWorkerContextClient::SendWorkerStarted, 449 FROM_HERE, base::Bind(&ServiceWorkerContextClient::SendWorkerStarted,
450 GetWeakPtr())); 450 GetWeakPtr()));
451 } 451 }
452 452
453 void ServiceWorkerContextClient::didInitializeWorkerContext( 453 void ServiceWorkerContextClient::didInitializeWorkerContext(
454 v8::Local<v8::Context> context) { 454 v8::Local<v8::Context> context) {
455 GetContentClient() 455 GetContentClient()
456 ->renderer() 456 ->renderer()
457 ->DidInitializeServiceWorkerContextOnWorkerThread( 457 ->DidInitializeServiceWorkerContextOnWorkerThread(
458 context, embedded_worker_id_, script_url_); 458 context, service_worker_version_id_, script_url_);
459 } 459 }
460 460
461 void ServiceWorkerContextClient::willDestroyWorkerContext( 461 void ServiceWorkerContextClient::willDestroyWorkerContext(
462 v8::Local<v8::Context> context) { 462 v8::Local<v8::Context> context) {
463 // At this point WillStopCurrentWorkerThread is already called, so 463 // At this point WillStopCurrentWorkerThread is already called, so
464 // worker_task_runner_->RunsTasksOnCurrentThread() returns false 464 // worker_task_runner_->RunsTasksOnCurrentThread() returns false
465 // (while we're still on the worker thread). 465 // (while we're still on the worker thread).
466 proxy_ = NULL; 466 proxy_ = NULL;
467 467
468 // We have to clear callbacks now, as they need to be freed on the 468 // We have to clear callbacks now, as they need to be freed on the
469 // same thread. 469 // same thread.
470 context_.reset(); 470 context_.reset();
471 471
472 // This also lets the message filter stop dispatching messages to 472 // This also lets the message filter stop dispatching messages to
473 // this client. 473 // this client.
474 g_worker_client_tls.Pointer()->Set(NULL); 474 g_worker_client_tls.Pointer()->Set(NULL);
475 475
476 GetContentClient()->renderer()->WillDestroyServiceWorkerContextOnWorkerThread( 476 GetContentClient()->renderer()->WillDestroyServiceWorkerContextOnWorkerThread(
477 context, embedded_worker_id_, script_url_); 477 context, service_worker_version_id_, script_url_);
478 } 478 }
479 479
480 void ServiceWorkerContextClient::workerContextDestroyed() { 480 void ServiceWorkerContextClient::workerContextDestroyed() {
481 DCHECK(g_worker_client_tls.Pointer()->Get() == NULL); 481 DCHECK(g_worker_client_tls.Pointer()->Get() == NULL);
482 482
483 // Now we should be able to free the WebEmbeddedWorker container on the 483 // Now we should be able to free the WebEmbeddedWorker container on the
484 // main thread. 484 // main thread.
485 main_thread_task_runner_->PostTask( 485 main_thread_task_runner_->PostTask(
486 FROM_HERE, 486 FROM_HERE,
487 base::Bind(&CallWorkerContextDestroyedOnMainThread, 487 base::Bind(&CallWorkerContextDestroyedOnMainThread,
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 } 1104 }
1105 1105
1106 base::WeakPtr<ServiceWorkerContextClient> 1106 base::WeakPtr<ServiceWorkerContextClient>
1107 ServiceWorkerContextClient::GetWeakPtr() { 1107 ServiceWorkerContextClient::GetWeakPtr() {
1108 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); 1108 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread());
1109 DCHECK(context_); 1109 DCHECK(context_);
1110 return context_->weak_factory.GetWeakPtr(); 1110 return context_->weak_factory.GetWeakPtr();
1111 } 1111 }
1112 1112
1113 } // namespace content 1113 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698