Defer shutting down Chrome after the CF automation connection goes away.

BUG=98506
TEST=NONE


Review URL: http://codereview.chromium.org/9570017

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124942 0039d316-1c4b-4281-b951-d872f2087c98
parent 9f76c1e7
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 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.
#include "chrome/browser/automation/chrome_frame_automation_provider.h"
#include <algorithm>
#include "base/command_line.h"
#include "base/string_number_conversions.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/automation_messages.h"
#include "chrome/common/chrome_switches.h"
#include "ipc/ipc_message.h"
#include "ipc/ipc_channel.h"
const int kMaxChromeShutdownDelaySeconds = 60*60;
ChromeFrameAutomationProvider::ChromeFrameAutomationProvider(Profile* profile)
: AutomationProvider(profile) {
DCHECK(g_browser_process);
......@@ -19,8 +27,38 @@ ChromeFrameAutomationProvider::ChromeFrameAutomationProvider(Profile* profile)
ChromeFrameAutomationProvider::~ChromeFrameAutomationProvider() {
DCHECK(g_browser_process);
if (g_browser_process)
g_browser_process->ReleaseModule();
if (g_browser_process) {
CommandLine& cmd_line = *CommandLine::ForCurrentProcess();
CommandLine::StringType shutdown_delay(
cmd_line.GetSwitchValueNative(switches::kChromeFrameShutdownDelay));
if (!shutdown_delay.empty()) {
VLOG(1) << "ChromeFrameAutomationProvider: "
"Scheduling ReleaseBrowserProcess.";
// Grab the specified shutdown delay.
int shutdown_delay_seconds = 0;
base::StringToInt(shutdown_delay, &shutdown_delay_seconds);
// Clamp to reasonable values.
shutdown_delay_seconds = std::max(0, shutdown_delay_seconds);
shutdown_delay_seconds = std::min(shutdown_delay_seconds,
kMaxChromeShutdownDelaySeconds);
// We have Chrome Frame defer Chrome shutdown for a time to improve
// intra-page load times.
// Note that we are tracking the perf impact of this under
// http://crbug.com/98506
MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::Bind(&ChromeFrameAutomationProvider::ReleaseBrowserProcess),
base::TimeDelta::FromSeconds(shutdown_delay_seconds));
} else {
VLOG(1) << "ChromeFrameAutomationProvider: "
"Releasing browser module with no delay.";
g_browser_process->ReleaseModule();
}
}
}
bool ChromeFrameAutomationProvider::OnMessageReceived(
......@@ -86,3 +124,12 @@ bool ChromeFrameAutomationProvider::IsValidMessage(uint32 type) {
return is_valid_message;
}
// static
void ChromeFrameAutomationProvider::ReleaseBrowserProcess() {
if (g_browser_process) {
VLOG(1) << "ChromeFrameAutomationProvider: "
"Releasing browser process.";
g_browser_process->ReleaseModule();
}
}
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 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.
......@@ -34,6 +34,10 @@ class ChromeFrameAutomationProvider : public AutomationProvider {
// Returns true if the message received is a valid chrome frame message.
bool IsValidMessage(uint32 type);
// Called to release an instance's ref count on the global BrowserProcess
// instance.
static void ReleaseBrowserProcess();
private:
DISALLOW_COPY_AND_ASSIGN(ChromeFrameAutomationProvider);
};
......
......@@ -135,6 +135,10 @@ const char kCheckForUpdateIntervalSec[] = "check-for-update-interval";
const char kCheckCloudPrintConnectorPolicy[] =
"check-cloud-print-connector-policy";
// Tells Chrome to delay shutdown (for a specified number of seconds) when a
// Chrome Frame automation channel is closed.
const char kChromeFrameShutdownDelay[] = "chrome-frame-shutdown-delay";
// Tells chrome to load the specified version of chrome.dll on Windows. If this
// version cannot be loaded, Chrome will exit.
const char kChromeVersion[] = "chrome-version";
......
......@@ -51,6 +51,7 @@ extern const char kAutomationClientChannelID[];
extern const char kAutomationReinitializeOnChannelError[];
extern const char kCheckForUpdateIntervalSec[];
extern const char kCheckCloudPrintConnectorPolicy[];
extern const char kChromeFrameShutdownDelay[];
extern const char kChromeVersion[];
extern const char kCipherSuiteBlacklist[];
extern const char kClearTokenService[];
......
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