Commit a9bf5603 authored by yoz's avatar yoz Committed by Commit bot

Remove the --event-page-idle-time and --event-page-suspending-time switches.

They were used only in tests, so change those tests to set a global state instead.

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

Cr-Commit-Position: refs/heads/master@{#295642}
parent 5fa52aea
......@@ -18,6 +18,7 @@
#include "extensions/browser/app_window/app_window_contents.h"
#include "extensions/browser/app_window/app_window_registry.h"
#include "extensions/browser/app_window/native_app_window.h"
#include "extensions/browser/process_manager.h"
#include "extensions/common/switches.h"
using content::WebContents;
......@@ -41,8 +42,8 @@ void PlatformAppBrowserTest::SetUpCommandLine(CommandLine* command_line) {
ExtensionBrowserTest::SetUpCommandLine(command_line);
// Make event pages get suspended quicker.
command_line->AppendSwitchASCII(switches::kEventPageIdleTime, "1000");
command_line->AppendSwitchASCII(switches::kEventPageSuspendingTime, "1000");
ProcessManager::SetEventPageIdleTimeForTesting(1000);
ProcessManager::SetEventPageSuspendingTimeForTesting(1000);
}
// static
......
......@@ -199,10 +199,8 @@ void EphemeralAppTestBase::SetUpCommandLine(base::CommandLine* command_line) {
ExtensionBrowserTest::SetUpCommandLine(command_line);
// Make event pages get suspended immediately.
command_line->AppendSwitchASCII(
extensions::switches::kEventPageIdleTime, "10");
command_line->AppendSwitchASCII(
extensions::switches::kEventPageSuspendingTime, "10");
extensions::ProcessManager::SetEventPageIdleTimeForTesting(1);
extensions::ProcessManager::SetEventPageSuspendingTimeForTesting(1);
// Enable ephemeral apps flag.
command_line->AppendSwitch(switches::kEnableEphemeralApps);
......
......@@ -21,6 +21,7 @@
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extension_util.h"
#include "extensions/browser/management_policy.h"
#include "extensions/browser/process_manager.h"
#include "extensions/common/switches.h"
using extensions::Extension;
......@@ -198,10 +199,8 @@ class EphemeralAppLauncherTest : public WebstoreInstallerTest {
WebstoreInstallerTest::SetUpCommandLine(command_line);
// Make event pages get suspended immediately.
command_line->AppendSwitchASCII(extensions::switches::kEventPageIdleTime,
"10");
command_line->AppendSwitchASCII(
extensions::switches::kEventPageSuspendingTime, "10");
extensions::ProcessManager::SetEventPageIdleTimeForTesting(1);
extensions::ProcessManager::SetEventPageSuspendingTimeForTesting(1);
// Enable ephemeral apps flag.
command_line->AppendSwitch(switches::kEnableEphemeralApps);
......
......@@ -12,19 +12,16 @@
#include "extensions/browser/extension_system.h"
#include "extensions/browser/process_manager.h"
#include "extensions/common/extension.h"
#include "extensions/common/switches.h"
#include "extensions/test/result_catcher.h"
class SystemIndicatorApiTest : public ExtensionApiTest {
public:
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
ExtensionApiTest::SetUpCommandLine(command_line);
virtual void SetUpOnMainThread() OVERRIDE {
ExtensionApiTest::SetUpOnMainThread();
// Set shorter delays to prevent test timeouts in tests that need to wait
// for the event page to unload.
command_line->AppendSwitchASCII(
extensions::switches::kEventPageIdleTime, "1000");
command_line->AppendSwitchASCII(
extensions::switches::kEventPageSuspendingTime, "1000");
extensions::ProcessManager::SetEventPageIdleTimeForTesting(1);
extensions::ProcessManager::SetEventPageSuspendingTimeForTesting(1);
}
const extensions::Extension* LoadExtensionAndWait(
......
......@@ -23,6 +23,7 @@
#include "content/public/browser/notification_service.h"
#include "content/public/test/test_notification_tracker.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/process_manager.h"
#include "extensions/common/extension.h"
#include "extensions/common/switches.h"
#include "net/dns/mock_host_resolver.h"
......@@ -128,15 +129,13 @@ class AppBackgroundPageNaClTest : public AppBackgroundPageApiTest {
virtual ~AppBackgroundPageNaClTest() {
}
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
AppBackgroundPageApiTest::SetUpCommandLine(command_line);
virtual void SetUpOnMainThread() OVERRIDE {
AppBackgroundPageApiTest::SetUpOnMainThread();
#if !defined(DISABLE_NACL)
nacl::NaClProcessHost::SetPpapiKeepAliveThrottleForTesting(50);
#endif
command_line->AppendSwitchASCII(
extensions::switches::kEventPageIdleTime, "1000");
command_line->AppendSwitchASCII(
extensions::switches::kEventPageSuspendingTime, "1000");
extensions::ProcessManager::SetEventPageIdleTimeForTesting(1000);
extensions::ProcessManager::SetEventPageSuspendingTimeForTesting(1000);
}
const Extension* extension() { return extension_; }
......@@ -651,4 +650,3 @@ IN_PROC_BROWSER_TEST_F(AppBackgroundPageNaClTest,
idle_impulse_counter.Wait();
#endif
}
......@@ -14,9 +14,9 @@
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/common/context_menu_params.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/process_manager.h"
#include "extensions/browser/test_management_policy.h"
#include "extensions/common/extension_set.h"
#include "extensions/common/switches.h"
#include "net/dns/mock_host_resolver.h"
#include "ui/base/models/menu_model.h"
......@@ -552,13 +552,11 @@ IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, Enabled) {
class ExtensionContextMenuBrowserLazyTest :
public ExtensionContextMenuBrowserTest {
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
ExtensionContextMenuBrowserTest::SetUpCommandLine(command_line);
virtual void SetUpOnMainThread() OVERRIDE {
ExtensionContextMenuBrowserTest::SetUpOnMainThread();
// Set shorter delays to prevent test timeouts.
command_line->AppendSwitchASCII(
extensions::switches::kEventPageIdleTime, "1");
command_line->AppendSwitchASCII(
extensions::switches::kEventPageSuspendingTime, "0");
extensions::ProcessManager::SetEventPageIdleTimeForTesting(1);
extensions::ProcessManager::SetEventPageSuspendingTimeForTesting(0);
}
};
......
......@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/scoped_observer.h"
#include "base/strings/utf_string_conversions.h"
......@@ -29,8 +28,8 @@
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/process_manager.h"
#include "extensions/common/extension.h"
#include "extensions/common/switches.h"
#include "extensions/test/result_catcher.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
......@@ -86,13 +85,11 @@ class LazyBackgroundPageApiTest : public ExtensionApiTest {
LazyBackgroundPageApiTest() {}
virtual ~LazyBackgroundPageApiTest() {}
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
ExtensionApiTest::SetUpCommandLine(command_line);
virtual void SetUpOnMainThread() OVERRIDE {
ExtensionApiTest::SetUpOnMainThread();
// Set shorter delays to prevent test timeouts.
command_line->AppendSwitchASCII(
extensions::switches::kEventPageIdleTime, "1000");
command_line->AppendSwitchASCII(
extensions::switches::kEventPageSuspendingTime, "1000");
extensions::ProcessManager::SetEventPageIdleTimeForTesting(1);
extensions::ProcessManager::SetEventPageSuspendingTimeForTesting(1);
}
// Loads the extension, which temporarily starts the lazy background page
......
......@@ -10,17 +10,14 @@
#include "chrome/browser/ui/browser.h"
#include "extensions/browser/process_manager.h"
#include "extensions/common/extension.h"
#include "extensions/common/switches.h"
class NotificationIdleTest : public ExtensionApiTest {
protected:
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
ExtensionApiTest::SetUpCommandLine(command_line);
virtual void SetUpOnMainThread() OVERRIDE {
ExtensionApiTest::SetUpOnMainThread();
command_line->AppendSwitchASCII(
extensions::switches::kEventPageIdleTime, "1000");
command_line->AppendSwitchASCII(
extensions::switches::kEventPageSuspendingTime, "1000");
extensions::ProcessManager::SetEventPageIdleTimeForTesting(1);
extensions::ProcessManager::SetEventPageSuspendingTimeForTesting(1);
}
const extensions::Extension* LoadExtensionAndWait(
......
......@@ -41,7 +41,6 @@
#include "extensions/common/manifest_handlers/background_info.h"
#include "extensions/common/manifest_handlers/incognito_info.h"
#include "extensions/common/one_shot_event.h"
#include "extensions/common/switches.h"
using content::BrowserContext;
using content::RenderViewHost;
......@@ -58,6 +57,16 @@ namespace extensions {
namespace {
// The time to delay between an extension becoming idle and
// sending a ShouldSuspend message.
// Note: Must be sufficiently larger (e.g. 2x) than
// kKeepaliveThrottleIntervalInSeconds in ppapi/proxy/plugin_globals.
unsigned g_event_page_idle_time_msec = 10000;
// The time to delay between sending a ShouldSuspend message and
// sending a Suspend message.
unsigned g_event_page_suspending_time_msec = 5000;
std::string GetExtensionID(RenderViewHost* render_view_host) {
// This works for both apps and extensions because the site has been
// normalized to the extension URL for hosted apps.
......@@ -267,24 +276,6 @@ ProcessManager::ProcessManager(BrowserContext* context,
registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
content::NotificationService::AllSources());
// Note: event_page_idle_time_ must be sufficiently larger (e.g. 2x) than
// kKeepaliveThrottleIntervalInSeconds in ppapi/proxy/plugin_globals.
event_page_idle_time_ = base::TimeDelta::FromSeconds(10);
unsigned idle_time_msec = 0;
if (base::StringToUint(CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
extensions::switches::kEventPageIdleTime), &idle_time_msec)) {
CHECK_GT(idle_time_msec, 0u); // OnKeepaliveImpulseCheck requires non zero.
event_page_idle_time_ = base::TimeDelta::FromMilliseconds(idle_time_msec);
}
event_page_suspending_time_ = base::TimeDelta::FromSeconds(5);
unsigned suspending_time_msec = 0;
if (base::StringToUint(CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
extensions::switches::kEventPageSuspendingTime),
&suspending_time_msec)) {
event_page_suspending_time_ =
base::TimeDelta::FromMilliseconds(suspending_time_msec);
}
content::DevToolsAgentHost::AddAgentStateCallback(devtools_callback_);
OnKeepaliveImpulseCheck();
......@@ -465,7 +456,7 @@ void ProcessManager::DecrementLazyKeepaliveCount(
weak_ptr_factory_.GetWeakPtr(),
extension_id,
last_background_close_sequence_id_),
event_page_idle_time_);
base::TimeDelta::FromMilliseconds(g_event_page_idle_time_msec));
}
}
......@@ -534,11 +525,12 @@ void ProcessManager::OnKeepaliveFromPlugin(int render_process_id,
}
// DecrementLazyKeepaliveCount is called when no calls to KeepaliveImpulse
// have been made for at least event_page_idle_time_. In the best case an
// have been made for at least g_event_page_idle_time_msec. In the best case an
// impulse was made just before being cleared, and the decrement will occur
// event_page_idle_time_ later, causing a 2 * event_page_idle_time_ total time
// for extension to be shut down based on impulses. Worst case is an impulse
// just after a clear, adding one check cycle and resulting in 3x total time.
// g_event_page_idle_time_msec later, causing a 2 * g_event_page_idle_time_msec
// total time for extension to be shut down based on impulses. Worst case is
// an impulse just after a clear, adding one check cycle and resulting in 3x
// total time.
void ProcessManager::OnKeepaliveImpulseCheck() {
for (BackgroundPageDataMap::iterator i = background_page_data_.begin();
i != background_page_data_.end();
......@@ -563,7 +555,7 @@ void ProcessManager::OnKeepaliveImpulseCheck() {
FROM_HERE,
base::Bind(&ProcessManager::OnKeepaliveImpulseCheck,
weak_ptr_factory_.GetWeakPtr()),
event_page_idle_time_);
base::TimeDelta::FromMilliseconds(g_event_page_idle_time_msec));
}
}
......@@ -608,8 +600,10 @@ void ProcessManager::OnSuspendAck(const std::string& extension_id) {
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::Bind(&ProcessManager::CloseLazyBackgroundPageNow,
weak_ptr_factory_.GetWeakPtr(), extension_id, sequence_id),
event_page_suspending_time_);
weak_ptr_factory_.GetWeakPtr(),
extension_id,
sequence_id),
base::TimeDelta::FromMilliseconds(g_event_page_suspending_time_msec));
}
void ProcessManager::CloseLazyBackgroundPageNow(const std::string& extension_id,
......@@ -677,6 +671,18 @@ void ProcessManager::SetKeepaliveImpulseDecrementCallbackForTesting(
keepalive_impulse_decrement_callback_for_testing_ = callback;
}
// static
void ProcessManager::SetEventPageIdleTimeForTesting(unsigned idle_time_msec) {
CHECK_GT(idle_time_msec, 0u); // OnKeepaliveImpulseCheck requires non zero.
g_event_page_idle_time_msec = idle_time_msec;
}
// static
void ProcessManager::SetEventPageSuspendingTimeForTesting(
unsigned suspending_time_msec) {
g_event_page_suspending_time_msec = suspending_time_msec;
}
void ProcessManager::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
......
......@@ -148,6 +148,16 @@ class ProcessManager : public content::NotificationObserver {
void SetKeepaliveImpulseDecrementCallbackForTesting(
const ImpulseCallbackForTesting& callback);
// 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);
// Sets the time in milliseconds that an extension event page has
// between being notified of its impending unload and that unload
// happening.
static void SetEventPageSuspendingTimeForTesting(
unsigned suspending_time_msec);
// Creates a non-incognito instance for tests. |registry| allows unit tests
// to inject an ExtensionRegistry that is not managed by the usual
// BrowserContextKeyedServiceFactory system.
......@@ -248,14 +258,6 @@ class ProcessManager : public content::NotificationObserver {
BackgroundPageDataMap background_page_data_;
// The time to delay between an extension becoming idle and
// sending a ShouldSuspend message; read from command-line switch.
base::TimeDelta event_page_idle_time_;
// The time to delay between sending a ShouldSuspend message and
// sending a Suspend message; read from command-line switch.
base::TimeDelta event_page_suspending_time_;
// True if we have created the startup set of background hosts.
bool startup_background_hosts_created_;
......
......@@ -60,14 +60,6 @@ const char kEnableOverrideBookmarksUI[] = "enable-override-bookmarks-ui";
// them in the chrome:extensions page.
const char kErrorConsole[] = "error-console";
// The time in milliseconds that an extension event page can be idle before it
// is shut down.
const char kEventPageIdleTime[] = "event-page-idle-time";
// The time in milliseconds that an extension event page has between being
// notified of its impending unload and that unload happening.
const char kEventPageSuspendingTime[] = "event-page-unloading-time";
// Whether to switch to extension action redesign mode (experimental).
const char kExtensionActionRedesign[] = "extension-action-redesign";
......
......@@ -24,8 +24,6 @@ extern const char kEnableExtensionActionRedesign[];
extern const char kEnableMimeHandlerView[];
extern const char kEnableOverrideBookmarksUI[];
extern const char kErrorConsole[];
extern const char kEventPageIdleTime[];
extern const char kEventPageSuspendingTime[];
extern const char kExtensionActionRedesign[];
extern const char kExtensionProcess[];
extern const char kExtensionsOnChromeURLs[];
......
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