revert: add first-instance-ack event to the app.requestSingleInstanceLock()
flow (#34297)
fix: revert "feat: add first-instance-ack event to the `app.requestSingleInstanceLock()` flow"
This commit is contained in:
parent
ff13fa8f0a
commit
38c21b7aca
8 changed files with 400 additions and 862 deletions
|
@ -522,24 +522,21 @@ bool NotificationCallbackWrapper(
|
|||
const base::RepeatingCallback<
|
||||
void(const base::CommandLine& command_line,
|
||||
const base::FilePath& current_directory,
|
||||
const std::vector<uint8_t> additional_data,
|
||||
const ProcessSingleton::NotificationAckCallback& ack_callback)>&
|
||||
callback,
|
||||
const std::vector<const uint8_t> additional_data)>& callback,
|
||||
const base::CommandLine& cmd,
|
||||
const base::FilePath& cwd,
|
||||
const std::vector<uint8_t> additional_data,
|
||||
const ProcessSingleton::NotificationAckCallback& ack_callback) {
|
||||
const std::vector<const uint8_t> additional_data) {
|
||||
// Make sure the callback is called after app gets ready.
|
||||
if (Browser::Get()->is_ready()) {
|
||||
callback.Run(cmd, cwd, std::move(additional_data), ack_callback);
|
||||
callback.Run(cmd, cwd, std::move(additional_data));
|
||||
} else {
|
||||
scoped_refptr<base::SingleThreadTaskRunner> task_runner(
|
||||
base::ThreadTaskRunnerHandle::Get());
|
||||
|
||||
// Make a copy of the span so that the data isn't lost.
|
||||
task_runner->PostTask(
|
||||
FROM_HERE, base::BindOnce(base::IgnoreResult(callback), cmd, cwd,
|
||||
std::move(additional_data), ack_callback));
|
||||
task_runner->PostTask(FROM_HERE,
|
||||
base::BindOnce(base::IgnoreResult(callback), cmd, cwd,
|
||||
std::move(additional_data)));
|
||||
}
|
||||
// ProcessSingleton needs to know whether current process is quiting.
|
||||
return !Browser::Get()->is_shutting_down();
|
||||
|
@ -1084,52 +1081,14 @@ std::string App::GetLocaleCountryCode() {
|
|||
return region.size() == 2 ? region : std::string();
|
||||
}
|
||||
|
||||
void App::OnFirstInstanceAck(
|
||||
const base::span<const uint8_t>* first_instance_data) {
|
||||
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
base::Value data_to_send;
|
||||
if (first_instance_data) {
|
||||
// Don't send back the local directly, because it might be empty.
|
||||
v8::Local<v8::Value> data_local;
|
||||
data_local = DeserializeV8Value(isolate, *first_instance_data);
|
||||
if (!data_local.IsEmpty()) {
|
||||
gin::ConvertFromV8(isolate, data_local, &data_to_send);
|
||||
}
|
||||
}
|
||||
Emit("first-instance-ack", data_to_send);
|
||||
}
|
||||
|
||||
// This function handles the user calling
|
||||
// the callback parameter sent out by the second-instance event.
|
||||
static void AckCallbackWrapper(
|
||||
const ProcessSingleton::NotificationAckCallback& ack_callback,
|
||||
gin::Arguments* args) {
|
||||
blink::CloneableMessage ack_message;
|
||||
args->GetNext(&ack_message);
|
||||
if (!ack_message.encoded_message.empty()) {
|
||||
ack_callback.Run(&ack_message.encoded_message);
|
||||
} else {
|
||||
ack_callback.Run(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void App::OnSecondInstance(
|
||||
const base::CommandLine& cmd,
|
||||
const base::FilePath& cwd,
|
||||
const std::vector<uint8_t> additional_data,
|
||||
const ProcessSingleton::NotificationAckCallback& ack_callback) {
|
||||
void App::OnSecondInstance(const base::CommandLine& cmd,
|
||||
const base::FilePath& cwd,
|
||||
const std::vector<const uint8_t> additional_data) {
|
||||
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
v8::Local<v8::Value> data_value =
|
||||
DeserializeV8Value(isolate, std::move(additional_data));
|
||||
auto cb = base::BindRepeating(&AckCallbackWrapper, ack_callback);
|
||||
bool prevent_default =
|
||||
Emit("second-instance", cmd.argv(), cwd, data_value, cb);
|
||||
if (!prevent_default) {
|
||||
// Call the callback ourselves, and send back nothing.
|
||||
ack_callback.Run(nullptr);
|
||||
}
|
||||
Emit("second-instance", cmd.argv(), cwd, data_value);
|
||||
}
|
||||
|
||||
bool App::HasSingleInstanceLock() const {
|
||||
|
@ -1150,9 +1109,6 @@ bool App::RequestSingleInstanceLock(gin::Arguments* args) {
|
|||
base::CreateDirectoryAndGetError(user_dir, nullptr);
|
||||
|
||||
auto cb = base::BindRepeating(&App::OnSecondInstance, base::Unretained(this));
|
||||
auto wrapped_cb = base::BindRepeating(NotificationCallbackWrapper, cb);
|
||||
auto ack_cb =
|
||||
base::BindRepeating(&App::OnFirstInstanceAck, base::Unretained(this));
|
||||
|
||||
blink::CloneableMessage additional_data_message;
|
||||
args->GetNext(&additional_data_message);
|
||||
|
@ -1161,10 +1117,11 @@ bool App::RequestSingleInstanceLock(gin::Arguments* args) {
|
|||
IsSandboxEnabled(base::CommandLine::ForCurrentProcess());
|
||||
process_singleton_ = std::make_unique<ProcessSingleton>(
|
||||
program_name, user_dir, additional_data_message.encoded_message,
|
||||
app_is_sandboxed, wrapped_cb, ack_cb);
|
||||
app_is_sandboxed, base::BindRepeating(NotificationCallbackWrapper, cb));
|
||||
#else
|
||||
process_singleton_ = std::make_unique<ProcessSingleton>(
|
||||
user_dir, additional_data_message.encoded_message, wrapped_cb, ack_cb);
|
||||
user_dir, additional_data_message.encoded_message,
|
||||
base::BindRepeating(NotificationCallbackWrapper, cb));
|
||||
#endif
|
||||
|
||||
switch (process_singleton_->NotifyOtherProcessOrCreate()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue