Commit 24b29b2f authored by kmarshall's avatar kmarshall Committed by Commit bot

Create interface "EventPageTracker" for checking an extension's

suspend state and waking it up.
Make ProcessManager inherit from EventPageTracker.
Add new WakeExtension method to ProcessManager.

R=kalman@chromium.org,mfoltz@chromium.org
BUG=

Review URL: https://codereview.chromium.org/1096313003

Cr-Commit-Position: refs/heads/master@{#327412}
parent ddc17490
// 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_EVENT_PAGE_TRACKER_H_
#define EXTENSIONS_BROWSER_EVENT_PAGE_TRACKER_H_
#include <string>
#include "base/callback.h"
namespace extensions {
class Extension;
class ExtensionHost;
// Tracks an extension's event page suspend state.
class EventPageTracker {
public:
// Returns true if an extension's event page is active,
// or false if it is suspended.
virtual bool IsEventPageSuspended(const std::string& extension_id) = 0;
// Wakes an extension's event page from a suspended state and calls
// |callback| after it is reactivated.
//
// |callback| will be passed true if the extension was reactivated
// successfully, or false if an error occurred.
//
// Returns true if a wake operation was scheduled successfully,
// or false if the event page was already awake.
// Callback will be run asynchronously if true, and never run if false.
virtual bool WakeEventPage(const std::string& extension_id,
const base::Callback<void(bool)>& callback) = 0;
};
} // namespace extensions
#endif // EXTENSIONS_BROWSER_EVENT_PAGE_TRACKER_H_
......@@ -4,6 +4,8 @@
#include "extensions/browser/process_manager.h"
#include <vector>
#include "base/bind.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
......@@ -23,6 +25,7 @@
#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/notification_types.h"
#include "extensions/browser/process_manager_delegate.h"
#include "extensions/browser/process_manager_factory.h"
......@@ -107,6 +110,11 @@ static void CreateBackgroundHostForExtensionLoad(
BackgroundInfo::GetBackgroundURL(extension));
}
void PropagateExtensionWakeResult(const base::Callback<void(bool)>& callback,
extensions::ExtensionHost* host) {
callback.Run(host != nullptr);
}
} // namespace
struct ProcessManager::BackgroundPageData {
......@@ -406,6 +414,23 @@ ExtensionHost* ProcessManager::GetBackgroundHostForExtension(
return nullptr;
}
bool ProcessManager::IsEventPageSuspended(const std::string& extension_id) {
return GetBackgroundHostForExtension(extension_id) == nullptr;
}
bool ProcessManager::WakeEventPage(const std::string& extension_id,
const base::Callback<void(bool)>& callback) {
if (GetBackgroundHostForExtension(extension_id)) {
// Run the callback immediately if the extension is already awake.
return false;
}
LazyBackgroundTaskQueue* queue =
ExtensionSystem::Get(browser_context_)->lazy_background_task_queue();
queue->AddPendingTask(browser_context_, extension_id,
base::Bind(&PropagateExtensionWakeResult, callback));
return true;
}
bool ProcessManager::IsBackgroundHostClosing(const std::string& extension_id) {
ExtensionHost* host = GetBackgroundHostForExtension(extension_id);
return (host && background_page_data_[extension_id].is_closing);
......
......@@ -17,6 +17,7 @@
#include "components/keyed_service/core/keyed_service.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "extensions/browser/event_page_tracker.h"
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/common/extension.h"
#include "extensions/common/view_type.h"
......@@ -43,7 +44,8 @@ class ProcessManagerObserver;
// track of split-mode extensions only.
class ProcessManager : public KeyedService,
public content::NotificationObserver,
public ExtensionRegistryObserver {
public ExtensionRegistryObserver,
public EventPageTracker {
public:
using ExtensionHostSet = std::set<extensions::ExtensionHost*>;
......@@ -145,6 +147,11 @@ class ProcessManager : public KeyedService,
void SetKeepaliveImpulseDecrementCallbackForTesting(
const ImpulseCallbackForTesting& callback);
// EventPageTracker implementation.
bool IsEventPageSuspended(const std::string& extension_id) override;
bool WakeEventPage(const std::string& extension_id,
const base::Callback<void(bool)>& callback) override;
// Sets the time in milliseconds that an extension event page can
// be idle before it is shut down; must be > 0.
static void SetEventPageIdleTimeForTesting(unsigned idle_time_msec);
......
......@@ -557,6 +557,7 @@
'browser/error_map.h',
'browser/event_listener_map.cc',
'browser/event_listener_map.h',
'browser/event_page_tracker.h',
'browser/event_router.cc',
'browser/event_router.h',
'browser/extension_error.cc',
......
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