Commit 0f48fcb9 authored by zturner@chromium.org's avatar zturner@chromium.org

Have browser process shutdown metro viewer on Metro -> Metro restart.

Metro -> Metro restarts can happen as a result of changing about:flags, or a chrome update.  In order for the metro viewer to exit, it is necessary for the browser to notify the metro viewer that it needs to close itself.  This was happening for Metro -> Desktop restarts, but not for Metro -> Metro restarts.

BUG=332063

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@244330 0039d316-1c4b-4281-b951-d872f2087c98
parent f8197029
......@@ -6,13 +6,27 @@
#include "base/command_line.h"
#include "base/logging.h"
#include "base/prefs/pref_service.h"
#include "base/process/kill.h"
#include "base/win/windows_version.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/first_run/upgrade_util.h"
#include "chrome/browser/first_run/upgrade_util_win.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/metro_viewer/chrome_metro_viewer_process_host_aurawin.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/notification_service.h"
#include "ui/aura/remote_root_window_host_win.h"
BrowserProcessPlatformPart::BrowserProcessPlatformPart() {
if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
// Tell metro viewer to close when we are shutting down.
registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
content::NotificationService::AllSources());
}
}
BrowserProcessPlatformPart::~BrowserProcessPlatformPart() {
......@@ -43,3 +57,27 @@ void BrowserProcessPlatformPart::PlatformSpecificCommandLineProcessing(
}
}
}
void BrowserProcessPlatformPart::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
DCHECK(type == chrome::NOTIFICATION_APP_TERMINATING);
PrefService* pref_service = g_browser_process->local_state();
bool is_relaunch = pref_service->GetBoolean(prefs::kWasRestarted);
if (is_relaunch) {
upgrade_util::RelaunchMode mode =
upgrade_util::RelaunchModeStringToEnum(
pref_service->GetString(prefs::kRelaunchMode));
if (metro_viewer_process_host_.get()) {
if (mode == upgrade_util::RELAUNCH_MODE_DESKTOP) {
// Metro -> Desktop
chrome::ActivateDesktopHelper(chrome::ASH_TERMINATE);
} else {
// Metro -> Metro
aura::HandleMetroExit();
}
}
}
}
......@@ -8,10 +8,13 @@
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/browser_process_platform_part_base.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
class ChromeMetroViewerProcessHost;
class BrowserProcessPlatformPart : public BrowserProcessPlatformPartBase {
class BrowserProcessPlatformPart : public BrowserProcessPlatformPartBase,
public content::NotificationObserver {
public:
BrowserProcessPlatformPart();
virtual ~BrowserProcessPlatformPart();
......@@ -23,11 +26,18 @@ class BrowserProcessPlatformPart : public BrowserProcessPlatformPartBase {
virtual void PlatformSpecificCommandLineProcessing(
const CommandLine& command_line) OVERRIDE;
// content::NotificationObserver method:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
private:
// Hosts the channel for the Windows 8 metro viewer process which runs in
// the ASH environment.
scoped_ptr<ChromeMetroViewerProcessHost> metro_viewer_process_host_;
content::NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(BrowserProcessPlatformPart);
};
......
......@@ -4,14 +4,11 @@
#include "chrome/browser/lifetime/browser_close_manager.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/background/background_mode_manager.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_shutdown.h"
#include "chrome/browser/download/download_service.h"
#include "chrome/browser/download/download_service_factory.h"
#include "chrome/browser/first_run/upgrade_util.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_iterator.h"
......@@ -20,14 +17,8 @@
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/web_contents.h"
#if defined(OS_WIN)
#include "base/win/windows_version.h"
#include "chrome/browser/first_run/upgrade_util_win.h"
#endif
BrowserCloseManager::BrowserCloseManager() : current_browser_(NULL) {}
BrowserCloseManager::~BrowserCloseManager() {}
......@@ -169,17 +160,4 @@ void BrowserCloseManager::CloseBrowsers() {
}
}
}
#if defined(OS_WIN)
if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
PrefService* pref_service = g_browser_process->local_state();
bool is_relaunch = pref_service->GetBoolean(prefs::kWasRestarted);
if (is_relaunch) {
upgrade_util::RelaunchMode mode = upgrade_util::RelaunchModeStringToEnum(
pref_service->GetString(prefs::kRelaunchMode));
if (mode == upgrade_util::RELAUNCH_MODE_DESKTOP)
chrome::ActivateDesktopHelper(chrome::ASH_TERMINATE);
}
}
#endif
}
......@@ -142,6 +142,11 @@ void HandleActivateDesktop(const base::FilePath& shortcut,
ash_exit);
}
void HandleMetroExit() {
DCHECK(aura::RemoteWindowTreeHostWin::Instance());
aura::RemoteWindowTreeHostWin::Instance()->HandleMetroExit();
}
RemoteWindowTreeHostWin* g_instance = NULL;
RemoteWindowTreeHostWin* RemoteWindowTreeHostWin::Instance() {
......@@ -249,6 +254,12 @@ void RemoteWindowTreeHostWin::HandleActivateDesktop(
host_->Send(new MetroViewerHostMsg_ActivateDesktop(shortcut, ash_exit));
}
void RemoteWindowTreeHostWin::HandleMetroExit() {
if (!host_)
return;
host_->Send(new MetroViewerHostMsg_MetroExit());
}
void RemoteWindowTreeHostWin::HandleOpenFile(
const base::string16& title,
const base::FilePath& default_path,
......
......@@ -86,14 +86,17 @@ AURA_EXPORT void HandleSelectFolder(const base::string16& title,
const SelectFolderCompletion& on_success,
const FileSelectionCanceled& on_failure);
// Handles the activate desktop command for Metro Chrome Ash. The on_success
// callback passed in is invoked when activation is completed.
// The |ash_exit| parameter indicates whether the Ash process would be shutdown
// after activating the desktop.
// Handles the activate desktop command for Metro Chrome Ash. The |ash_exit|
// parameter indicates whether the Ash process would be shutdown after
// activating the desktop.
AURA_EXPORT void HandleActivateDesktop(
const base::FilePath& shortcut,
bool ash_exit);
// Handles the metro exit command. Notifies the metro viewer to shutdown
// gracefully.
AURA_EXPORT void HandleMetroExit();
// WindowTreeHost implementaton that receives events from a different
// process. In the case of Windows this is the Windows 8 (aka Metro)
// frontend process, which forwards input events to this class.
......@@ -121,9 +124,10 @@ class AURA_EXPORT RemoteWindowTreeHostWin
// The |ash_exit| parameter indicates whether the Ash process would be
// shutdown after activating the desktop.
void HandleActivateDesktop(
const base::FilePath& shortcut,
bool ash_exit);
void HandleActivateDesktop(const base::FilePath& shortcut, bool ash_exit);
// Notify the metro viewer that it should shut itself down.
void HandleMetroExit();
void HandleOpenFile(const base::string16& title,
const base::FilePath& default_path,
......
......@@ -105,6 +105,9 @@ IPC_MESSAGE_CONTROL2(MetroViewerHostMsg_ActivateDesktop,
base::FilePath /* shortcut */,
bool /* ash exit */);
// Request the viewer to close itself gracefully.
IPC_MESSAGE_CONTROL0(MetroViewerHostMsg_MetroExit);
// Requests the viewer to open a URL in desktop mode.
IPC_MESSAGE_CONTROL2(MetroViewerHostMsg_OpenURLOnDesktop,
base::FilePath, /* shortcut */
......
......@@ -157,6 +157,7 @@ class ChromeChannelListener : public IPC::Listener {
IPC_BEGIN_MESSAGE_MAP(ChromeChannelListener, message)
IPC_MESSAGE_HANDLER(MetroViewerHostMsg_ActivateDesktop,
OnActivateDesktop)
IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MetroExit, OnMetroExit)
IPC_MESSAGE_HANDLER(MetroViewerHostMsg_OpenURLOnDesktop,
OnOpenURLOnDesktop)
IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SetCursor, OnSetCursor)
......@@ -194,6 +195,10 @@ class ChromeChannelListener : public IPC::Listener {
shortcut, ash_exit));
}
void OnMetroExit() {
MetroExit(app_view_->core_window_hwnd());
}
void OnOpenURLOnDesktop(const base::FilePath& shortcut,
const base::string16& url) {
ui_proxy_->PostTask(FROM_HERE,
......
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