Get ready to make relauncher cross-platform

This commit is contained in:
Cheng Zhao 2016-06-01 22:04:20 +09:00
Родитель abdcb9d481
Коммит 6df18956cd
6 изменённых файлов: 26 добавлений и 46 удалений

Просмотреть файл

@ -9,6 +9,7 @@
#include "atom/app/atom_content_client.h" #include "atom/app/atom_content_client.h"
#include "atom/browser/atom_browser_client.h" #include "atom/browser/atom_browser_client.h"
#include "atom/browser/relauncher.h"
#include "atom/common/google_api_key.h" #include "atom/common/google_api_key.h"
#include "atom/renderer/atom_renderer_client.h" #include "atom/renderer/atom_renderer_client.h"
#include "atom/utility/atom_content_utility_client.h" #include "atom/utility/atom_content_utility_client.h"
@ -21,17 +22,11 @@
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#if defined(OS_MACOSX)
#include "chrome/browser/mac/relauncher.h"
#endif
namespace atom { namespace atom {
namespace { namespace {
#if defined(OS_MACOSX)
const char* kRelauncherProcess = "relauncher"; const char* kRelauncherProcess = "relauncher";
#endif
bool IsBrowserProcess(base::CommandLine* cmd) { bool IsBrowserProcess(base::CommandLine* cmd) {
std::string process_type = cmd->GetSwitchValueASCII(switches::kProcessType); std::string process_type = cmd->GetSwitchValueASCII(switches::kProcessType);
@ -154,12 +149,11 @@ content::ContentUtilityClient* AtomMainDelegate::CreateContentUtilityClient() {
return utility_client_.get(); return utility_client_.get();
} }
#if defined(OS_MACOSX)
int AtomMainDelegate::RunProcess( int AtomMainDelegate::RunProcess(
const std::string& process_type, const std::string& process_type,
const content::MainFunctionParams& main_function_params) { const content::MainFunctionParams& main_function_params) {
if (process_type == kRelauncherProcess) if (process_type == kRelauncherProcess)
return mac_relauncher::internal::RelauncherMain(main_function_params); return relauncher::RelauncherMain(main_function_params);
else else
return -1; return -1;
} }
@ -172,7 +166,6 @@ bool AtomMainDelegate::DelaySandboxInitialization(
const std::string& process_type) { const std::string& process_type) {
return process_type == kRelauncherProcess; return process_type == kRelauncherProcess;
} }
#endif
std::unique_ptr<brightray::ContentClient> std::unique_ptr<brightray::ContentClient>
AtomMainDelegate::CreateContentClient() { AtomMainDelegate::CreateContentClient() {

Просмотреть файл

@ -24,13 +24,11 @@ class AtomMainDelegate : public brightray::MainDelegate {
content::ContentBrowserClient* CreateContentBrowserClient() override; content::ContentBrowserClient* CreateContentBrowserClient() override;
content::ContentRendererClient* CreateContentRendererClient() override; content::ContentRendererClient* CreateContentRendererClient() override;
content::ContentUtilityClient* CreateContentUtilityClient() override; content::ContentUtilityClient* CreateContentUtilityClient() override;
#if defined(OS_MACOSX)
int RunProcess( int RunProcess(
const std::string& process_type, const std::string& process_type,
const content::MainFunctionParams& main_function_params) override; const content::MainFunctionParams& main_function_params) override;
bool ShouldSendMachPort(const std::string& process_type) override; bool ShouldSendMachPort(const std::string& process_type) override;
bool DelaySandboxInitialization(const std::string& process_type) override; bool DelaySandboxInitialization(const std::string& process_type) override;
#endif
// brightray::MainDelegate: // brightray::MainDelegate:
std::unique_ptr<brightray::ContentClient> CreateContentClient() override; std::unique_ptr<brightray::ContentClient> CreateContentClient() override;

Просмотреть файл

@ -8,13 +8,13 @@
#include "atom/browser/mac/atom_application_delegate.h" #include "atom/browser/mac/atom_application_delegate.h"
#include "atom/browser/mac/dict_util.h" #include "atom/browser/mac/dict_util.h"
#include "atom/browser/native_window.h" #include "atom/browser/native_window.h"
#include "atom/browser/relauncher.h"
#include "atom/browser/window_list.h" #include "atom/browser/window_list.h"
#include "base/mac/bundle_locations.h" #include "base/mac/bundle_locations.h"
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "brightray/common/application_info.h" #include "brightray/common/application_info.h"
#include "brightray/common/mac/main_application_bundle.h" #include "brightray/common/mac/main_application_bundle.h"
#include "chrome/browser/mac/relauncher.h"
#include "net/base/mac/url_conversions.h" #include "net/base/mac/url_conversions.h"
#include "url/gurl.h" #include "url/gurl.h"
@ -26,7 +26,7 @@ void Browser::Relaunch(const std::vector<std::string>& args,
args_with_app.insert( args_with_app.insert(
args_with_app.begin(), args_with_app.begin(),
app.empty() ? brightray::MainApplicationBundlePath().value() : app); app.empty() ? brightray::MainApplicationBundlePath().value() : app);
mac_relauncher::RelaunchApp(args_with_app); relauncher::RelaunchApp(args_with_app);
} }
void Browser::Focus() { void Browser::Focus() {

Просмотреть файл

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/mac/relauncher.h" #include "atom/browser/relauncher.h"
#include <ApplicationServices/ApplicationServices.h> #include <ApplicationServices/ApplicationServices.h>
#include <AvailabilityMacros.h> #include <AvailabilityMacros.h>
@ -33,7 +33,7 @@
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "content/public/common/main_function_params.h" #include "content/public/common/main_function_params.h"
namespace mac_relauncher { namespace relauncher {
namespace { namespace {
@ -171,14 +171,6 @@ bool RelaunchAppWithHelper(const std::string& helper,
return true; return true;
} }
namespace {
// In the relauncher process, performs the necessary synchronization steps
// with the parent by setting up a kqueue to watch for it to exit, writing a
// byte to the pipe, and then waiting for the exit notification on the kqueue.
// If anything fails, this logs a message and returns immediately. In those
// situations, it can be assumed that something went wrong with the parent
// process and the best recovery approach is to attempt relaunch anyway.
void RelauncherSynchronizeWithParent() { void RelauncherSynchronizeWithParent() {
base::ScopedFD relauncher_sync_fd(kRelauncherSyncFD); base::ScopedFD relauncher_sync_fd(kRelauncherSyncFD);
@ -236,10 +228,6 @@ void RelauncherSynchronizeWithParent() {
} }
} }
} // namespace
namespace internal {
int RelauncherMain(const content::MainFunctionParams& main_parameters) { int RelauncherMain(const content::MainFunctionParams& main_parameters) {
// CommandLine rearranges the order of the arguments returned by // CommandLine rearranges the order of the arguments returned by
// main_parameters.argv(), rendering it impossible to determine which // main_parameters.argv(), rendering it impossible to determine which
@ -360,6 +348,4 @@ int RelauncherMain(const content::MainFunctionParams& main_parameters) {
return 0; return 0;
} }
} // namespace internal } // namespace relauncher
} // namespace mac_relauncher

Просмотреть файл

@ -1,11 +1,11 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Copyright (c) 2016 GitHub, Inc.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by the MIT license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_MAC_RELAUNCHER_H_ #ifndef ATOM_BROWSER_RELAUNCHER_H_
#define CHROME_BROWSER_MAC_RELAUNCHER_H_ #define ATOM_BROWSER_RELAUNCHER_H_
// mac_relauncher implements main browser application relaunches on the Mac. // relauncher implements main browser application relaunches across platforms.
// When a browser wants to relaunch itself, it can't simply fork off a new // When a browser wants to relaunch itself, it can't simply fork off a new
// process and exec a new browser from within. That leaves open a window // process and exec a new browser from within. That leaves open a window
// during which two browser applications might be running concurrently. If // during which two browser applications might be running concurrently. If
@ -13,7 +13,7 @@
// especially bad if the user expected the Dock icon to be persistent by // especially bad if the user expected the Dock icon to be persistent by
// choosing Keep in Dock from the icon's contextual menu. // choosing Keep in Dock from the icon's contextual menu.
// //
// mac_relauncher approaches this problem by introducing an intermediate // relauncher approaches this problem by introducing an intermediate
// process (the "relauncher") in between the original browser ("parent") and // process (the "relauncher") in between the original browser ("parent") and
// replacement browser ("relaunched"). The helper executable is used for the // replacement browser ("relaunched"). The helper executable is used for the
// relauncher process; because it's an LSUIElement, it doesn't get a Dock // relauncher process; because it's an LSUIElement, it doesn't get a Dock
@ -36,7 +36,7 @@ namespace content {
struct MainFunctionParams; struct MainFunctionParams;
} }
namespace mac_relauncher { namespace relauncher {
// Relaunches the application using the helper application associated with the // Relaunches the application using the helper application associated with the
// currently running instance of Chrome in the parent browser process as the // currently running instance of Chrome in the parent browser process as the
@ -64,14 +64,17 @@ bool RelaunchAppWithHelper(const std::string& helper,
const std::vector<std::string>& relauncher_args, const std::vector<std::string>& relauncher_args,
const std::vector<std::string>& args); const std::vector<std::string>& args);
namespace internal { // In the relauncher process, performs the necessary synchronization steps
// with the parent by setting up a kqueue to watch for it to exit, writing a
// byte to the pipe, and then waiting for the exit notification on the kqueue.
// If anything fails, this logs a message and returns immediately. In those
// situations, it can be assumed that something went wrong with the parent
// process and the best recovery approach is to attempt relaunch anyway.
void RelauncherSynchronizeWithParent();
// The entry point from ChromeMain into the relauncher process. This is not a // The entry point from ChromeMain into the relauncher process.
// user API. Don't call it if your name isn't ChromeMain.
int RelauncherMain(const content::MainFunctionParams& main_parameters); int RelauncherMain(const content::MainFunctionParams& main_parameters);
} // namespace internal } // namespace relauncher
} // namespace mac_relauncher #endif // ATOM_BROWSER_RELAUNCHER_H_
#endif // CHROME_BROWSER_MAC_RELAUNCHER_H_

Просмотреть файл

@ -225,6 +225,8 @@
'atom/browser/net/url_request_fetch_job.h', 'atom/browser/net/url_request_fetch_job.h',
'atom/browser/node_debugger.cc', 'atom/browser/node_debugger.cc',
'atom/browser/node_debugger.h', 'atom/browser/node_debugger.h',
'atom/browser/relauncher.cc',
'atom/browser/relauncher.h',
'atom/browser/render_process_preferences.cc', 'atom/browser/render_process_preferences.cc',
'atom/browser/render_process_preferences.h', 'atom/browser/render_process_preferences.h',
'atom/browser/ui/accelerator_util.cc', 'atom/browser/ui/accelerator_util.cc',
@ -420,8 +422,6 @@
'chromium_src/chrome/browser/extensions/global_shortcut_listener_x11.h', 'chromium_src/chrome/browser/extensions/global_shortcut_listener_x11.h',
'chromium_src/chrome/browser/extensions/global_shortcut_listener_win.cc', 'chromium_src/chrome/browser/extensions/global_shortcut_listener_win.cc',
'chromium_src/chrome/browser/extensions/global_shortcut_listener_win.h', 'chromium_src/chrome/browser/extensions/global_shortcut_listener_win.h',
'chromium_src/chrome/browser/mac/relauncher.cc',
'chromium_src/chrome/browser/mac/relauncher.h',
'chromium_src/chrome/browser/media/desktop_media_list.h', 'chromium_src/chrome/browser/media/desktop_media_list.h',
'chromium_src/chrome/browser/media/desktop_media_list_observer.h', 'chromium_src/chrome/browser/media/desktop_media_list_observer.h',
'chromium_src/chrome/browser/media/native_desktop_media_list.cc', 'chromium_src/chrome/browser/media/native_desktop_media_list.cc',