refactor: Convert ProcessSingleton changes to patch (#30594)

* Convert ProcessSingleton changes to patch

* Update patch

* Polish

* Add sandbox check to patch

* Add missing includes

* Fix linking error

* Fix compile error

* Apply PR feedback

* Fix compile fails

* Fix tests

* Remove extra patch

* Update test
This commit is contained in:
Raymond Zhao 2021-09-03 14:16:33 -07:00 committed by GitHub
parent b8372f20a0
commit e6f781f403
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 349 additions and 1621 deletions

View file

@ -38,6 +38,7 @@
#include "net/ssl/ssl_private_key.h"
#include "sandbox/policy/switches.h"
#include "services/network/network_service.h"
#include "shell/app/command_line_args.h"
#include "shell/browser/api/electron_api_menu.h"
#include "shell/browser/api/electron_api_session.h"
#include "shell/browser/api/electron_api_web_contents.h"
@ -511,9 +512,9 @@ int GetPathConstant(const std::string& name) {
bool NotificationCallbackWrapper(
const base::RepeatingCallback<
void(const base::CommandLine::StringVector& command_line,
void(const base::CommandLine& command_line,
const base::FilePath& current_directory)>& callback,
const base::CommandLine::StringVector& cmd,
const base::CommandLine& cmd,
const base::FilePath& cwd) {
// Make sure the callback is called after app gets ready.
if (Browser::Get()->is_ready()) {
@ -1067,9 +1068,9 @@ std::string App::GetLocaleCountryCode() {
return region.size() == 2 ? region : std::string();
}
void App::OnSecondInstance(const base::CommandLine::StringVector& cmd,
void App::OnSecondInstance(const base::CommandLine& cmd,
const base::FilePath& cwd) {
Emit("second-instance", cmd, cwd);
Emit("second-instance", cmd.argv(), cwd);
}
bool App::HasSingleInstanceLock() const {
@ -1082,13 +1083,23 @@ bool App::RequestSingleInstanceLock() {
if (HasSingleInstanceLock())
return true;
std::string program_name = electron::Browser::Get()->GetName();
base::FilePath user_dir;
base::PathService::Get(chrome::DIR_USER_DATA, &user_dir);
auto cb = base::BindRepeating(&App::OnSecondInstance, base::Unretained(this));
#if defined(OS_WIN)
bool app_is_sandboxed =
IsSandboxEnabled(base::CommandLine::ForCurrentProcess());
process_singleton_ = std::make_unique<ProcessSingleton>(
program_name, user_dir, app_is_sandboxed,
base::BindRepeating(NotificationCallbackWrapper, cb));
#else
process_singleton_ = std::make_unique<ProcessSingleton>(
user_dir, base::BindRepeating(NotificationCallbackWrapper, cb));
#endif
switch (process_singleton_->NotifyOtherProcessOrCreate()) {
case ProcessSingleton::NotifyResult::LOCK_ERROR:

View file

@ -188,7 +188,7 @@ class App : public ElectronBrowserClient::Delegate,
void SetDesktopName(const std::string& desktop_name);
std::string GetLocale();
std::string GetLocaleCountryCode();
void OnSecondInstance(const base::CommandLine::StringVector& cmd,
void OnSecondInstance(const base::CommandLine& cmd,
const base::FilePath& cwd);
bool HasSingleInstanceLock() const;
bool RequestSingleInstanceLock();