| OLD | NEW |
| 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 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 | 465 |
| 466 response_callback_.Run(response, *results_, GetError(), histogram_value()); | 466 response_callback_.Run(response, *results_, GetError(), histogram_value()); |
| 467 LogUma(success, timer_.Elapsed(), histogram_value_); | 467 LogUma(success, timer_.Elapsed(), histogram_value_); |
| 468 | 468 |
| 469 OnResponded(); | 469 OnResponded(); |
| 470 } | 470 } |
| 471 | 471 |
| 472 UIThreadExtensionFunction::UIThreadExtensionFunction() | 472 UIThreadExtensionFunction::UIThreadExtensionFunction() |
| 473 : context_(nullptr), | 473 : context_(nullptr), |
| 474 render_frame_host_(nullptr), | 474 render_frame_host_(nullptr), |
| 475 is_from_service_worker_(false) {} | 475 service_worker_version_id_(content::kInvalidServiceWorkerVersionId) {} |
| 476 | 476 |
| 477 UIThreadExtensionFunction::~UIThreadExtensionFunction() { | 477 UIThreadExtensionFunction::~UIThreadExtensionFunction() { |
| 478 if (dispatcher() && render_frame_host()) | 478 if (dispatcher() && (render_frame_host() || is_from_service_worker())) { |
| 479 dispatcher()->OnExtensionFunctionCompleted(extension()); | 479 dispatcher()->OnExtensionFunctionCompleted(extension(), |
| 480 service_worker_version_id_); |
| 481 } |
| 482 |
| 480 // The extension function should always respond to avoid leaks in the | 483 // The extension function should always respond to avoid leaks in the |
| 481 // renderer, dangling callbacks, etc. The exception is if the system is | 484 // renderer, dangling callbacks, etc. The exception is if the system is |
| 482 // shutting down. | 485 // shutting down. |
| 483 // TODO(devlin): Duplicate this check in IOThreadExtensionFunction. It's | 486 // TODO(devlin): Duplicate this check in IOThreadExtensionFunction. It's |
| 484 // tricky because checking IsShuttingDown has to be called from the UI thread. | 487 // tricky because checking IsShuttingDown has to be called from the UI thread. |
| 485 extensions::ExtensionsBrowserClient* browser_client = | 488 extensions::ExtensionsBrowserClient* browser_client = |
| 486 extensions::ExtensionsBrowserClient::Get(); | 489 extensions::ExtensionsBrowserClient::Get(); |
| 487 DCHECK(!browser_client || browser_client->IsShuttingDown() || did_respond_ || | 490 DCHECK(!browser_client || browser_client->IsShuttingDown() || did_respond_ || |
| 488 ignore_all_did_respond_for_testing_do_not_use) | 491 ignore_all_did_respond_for_testing_do_not_use) |
| 489 << name_; | 492 << name_; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 518 return false; | 521 return false; |
| 519 } | 522 } |
| 520 | 523 |
| 521 void UIThreadExtensionFunction::Destruct() const { | 524 void UIThreadExtensionFunction::Destruct() const { |
| 522 BrowserThread::DeleteOnUIThread::Destruct(this); | 525 BrowserThread::DeleteOnUIThread::Destruct(this); |
| 523 } | 526 } |
| 524 | 527 |
| 525 void UIThreadExtensionFunction::SetRenderFrameHost( | 528 void UIThreadExtensionFunction::SetRenderFrameHost( |
| 526 content::RenderFrameHost* render_frame_host) { | 529 content::RenderFrameHost* render_frame_host) { |
| 527 // An extension function from Service Worker does not have a RenderFrameHost. | 530 // An extension function from Service Worker does not have a RenderFrameHost. |
| 528 if (is_from_service_worker_) { | 531 if (is_from_service_worker()) { |
| 529 DCHECK(!render_frame_host); | 532 DCHECK(!render_frame_host); |
| 530 return; | 533 return; |
| 531 } | 534 } |
| 532 | 535 |
| 533 DCHECK_NE(render_frame_host_ == nullptr, render_frame_host == nullptr); | 536 DCHECK_NE(render_frame_host_ == nullptr, render_frame_host == nullptr); |
| 534 render_frame_host_ = render_frame_host; | 537 render_frame_host_ = render_frame_host; |
| 535 tracker_.reset( | 538 tracker_.reset( |
| 536 render_frame_host ? new RenderFrameHostTracker(this) : nullptr); | 539 render_frame_host ? new RenderFrameHostTracker(this) : nullptr); |
| 537 } | 540 } |
| 538 | 541 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 | 610 |
| 608 // static | 611 // static |
| 609 bool AsyncExtensionFunction::ValidationFailure( | 612 bool AsyncExtensionFunction::ValidationFailure( |
| 610 AsyncExtensionFunction* function) { | 613 AsyncExtensionFunction* function) { |
| 611 return false; | 614 return false; |
| 612 } | 615 } |
| 613 | 616 |
| 614 void AsyncExtensionFunction::SendResponse(bool success) { | 617 void AsyncExtensionFunction::SendResponse(bool success) { |
| 615 Respond(success ? ArgumentList(std::move(results_)) : Error(error_)); | 618 Respond(success ? ArgumentList(std::move(results_)) : Error(error_)); |
| 616 } | 619 } |
| OLD | NEW |