Skip to content

Commit

Permalink
[Extensions] Remove most references to LazyBackgroundTaskQueue.
Browse files Browse the repository at this point in the history
This CL is part of the effort to unify the LazyBackgroundTaskQueue and the ServiceWorkerTaskQueue.

Bug: 915814
TBR: dmazzoni@chromium.org (Removed a header file in accessibility_extension_api.cc)
Change-Id: I067bc70b4ed047a0466d70b7d976e01806e7bf98
Reviewed-on: https://chromium-review.googlesource.com/c/1404577
Commit-Queue: David Bertoni <dbertoni@chromium.org>
Reviewed-by: Ben Wells <benwells@chromium.org>
Reviewed-by: Anand Mistry <amistry@chromium.org>
Reviewed-by: Luke Halliwell <halliwell@chromium.org>
Reviewed-by: Istiaque Ahmed <lazyboy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#622127}
  • Loading branch information
David Bertoni authored and Commit Bot committed Jan 11, 2019
1 parent e1a6276 commit 641e3ce
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 65 deletions.
8 changes: 4 additions & 4 deletions apps/launcher.cc
Expand Up @@ -34,8 +34,8 @@
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/granted_file_entry.h"
#include "extensions/browser/lazy_background_task_queue.h"
#include "extensions/browser/lazy_context_id.h"
#include "extensions/browser/lazy_context_task_queue.h"
#include "extensions/browser/process_manager.h"
#include "extensions/common/api/app_runtime.h"
#include "extensions/common/extension.h"
Expand Down Expand Up @@ -290,11 +290,11 @@ class PlatformAppPathLauncher
// available, or it might be in the process of being unloaded, in which case
// the lazy background task queue is used to load the extension and then
// call back to us.
extensions::LazyBackgroundTaskQueue* const queue =
extensions::LazyBackgroundTaskQueue::Get(context_);
const extensions::LazyContextId context_id(context_, extension_id);
extensions::LazyContextTaskQueue* const queue = context_id.GetTaskQueue();
if (queue->ShouldEnqueueTask(context_, app)) {
queue->AddPendingTask(
extensions::LazyContextId(context_, extension_id),
context_id,
base::Bind(&PlatformAppPathLauncher::GrantAccessToFilesAndLaunch,
this));
return;
Expand Down
Expand Up @@ -27,7 +27,6 @@
#include "content/public/common/service_manager_connection.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/lazy_background_task_queue.h"
#include "extensions/common/error_utils.h"
#include "extensions/common/image_util.h"
#include "extensions/common/manifest_handlers/background_info.h"
Expand Down
8 changes: 4 additions & 4 deletions chrome/browser/chromeos/file_manager/file_browser_handlers.cc
Expand Up @@ -37,8 +37,8 @@
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_util.h"
#include "extensions/browser/lazy_background_task_queue.h"
#include "extensions/browser/lazy_context_id.h"
#include "extensions/browser/lazy_context_task_queue.h"
#include "extensions/common/extension_set.h"
#include "extensions/common/manifest_handlers/background_info.h"
#include "extensions/common/url_pattern.h"
Expand Down Expand Up @@ -350,14 +350,14 @@ void FileBrowserHandlerExecutor::ExecuteFileActionsOnUIThread(
handler_pid, nullptr);
} else {
// We have to wake the handler background page before we proceed.
extensions::LazyBackgroundTaskQueue* queue =
extensions::LazyBackgroundTaskQueue::Get(profile_);
const extensions::LazyContextId context_id(profile_, extension_->id());
extensions::LazyContextTaskQueue* queue = context_id.GetTaskQueue();
if (!queue->ShouldEnqueueTask(profile_, extension_.get())) {
ExecuteDoneOnUIThread(false);
return;
}
queue->AddPendingTask(
extensions::LazyContextId(profile_, extension_->id()),
context_id,
base::BindOnce(
&FileBrowserHandlerExecutor::SetupPermissionsAndDispatchEvent,
weak_ptr_factory_.GetWeakPtr(),
Expand Down
8 changes: 4 additions & 4 deletions chrome/browser/extensions/devtools_util.cc
Expand Up @@ -7,8 +7,8 @@
#include "chrome/browser/devtools/devtools_window.h"
#include "chrome/browser/profiles/profile.h"
#include "extensions/browser/extension_host.h"
#include "extensions/browser/lazy_background_task_queue.h"
#include "extensions/browser/lazy_context_id.h"
#include "extensions/browser/lazy_context_task_queue.h"
#include "extensions/browser/process_manager.h"
#include "extensions/common/extension.h"

Expand All @@ -34,9 +34,9 @@ void InspectBackgroundPage(const Extension* extension, Profile* profile) {
InspectExtensionHost(
std::make_unique<LazyContextTaskQueue::ContextInfo>(host));
} else {
LazyBackgroundTaskQueue::Get(profile)->AddPendingTask(
LazyContextId(profile, extension->id()),
base::BindOnce(&InspectExtensionHost));
const LazyContextId context_id(profile, extension->id());
context_id.GetTaskQueue()->AddPendingTask(
context_id, base::BindOnce(&InspectExtensionHost));
}
}

Expand Down
1 change: 0 additions & 1 deletion chromecast/browser/extensions/cast_extension_system.cc
Expand Up @@ -23,7 +23,6 @@
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/info_map.h"
#include "extensions/browser/lazy_background_task_queue.h"
#include "extensions/browser/notification_types.h"
#include "extensions/browser/null_app_sorting.h"
#include "extensions/browser/process_manager.h"
Expand Down
25 changes: 13 additions & 12 deletions extensions/browser/api/messaging/message_service.cc
Expand Up @@ -38,8 +38,6 @@
#include "extensions/browser/extension_web_contents_observer.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/guest_view/web_view/web_view_guest.h"
#include "extensions/browser/lazy_background_task_queue.h"
#include "extensions/browser/lazy_context_id.h"
#include "extensions/browser/process_manager.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest_constants.h"
Expand Down Expand Up @@ -162,7 +160,6 @@ static content::RenderProcessHost* GetExtensionProcess(

MessageService::MessageService(BrowserContext* context)
: messaging_delegate_(ExtensionsAPIClient::Get()->GetMessagingDelegate()),
lazy_background_task_queue_(LazyBackgroundTaskQueue::Get(context)),
weak_factory_(this) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK_NE(nullptr, messaging_delegate_);
Expand Down Expand Up @@ -635,9 +632,10 @@ void MessageService::ClosePortImpl(const PortId& port_id,
if (it == channels_.end()) {
auto pending = pending_lazy_background_page_channels_.find(channel_id);
if (pending != pending_lazy_background_page_channels_.end()) {
lazy_background_task_queue_->AddPendingTask(
LazyContextId(pending->second.browser_context(),
pending->second.extension_id()),
const LazyContextId context_id(pending->second.browser_context(),
pending->second.extension_id());
context_id.GetTaskQueue()->AddPendingTask(
context_id,
base::BindOnce(&MessageService::PendingLazyBackgroundPageClosePort,
weak_factory_.GetWeakPtr(), port_id, process_id,
routing_id, force_close, error_message));
Expand Down Expand Up @@ -736,9 +734,10 @@ void MessageService::EnqueuePendingMessageForLazyBackgroundLoad(

auto pending = pending_lazy_background_page_channels_.find(channel_id);
if (pending != pending_lazy_background_page_channels_.end()) {
lazy_background_task_queue_->AddPendingTask(
LazyContextId(pending->second.browser_context(),
pending->second.extension_id()),
const LazyContextId context_id(pending->second.browser_context(),
pending->second.extension_id());
context_id.GetTaskQueue()->AddPendingTask(
context_id,
base::BindOnce(&MessageService::PendingLazyBackgroundPagePostMessage,
weak_factory_.GetWeakPtr(), source_port_id, message));
}
Expand Down Expand Up @@ -772,15 +771,17 @@ bool MessageService::MaybeAddPendingLazyBackgroundPageOpenChannelTask(
if (!IncognitoInfo::IsSplitMode(extension))
context = ExtensionsBrowserClient::Get()->GetOriginalContext(context);

if (!lazy_background_task_queue_->ShouldEnqueueTask(context, extension))
const LazyContextId context_id(context, extension->id());
LazyContextTaskQueue* task_queue = context_id.GetTaskQueue();
if (!task_queue->ShouldEnqueueTask(context, extension))
return false;

ChannelId channel_id = (*params)->receiver_port_id.GetChannelId();
pending_lazy_background_page_channels_.insert(std::make_pair(
channel_id, PendingLazyBackgroundPageChannel(context, extension->id())));
int source_id = (*params)->source_process_id;
lazy_background_task_queue_->AddPendingTask(
LazyContextId(context, extension->id()),
task_queue->AddPendingTask(
context_id,
base::BindOnce(&MessageService::PendingLazyBackgroundPageOpenChannel,
weak_factory_.GetWeakPtr(), base::Passed(params),
source_id));
Expand Down
8 changes: 2 additions & 6 deletions extensions/browser/api/messaging/message_service.h
Expand Up @@ -33,7 +33,6 @@ class BrowserContext;
namespace extensions {
class Extension;
class ExtensionHost;
class LazyBackgroundTaskQueue;
class MessagingDelegate;

// This class manages message and event passing between renderer processes.
Expand Down Expand Up @@ -187,7 +186,7 @@ class MessageService : public BrowserContextKeyedAPI,
MessageChannel* channel,
const Message& message);

// Potentially registers a pending task with the LazyBackgroundTaskQueue
// Potentially registers a pending task with the background task queue
// to open a channel. Returns true if a task was queued.
// Takes ownership of |params| if true is returned.
bool MaybeAddPendingLazyBackgroundPageOpenChannelTask(
Expand All @@ -196,7 +195,7 @@ class MessageService : public BrowserContextKeyedAPI,
std::unique_ptr<OpenChannelParams>* params,
const PendingMessagesQueue& pending_messages);

// Callbacks for LazyBackgroundTaskQueue tasks. The queue passes in an
// Callbacks for background task queue tasks. The queue passes in an
// ExtensionHost to its task callbacks, though some of our callbacks don't
// use that argument.
void PendingLazyBackgroundPageOpenChannel(
Expand Down Expand Up @@ -254,9 +253,6 @@ class MessageService : public BrowserContextKeyedAPI,
PendingLazyBackgroundPageChannelMap pending_lazy_background_page_channels_;
MessagePropertyProvider property_provider_;

// Weak pointer. Guaranteed to outlive this class.
LazyBackgroundTaskQueue* lazy_background_task_queue_;

base::WeakPtrFactory<MessageService> weak_factory_;

DISALLOW_COPY_AND_ASSIGN(MessageService);
Expand Down
34 changes: 17 additions & 17 deletions extensions/browser/api/runtime/runtime_api.cc
Expand Up @@ -31,8 +31,8 @@
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extension_util.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/lazy_background_task_queue.h"
#include "extensions/browser/lazy_context_id.h"
#include "extensions/browser/lazy_context_task_queue.h"
#include "extensions/browser/process_manager_factory.h"
#include "extensions/common/api/runtime.h"
#include "extensions/common/error_utils.h"
Expand Down Expand Up @@ -104,7 +104,7 @@ void DispatchOnStartupEventImpl(
const std::string& extension_id,
bool first_call,
std::unique_ptr<LazyContextTaskQueue::ContextInfo> context_info) {
// A NULL ContextInfo from the LazyBackgroundTaskQueue means the page failed
// A NULL ContextInfo from the task callback means the page failed
// to load. Give up.
if (!context_info && !first_call)
return;
Expand All @@ -127,14 +127,15 @@ void DispatchOnStartupEventImpl(
ExtensionRegistry::Get(browser_context)->enabled_extensions().GetByID(
extension_id);
if (extension && BackgroundInfo::HasPersistentBackgroundPage(extension) &&
first_call &&
LazyBackgroundTaskQueue::Get(browser_context)
->ShouldEnqueueTask(browser_context, extension)) {
LazyBackgroundTaskQueue::Get(browser_context)
->AddPendingTask(LazyContextId(browser_context, extension_id),
base::BindOnce(&DispatchOnStartupEventImpl,
browser_context, extension_id, false));
return;
first_call) {
const LazyContextId context_id(browser_context, extension_id);
LazyContextTaskQueue* task_queue = context_id.GetTaskQueue();
if (task_queue->ShouldEnqueueTask(browser_context, extension)) {
task_queue->AddPendingTask(
context_id, base::BindOnce(&DispatchOnStartupEventImpl,
browser_context, extension_id, false));
return;
}
}

std::unique_ptr<base::ListValue> event_args(new base::ListValue());
Expand Down Expand Up @@ -596,13 +597,12 @@ void RuntimeAPI::OnExtensionInstalledAndLoaded(
ExtensionFunction::ResponseAction RuntimeGetBackgroundPageFunction::Run() {
ExtensionHost* host = ProcessManager::Get(browser_context())
->GetBackgroundHostForExtension(extension_id());
if (LazyBackgroundTaskQueue::Get(browser_context())
->ShouldEnqueueTask(browser_context(), extension())) {
LazyBackgroundTaskQueue::Get(browser_context())
->AddPendingTask(
LazyContextId(browser_context(), extension_id()),
base::BindOnce(&RuntimeGetBackgroundPageFunction::OnPageLoaded,
this));
const LazyContextId context_id(browser_context(), extension_id());
LazyContextTaskQueue* task_queue = context_id.GetTaskQueue();
if (task_queue->ShouldEnqueueTask(browser_context(), extension())) {
task_queue->AddPendingTask(
context_id,
base::BindOnce(&RuntimeGetBackgroundPageFunction::OnPageLoaded, this));
} else if (host) {
OnPageLoaded(std::make_unique<LazyContextTaskQueue::ContextInfo>(host));
} else {
Expand Down
2 changes: 0 additions & 2 deletions extensions/browser/events/lazy_event_dispatcher.cc
Expand Up @@ -8,9 +8,7 @@
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/lazy_background_task_queue.h"
#include "extensions/browser/lazy_context_id.h"
#include "extensions/browser/service_worker_task_queue.h"
#include "extensions/common/manifest_handlers/incognito_info.h"

using content::BrowserContext;
Expand Down
8 changes: 3 additions & 5 deletions extensions/browser/extension_registrar.cc
Expand Up @@ -16,8 +16,8 @@
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/lazy_background_task_queue.h"
#include "extensions/browser/lazy_context_id.h"
#include "extensions/browser/lazy_context_task_queue.h"
#include "extensions/browser/notification_types.h"
#include "extensions/browser/process_manager.h"
#include "extensions/browser/renderer_startup_helper.h"
Expand Down Expand Up @@ -521,10 +521,8 @@ void ExtensionRegistrar::MaybeSpinUpLazyBackgroundPage(
return;

// Wake up the event page by posting a dummy task.
LazyBackgroundTaskQueue* queue =
LazyBackgroundTaskQueue::Get(browser_context_);
queue->AddPendingTask(LazyContextId(browser_context_, extension->id()),
base::DoNothing());
const LazyContextId context_id(browser_context_, extension->id());
context_id.GetTaskQueue()->AddPendingTask(context_id, base::DoNothing());
}

} // namespace extensions
8 changes: 4 additions & 4 deletions extensions/browser/guest_view/app_view/app_view_guest.cc
Expand Up @@ -19,8 +19,8 @@
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/guest_view/app_view/app_view_constants.h"
#include "extensions/browser/lazy_background_task_queue.h"
#include "extensions/browser/lazy_context_id.h"
#include "extensions/browser/lazy_context_task_queue.h"
#include "extensions/browser/process_manager.h"
#include "extensions/browser/view_type_utils.h"
#include "extensions/common/api/app_runtime.h"
Expand Down Expand Up @@ -194,11 +194,11 @@ void AppViewGuest::CreateWebContents(const base::DictionaryValue& create_params,
guest_extension, weak_ptr_factory_.GetWeakPtr(),
std::move(callback))));

LazyBackgroundTaskQueue* queue =
LazyBackgroundTaskQueue::Get(browser_context());
const LazyContextId context_id(browser_context(), guest_extension->id());
LazyContextTaskQueue* queue = context_id.GetTaskQueue();
if (queue->ShouldEnqueueTask(browser_context(), guest_extension)) {
queue->AddPendingTask(
LazyContextId(browser_context(), guest_extension->id()),
context_id,
base::BindOnce(&AppViewGuest::LaunchAppAndFireEvent,
weak_ptr_factory_.GetWeakPtr(), data->CreateDeepCopy(),
std::move(callback)));
Expand Down
9 changes: 4 additions & 5 deletions extensions/browser/process_manager.cc
Expand Up @@ -32,8 +32,8 @@
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/lazy_background_task_queue.h"
#include "extensions/browser/lazy_context_id.h"
#include "extensions/browser/lazy_context_task_queue.h"
#include "extensions/browser/notification_types.h"
#include "extensions/browser/process_manager_delegate.h"
#include "extensions/browser/process_manager_factory.h"
Expand Down Expand Up @@ -432,10 +432,9 @@ bool ProcessManager::WakeEventPage(const std::string& extension_id,
// The extension is already awake.
return false;
}
LazyBackgroundTaskQueue* queue =
LazyBackgroundTaskQueue::Get(browser_context_);
queue->AddPendingTask(
LazyContextId(browser_context_, extension_id),
const LazyContextId context_id(browser_context_, extension_id);
context_id.GetTaskQueue()->AddPendingTask(
context_id,
base::BindOnce(&PropagateExtensionWakeResult, std::move(callback)));
return true;
}
Expand Down

0 comments on commit 641e3ce

Please sign in to comment.