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