Commit cad04d74 authored by Devlin Cronin's avatar Devlin Cronin Committed by Commit Bot

[Extensions Cleanup] Combine ExtensionHostQueue, SerialExtensionHostQueue

SerialExtensionHostQueue is now the only implementation of
ExtensionHostQueue. Combine them into a de-virtualized
ExtensionHostQueue.

TBR=halliwell@chromium.org (trivial //chromecast change)

Bug: 1028334
Change-Id: I214596d57ccc1edbd6ba4e9ece266b7845baa954
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1934265
Commit-Queue: Devlin <rdevlin.cronin@chromium.org>
Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#718919}
parent a9e22f8e
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
#include "components/performance_manager/performance_manager_tab_helper.h" #include "components/performance_manager/performance_manager_tab_helper.h"
#include "components/performance_manager/public/performance_manager.h" #include "components/performance_manager/public/performance_manager.h"
#include "extensions/browser/extension_host.h" #include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_host_queue.h"
#include "extensions/browser/extension_system.h" #include "extensions/browser/extension_system.h"
#include "extensions/browser/serial_extension_host_queue.h"
namespace extensions { namespace extensions {
...@@ -90,7 +90,7 @@ bool ChromeExtensionHostDelegate::CheckMediaAccessPermission( ...@@ -90,7 +90,7 @@ bool ChromeExtensionHostDelegate::CheckMediaAccessPermission(
} }
ExtensionHostQueue* ChromeExtensionHostDelegate::GetExtensionHostQueue() const { ExtensionHostQueue* ChromeExtensionHostDelegate::GetExtensionHostQueue() const {
static base::NoDestructor<SerialExtensionHostQueue> queue; static base::NoDestructor<ExtensionHostQueue> queue;
return queue.get(); return queue.get();
} }
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "chromecast/browser/extensions/cast_extension_web_contents_observer.h" #include "chromecast/browser/extensions/cast_extension_web_contents_observer.h"
#include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_delegate.h"
#include "extensions/browser/extension_host_queue.h"
#include "extensions/browser/media_capture_util.h" #include "extensions/browser/media_capture_util.h"
#include "extensions/browser/serial_extension_host_queue.h"
namespace extensions { namespace extensions {
...@@ -59,7 +59,7 @@ bool CastExtensionHostDelegate::CheckMediaAccessPermission( ...@@ -59,7 +59,7 @@ bool CastExtensionHostDelegate::CheckMediaAccessPermission(
} }
ExtensionHostQueue* CastExtensionHostDelegate::GetExtensionHostQueue() const { ExtensionHostQueue* CastExtensionHostDelegate::GetExtensionHostQueue() const {
static base::NoDestructor<SerialExtensionHostQueue> queue; static base::NoDestructor<ExtensionHostQueue> queue;
return queue.get(); return queue.get();
} }
......
...@@ -146,6 +146,7 @@ jumbo_source_set("browser_sources") { ...@@ -146,6 +146,7 @@ jumbo_source_set("browser_sources") {
"extension_host.h", "extension_host.h",
"extension_host_delegate.h", "extension_host_delegate.h",
"extension_host_observer.h", "extension_host_observer.h",
"extension_host_queue.cc",
"extension_host_queue.h", "extension_host_queue.h",
"extension_icon_image.cc", "extension_icon_image.cc",
"extension_icon_image.h", "extension_icon_image.h",
...@@ -318,8 +319,6 @@ jumbo_source_set("browser_sources") { ...@@ -318,8 +319,6 @@ jumbo_source_set("browser_sources") {
"sandboxed_unpacker.h", "sandboxed_unpacker.h",
"script_executor.cc", "script_executor.cc",
"script_executor.h", "script_executor.h",
"serial_extension_host_queue.cc",
"serial_extension_host_queue.h",
"service_worker/worker_id.cc", "service_worker/worker_id.cc",
"service_worker/worker_id.h", "service_worker/worker_id.h",
"service_worker/worker_id_set.cc", "service_worker/worker_id_set.cc",
......
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "extensions/browser/serial_extension_host_queue.h" #include "extensions/browser/extension_host_queue.h"
#include <algorithm>
#include "base/bind.h" #include "base/bind.h"
#include "base/location.h" #include "base/location.h"
...@@ -20,6 +22,7 @@ namespace { ...@@ -20,6 +22,7 @@ namespace {
// Gets the number of milliseconds to delay between loading ExtensionHosts. By // Gets the number of milliseconds to delay between loading ExtensionHosts. By
// default this is 0, but it can be overridden by field trials. // default this is 0, but it can be overridden by field trials.
int GetDelayMs() { int GetDelayMs() {
// TODO(devlin): I think these field trials are dead. Confirm, and remove.
// A sanity check for the maximum delay, to guard against a bad field trial // A sanity check for the maximum delay, to guard against a bad field trial
// config being pushed that delays loading too much (e.g. using wrong units). // config being pushed that delays loading too much (e.g. using wrong units).
static const int kMaxDelayMs = 30 * 1000; static const int kMaxDelayMs = 30 * 1000;
...@@ -42,34 +45,33 @@ int GetDelayMs() { ...@@ -42,34 +45,33 @@ int GetDelayMs() {
} // namespace } // namespace
SerialExtensionHostQueue::SerialExtensionHostQueue() : pending_create_(false) {} ExtensionHostQueue::ExtensionHostQueue() : pending_create_(false) {}
SerialExtensionHostQueue::~SerialExtensionHostQueue() { ExtensionHostQueue::~ExtensionHostQueue() = default;
}
void SerialExtensionHostQueue::Add(DeferredStartRenderHost* host) { void ExtensionHostQueue::Add(DeferredStartRenderHost* host) {
queue_.push_back(host); queue_.push_back(host);
PostTask(); PostTask();
} }
void SerialExtensionHostQueue::Remove(DeferredStartRenderHost* host) { void ExtensionHostQueue::Remove(DeferredStartRenderHost* host) {
auto it = std::find(queue_.begin(), queue_.end(), host); auto it = std::find(queue_.begin(), queue_.end(), host);
if (it != queue_.end()) if (it != queue_.end())
queue_.erase(it); queue_.erase(it);
} }
void SerialExtensionHostQueue::PostTask() { void ExtensionHostQueue::PostTask() {
if (!pending_create_) { if (!pending_create_) {
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, FROM_HERE,
base::BindOnce(&SerialExtensionHostQueue::ProcessOneHost, base::BindOnce(&ExtensionHostQueue::ProcessOneHost,
ptr_factory_.GetWeakPtr()), ptr_factory_.GetWeakPtr()),
base::TimeDelta::FromMilliseconds(GetDelayMs())); base::TimeDelta::FromMilliseconds(GetDelayMs()));
pending_create_ = true; pending_create_ = true;
} }
} }
void SerialExtensionHostQueue::ProcessOneHost() { void ExtensionHostQueue::ProcessOneHost() {
pending_create_ = false; pending_create_ = false;
if (queue_.empty()) if (queue_.empty())
return; // can happen on shutdown return; // can happen on shutdown
......
...@@ -5,22 +5,48 @@ ...@@ -5,22 +5,48 @@
#ifndef EXTENSIONS_BROWSER_EXTENSION_HOST_QUEUE_H_ #ifndef EXTENSIONS_BROWSER_EXTENSION_HOST_QUEUE_H_
#define EXTENSIONS_BROWSER_EXTENSION_HOST_QUEUE_H_ #define EXTENSIONS_BROWSER_EXTENSION_HOST_QUEUE_H_
namespace extensions { #include <list>
#include "base/memory/weak_ptr.h"
namespace extensions {
class DeferredStartRenderHost; class DeferredStartRenderHost;
// An interface for a queue of ExtensionHosts waiting for initialization. // A queue of ExtensionHosts waiting for initialization. This initializes
// This is used to implement different throttling strategies. // DeferredStartRenderHosts in the order they're Add()ed, with simple rate
// limiting logic that re-posts each task to the UI thread, to avoid clogging it
// for a long period of time.
class ExtensionHostQueue { class ExtensionHostQueue {
public: public:
virtual ~ExtensionHostQueue() {} ExtensionHostQueue();
~ExtensionHostQueue();
ExtensionHostQueue(const ExtensionHostQueue& queue) = delete;
ExtensionHostQueue& operator=(const ExtensionHostQueue& queue) = delete;
// Adds a host to the queue for RenderView creation. // Adds a host to the queue for RenderView creation.
virtual void Add(DeferredStartRenderHost* host) = 0; void Add(DeferredStartRenderHost* host);
// Removes a host from the queue (for example, it may be deleted before // Removes a host from the queue (for example, it may be deleted before
// having a chance to start). // having a chance to start)
virtual void Remove(DeferredStartRenderHost* host) = 0; void Remove(DeferredStartRenderHost* host);
private:
// Queues up a delayed task to process the next DeferredStartRenderHost in
// the queue.
void PostTask();
// Creates the RenderView for the next host in the queue.
void ProcessOneHost();
// True if this queue is currently in the process of starting an
// DeferredStartRenderHost.
bool pending_create_;
// The list of DeferredStartRenderHosts waiting to be started.
std::list<DeferredStartRenderHost*> queue_;
base::WeakPtrFactory<ExtensionHostQueue> ptr_factory_{this};
}; };
} // namespace extensions } // namespace extensions
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef EXTENSIONS_BROWSER_SERIAL_EXTENSION_HOST_QUEUE_H_
#define EXTENSIONS_BROWSER_SERIAL_EXTENSION_HOST_QUEUE_H_
#include <list>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "extensions/browser/extension_host_queue.h"
namespace extensions {
class DeferredStartRenderHost;
// An ExtensionHostQueue which initializes DeferredStartRenderHosts in the order
// they're Add()ed, with simple rate limiting logic that re-posts each task to
// the UI thread, to avoid clogging it for a long period of time.
class SerialExtensionHostQueue : public ExtensionHostQueue {
public:
SerialExtensionHostQueue();
~SerialExtensionHostQueue() override;
private:
// ExtensionHostQueue:
void Add(DeferredStartRenderHost* host) override;
void Remove(DeferredStartRenderHost* host) override;
// Queues up a delayed task to process the next DeferredStartRenderHost in
// the queue.
void PostTask();
// Creates the RenderView for the next host in the queue.
void ProcessOneHost();
// True if this queue is currently in the process of starting an
// DeferredStartRenderHost.
bool pending_create_;
// The list of DeferredStartRenderHosts waiting to be started.
std::list<DeferredStartRenderHost*> queue_;
base::WeakPtrFactory<SerialExtensionHostQueue> ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(SerialExtensionHostQueue);
};
} // namespace extensions
#endif // EXTENSIONS_BROWSER_SERIAL_EXTENSION_HOST_QUEUE_H_
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/logging.h" #include "base/logging.h"
#include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_delegate.h"
#include "extensions/browser/extension_host_queue.h"
#include "extensions/browser/media_capture_util.h" #include "extensions/browser/media_capture_util.h"
#include "extensions/browser/serial_extension_host_queue.h"
#include "extensions/shell/browser/shell_extension_web_contents_observer.h" #include "extensions/shell/browser/shell_extension_web_contents_observer.h"
namespace extensions { namespace extensions {
...@@ -65,7 +65,7 @@ bool ShellExtensionHostDelegate::CheckMediaAccessPermission( ...@@ -65,7 +65,7 @@ bool ShellExtensionHostDelegate::CheckMediaAccessPermission(
return true; return true;
} }
static base::LazyInstance<SerialExtensionHostQueue>::DestructorAtExit g_queue = static base::LazyInstance<ExtensionHostQueue>::DestructorAtExit g_queue =
LAZY_INSTANCE_INITIALIZER; LAZY_INSTANCE_INITIALIZER;
ExtensionHostQueue* ShellExtensionHostDelegate::GetExtensionHostQueue() const { ExtensionHostQueue* ShellExtensionHostDelegate::GetExtensionHostQueue() const {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment