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

Side by Side Diff: extensions/browser/extension_function.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 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 "extensions/browser/extension_function.h" 5 #include "extensions/browser/extension_function.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 443
444 response_callback_.Run(response, *results_, GetError(), histogram_value()); 444 response_callback_.Run(response, *results_, GetError(), histogram_value());
445 LogUma(success, timer_.Elapsed(), histogram_value_); 445 LogUma(success, timer_.Elapsed(), histogram_value_);
446 446
447 OnResponded(); 447 OnResponded();
448 } 448 }
449 449
450 UIThreadExtensionFunction::UIThreadExtensionFunction() 450 UIThreadExtensionFunction::UIThreadExtensionFunction()
451 : context_(nullptr), 451 : context_(nullptr),
452 render_frame_host_(nullptr), 452 render_frame_host_(nullptr),
453 is_from_service_worker_(false) {} 453 service_worker_version_id_(content::kInvalidServiceWorkerVersionId) {}
454 454
455 UIThreadExtensionFunction::~UIThreadExtensionFunction() { 455 UIThreadExtensionFunction::~UIThreadExtensionFunction() {
456 if (dispatcher() && render_frame_host()) 456 if (dispatcher() && (render_frame_host() || is_from_service_worker())) {
457 dispatcher()->OnExtensionFunctionCompleted(extension()); 457 dispatcher()->OnExtensionFunctionCompleted(extension(),
458 is_from_service_worker());
459 }
460
458 // The extension function should always respond to avoid leaks in the 461 // The extension function should always respond to avoid leaks in the
459 // renderer, dangling callbacks, etc. The exception is if the system is 462 // renderer, dangling callbacks, etc. The exception is if the system is
460 // shutting down. 463 // shutting down.
461 // TODO(devlin): Duplicate this check in IOThreadExtensionFunction. It's 464 // TODO(devlin): Duplicate this check in IOThreadExtensionFunction. It's
462 // tricky because checking IsShuttingDown has to be called from the UI thread. 465 // tricky because checking IsShuttingDown has to be called from the UI thread.
463 extensions::ExtensionsBrowserClient* browser_client = 466 extensions::ExtensionsBrowserClient* browser_client =
464 extensions::ExtensionsBrowserClient::Get(); 467 extensions::ExtensionsBrowserClient::Get();
465 DCHECK(!browser_client || browser_client->IsShuttingDown() || did_respond() || 468 DCHECK(!browser_client || browser_client->IsShuttingDown() || did_respond() ||
466 ignore_all_did_respond_for_testing_do_not_use) 469 ignore_all_did_respond_for_testing_do_not_use)
467 << name(); 470 << name();
(...skipping 28 matching lines...) Expand all
496 return false; 499 return false;
497 } 500 }
498 501
499 void UIThreadExtensionFunction::Destruct() const { 502 void UIThreadExtensionFunction::Destruct() const {
500 BrowserThread::DeleteOnUIThread::Destruct(this); 503 BrowserThread::DeleteOnUIThread::Destruct(this);
501 } 504 }
502 505
503 void UIThreadExtensionFunction::SetRenderFrameHost( 506 void UIThreadExtensionFunction::SetRenderFrameHost(
504 content::RenderFrameHost* render_frame_host) { 507 content::RenderFrameHost* render_frame_host) {
505 // An extension function from Service Worker does not have a RenderFrameHost. 508 // An extension function from Service Worker does not have a RenderFrameHost.
506 if (is_from_service_worker_) { 509 if (is_from_service_worker()) {
507 DCHECK(!render_frame_host); 510 DCHECK(!render_frame_host);
508 return; 511 return;
509 } 512 }
510 513
511 DCHECK_NE(render_frame_host_ == nullptr, render_frame_host == nullptr); 514 DCHECK_NE(render_frame_host_ == nullptr, render_frame_host == nullptr);
512 render_frame_host_ = render_frame_host; 515 render_frame_host_ = render_frame_host;
513 tracker_.reset( 516 tracker_.reset(
514 render_frame_host ? new RenderFrameHostTracker(this) : nullptr); 517 render_frame_host ? new RenderFrameHostTracker(this) : nullptr);
515 } 518 }
516 519
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 void AsyncExtensionFunction::SendResponse(bool success) { 616 void AsyncExtensionFunction::SendResponse(bool success) {
614 ResponseValue response; 617 ResponseValue response;
615 if (success) { 618 if (success) {
616 response = ArgumentList(std::move(results_)); 619 response = ArgumentList(std::move(results_));
617 } else { 620 } else {
618 response = results_ ? ErrorWithArguments(std::move(results_), error_) 621 response = results_ ? ErrorWithArguments(std::move(results_), error_)
619 : Error(error_); 622 : Error(error_);
620 } 623 }
621 Respond(std::move(response)); 624 Respond(std::move(response));
622 } 625 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698