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

Side by Side Diff: extensions/browser/extension_function_dispatcher.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: Created 4 years, 5 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_dispatcher.h" 5 #include "extensions/browser/extension_function_dispatcher.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/json/json_string_value_serializer.h" 10 #include "base/json/json_string_value_serializer.h"
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/metrics/histogram_macros.h" 15 #include "base/metrics/histogram_macros.h"
16 #include "base/metrics/sparse_histogram.h" 16 #include "base/metrics/sparse_histogram.h"
17 #include "base/process/process.h" 17 #include "base/process/process.h"
18 #include "base/profiler/scoped_profile.h" 18 #include "base/profiler/scoped_profile.h"
19 #include "base/scoped_observer.h" 19 #include "base/scoped_observer.h"
20 #include "base/values.h" 20 #include "base/values.h"
21 #include "build/build_config.h" 21 #include "build/build_config.h"
22 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
23 #include "content/public/browser/render_frame_host.h" 23 #include "content/public/browser/render_frame_host.h"
24 #include "content/public/browser/render_process_host.h" 24 #include "content/public/browser/render_process_host.h"
25 #include "content/public/browser/render_process_host_observer.h" 25 #include "content/public/browser/render_process_host_observer.h"
26 #include "content/public/browser/render_view_host.h" 26 #include "content/public/browser/render_view_host.h"
27 #include "content/public/browser/service_worker_context.h"
27 #include "content/public/browser/user_metrics.h" 28 #include "content/public/browser/user_metrics.h"
28 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
29 #include "content/public/browser/web_contents_observer.h" 30 #include "content/public/browser/web_contents_observer.h"
30 #include "content/public/common/result_codes.h" 31 #include "content/public/common/result_codes.h"
31 #include "extensions/browser/api_activity_monitor.h" 32 #include "extensions/browser/api_activity_monitor.h"
32 #include "extensions/browser/extension_function_registry.h" 33 #include "extensions/browser/extension_function_registry.h"
33 #include "extensions/browser/extension_registry.h" 34 #include "extensions/browser/extension_registry.h"
34 #include "extensions/browser/extension_system.h" 35 #include "extensions/browser/extension_system.h"
36 #include "extensions/browser/extension_util.h"
35 #include "extensions/browser/extensions_browser_client.h" 37 #include "extensions/browser/extensions_browser_client.h"
36 #include "extensions/browser/io_thread_extension_message_filter.h" 38 #include "extensions/browser/io_thread_extension_message_filter.h"
37 #include "extensions/browser/process_manager.h" 39 #include "extensions/browser/process_manager.h"
38 #include "extensions/browser/process_map.h" 40 #include "extensions/browser/process_map.h"
39 #include "extensions/browser/quota_service.h" 41 #include "extensions/browser/quota_service.h"
40 #include "extensions/common/extension_api.h" 42 #include "extensions/common/extension_api.h"
41 #include "extensions/common/extension_messages.h" 43 #include "extensions/common/extension_messages.h"
42 #include "extensions/common/extension_set.h" 44 #include "extensions/common/extension_set.h"
43 #include "extensions/common/extensions_client.h" 45 #include "extensions/common/extensions_client.h"
44 #include "ipc/ipc_message.h" 46 #include "ipc/ipc_message.h"
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 return; 469 return;
468 470
469 UIThreadExtensionFunction* function_ui = 471 UIThreadExtensionFunction* function_ui =
470 function->AsUIThreadExtensionFunction(); 472 function->AsUIThreadExtensionFunction();
471 if (!function_ui) { 473 if (!function_ui) {
472 NOTREACHED(); 474 NOTREACHED();
473 return; 475 return;
474 } 476 }
475 if (params.embedded_worker_id != -1) { 477 if (params.embedded_worker_id != -1) {
476 function_ui->set_is_from_service_worker(true); 478 function_ui->set_is_from_service_worker(true);
479 function_ui->set_embedded_worker_id(params.embedded_worker_id);
477 } else { 480 } else {
478 function_ui->SetRenderFrameHost(render_frame_host); 481 function_ui->SetRenderFrameHost(render_frame_host);
479 } 482 }
480 function_ui->set_dispatcher(AsWeakPtr()); 483 function_ui->set_dispatcher(AsWeakPtr());
481 function_ui->set_browser_context(browser_context_); 484 function_ui->set_browser_context(browser_context_);
482 if (extension && 485 if (extension &&
483 ExtensionsBrowserClient::Get()->CanExtensionCrossIncognito( 486 ExtensionsBrowserClient::Get()->CanExtensionCrossIncognito(
484 extension, browser_context_)) { 487 extension, browser_context_)) {
485 function->set_include_incognito(true); 488 function->set_include_incognito(true);
486 } 489 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 // Check if extension was uninstalled by management.uninstall. 538 // Check if extension was uninstalled by management.uninstall.
536 if (!registry->enabled_extensions().GetByID(params.extension_id)) 539 if (!registry->enabled_extensions().GetByID(params.extension_id))
537 return; 540 return;
538 541
539 // We only adjust the keepalive count for UIThreadExtensionFunction for 542 // We only adjust the keepalive count for UIThreadExtensionFunction for
540 // now, largely for simplicity's sake. This is OK because currently, only 543 // now, largely for simplicity's sake. This is OK because currently, only
541 // the webRequest API uses IOThreadExtensionFunction, and that API is not 544 // the webRequest API uses IOThreadExtensionFunction, and that API is not
542 // compatible with lazy background pages. 545 // compatible with lazy background pages.
543 // TODO(lazyboy): API functions from extension Service Worker will incorrectly 546 // TODO(lazyboy): API functions from extension Service Worker will incorrectly
544 // change keepalive count below. 547 // change keepalive count below.
545 process_manager->IncrementLazyKeepaliveCount(extension); 548 if (params.embedded_worker_id == -1) {
549 // Increment ref count for non-service worker extension API.
550 process_manager->IncrementLazyKeepaliveCount(extension);
551 } else {
552 // Increment ref count for service worker extension API.
553 LOG(ERROR) << "Increment ref count";
554 content::ServiceWorkerContext::IncrementEmbeddedWorkerRefCount(
555 extensions::util::GetStoragePartitionForExtensionId(params.extension_id,
556 browser_context()),
557 params.embedded_worker_id);
558 }
546 } 559 }
547 560
548 void ExtensionFunctionDispatcher::RemoveWorkerCallbacksForProcess( 561 void ExtensionFunctionDispatcher::RemoveWorkerCallbacksForProcess(
549 int render_process_id) { 562 int render_process_id) {
550 UIThreadWorkerResponseCallbackWrapperMap& map = 563 UIThreadWorkerResponseCallbackWrapperMap& map =
551 ui_thread_response_callback_wrappers_for_worker_; 564 ui_thread_response_callback_wrappers_for_worker_;
552 for (UIThreadWorkerResponseCallbackWrapperMap::iterator it = map.begin(); 565 for (UIThreadWorkerResponseCallbackWrapperMap::iterator it = map.begin();
553 it != map.end();) { 566 it != map.end();) {
554 if (it->first.render_process_id == render_process_id) { 567 if (it->first.render_process_id == render_process_id) {
555 it = map.erase(it); 568 it = map.erase(it);
556 continue; 569 continue;
557 } 570 }
558 ++it; 571 ++it;
559 } 572 }
560 } 573 }
561 574
562 void ExtensionFunctionDispatcher::OnExtensionFunctionCompleted( 575 void ExtensionFunctionDispatcher::OnExtensionFunctionCompleted(
563 const Extension* extension) { 576 const Extension* extension,
564 // TODO(lazyboy): API functions from extension Service Worker will incorrectly 577 int embedded_worker_id) {
565 // change keepalive count below.
566 if (extension) { 578 if (extension) {
567 ProcessManager::Get(browser_context_) 579 if (embedded_worker_id == -1) {
568 ->DecrementLazyKeepaliveCount(extension); 580 // Decrement ref count for non-service worker extension API.
581 ProcessManager::Get(browser_context_)
582 ->DecrementLazyKeepaliveCount(extension);
583 } else {
584 // Decrement ref count for service worker extension API.
585 LOG(ERROR) << "Decrement ref count.";
586 content::ServiceWorkerContext::DecrementEmbeddedWorkerRefCount(
587 extensions::util::GetStoragePartitionForExtensionId(extension->id(),
588 browser_context_),
589 embedded_worker_id);
590 }
569 } 591 }
570 } 592 }
571 593
572 WindowController* 594 WindowController*
573 ExtensionFunctionDispatcher::GetExtensionWindowController() const { 595 ExtensionFunctionDispatcher::GetExtensionWindowController() const {
574 return delegate_ ? delegate_->GetExtensionWindowController() : nullptr; 596 return delegate_ ? delegate_->GetExtensionWindowController() : nullptr;
575 } 597 }
576 598
577 content::WebContents* 599 content::WebContents*
578 ExtensionFunctionDispatcher::GetAssociatedWebContents() const { 600 ExtensionFunctionDispatcher::GetAssociatedWebContents() const {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 // static 656 // static
635 void ExtensionFunctionDispatcher::SendAccessDenied( 657 void ExtensionFunctionDispatcher::SendAccessDenied(
636 const ExtensionFunction::ResponseCallback& callback, 658 const ExtensionFunction::ResponseCallback& callback,
637 functions::HistogramValue histogram_value) { 659 functions::HistogramValue histogram_value) {
638 base::ListValue empty_list; 660 base::ListValue empty_list;
639 callback.Run(ExtensionFunction::FAILED, empty_list, 661 callback.Run(ExtensionFunction::FAILED, empty_list,
640 "Access to extension API denied.", histogram_value); 662 "Access to extension API denied.", histogram_value);
641 } 663 }
642 664
643 } // namespace extensions 665 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698