Commit 2eb8f9b2 authored by Hidehiko Abe's avatar Hidehiko Abe Committed by Commit Bot

Lacros: Introduce NewWindow API.

Lacros-chrome starts to provide a way to open a new window.
This will replace "IPC based on process launching".

The API in lacros-chrome called by ash-chrome should be rare,
but this is one of the exceptional cases.

Bug: 1094106
Test: Ran locally. Manually opened the multiple windows via launcher.
Change-Id: Iba6ccfb7acdc97837d44a176eb4d163524811590
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2280803
Commit-Queue: Hidehiko Abe <hidehiko@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarJorge Lucangeli Obes <jorgelo@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#787667}
parent 16474925
...@@ -4000,6 +4000,8 @@ static_library("browser") { ...@@ -4000,6 +4000,8 @@ static_library("browser") {
sources += [ sources += [
"chrome_browser_main_extra_parts_lacros.cc", "chrome_browser_main_extra_parts_lacros.cc",
"chrome_browser_main_extra_parts_lacros.h", "chrome_browser_main_extra_parts_lacros.h",
"lacros/lacros_chrome_service_delegate_impl.cc",
"lacros/lacros_chrome_service_delegate_impl.h",
"metrics/lacros_metrics_provider.cc", "metrics/lacros_metrics_provider.cc",
"metrics/lacros_metrics_provider.h", "metrics/lacros_metrics_provider.h",
] ]
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chrome/browser/chrome_browser_main_extra_parts_lacros.h" #include "chrome/browser/chrome_browser_main_extra_parts_lacros.h"
#include "chrome/browser/lacros/lacros_chrome_service_delegate_impl.h"
#include "chromeos/lacros/browser/lacros_chrome_service_impl.h" #include "chromeos/lacros/browser/lacros_chrome_service_impl.h"
ChromeBrowserMainExtraPartsLacros::ChromeBrowserMainExtraPartsLacros() = ChromeBrowserMainExtraPartsLacros::ChromeBrowserMainExtraPartsLacros() =
...@@ -13,6 +14,6 @@ ChromeBrowserMainExtraPartsLacros::~ChromeBrowserMainExtraPartsLacros() = ...@@ -13,6 +14,6 @@ ChromeBrowserMainExtraPartsLacros::~ChromeBrowserMainExtraPartsLacros() =
default; default;
void ChromeBrowserMainExtraPartsLacros::PostCreateThreads() { void ChromeBrowserMainExtraPartsLacros::PostCreateThreads() {
lacros_chrome_service_ = lacros_chrome_service_ = std::make_unique<chromeos::LacrosChromeServiceImpl>(
std::make_unique<chromeos::LacrosChromeServiceImpl>(); std::make_unique<LacrosChromeServiceDelegateImpl>());
} }
...@@ -207,11 +207,10 @@ void LacrosManager::StartForeground(bool already_running) { ...@@ -207,11 +207,10 @@ void LacrosManager::StartForeground(bool already_running) {
if (already_running) { if (already_running) {
DCHECK_EQ(state_, State::RUNNING); DCHECK_EQ(state_, State::RUNNING);
DCHECK(lacros_chrome_service_.is_connected());
// If Lacros is already running, then the new call to launch process spawns // If Lacros is already running, then the new call to launch process spawns
// a new window but does not create a lasting process. // a new window but does not create a lasting process.
// TODO(erikchen): we should send a mojo signal to open a new tab rather lacros_chrome_service_->NewWindow(base::DoNothing());
// than going through the start flow again.
base::LaunchProcess(argv, options);
} else { } else {
DCHECK_EQ(state_, State::STARTING); DCHECK_EQ(state_, State::STARTING);
// Set up Mojo channel. // Set up Mojo channel.
...@@ -244,8 +243,8 @@ void LacrosManager::StartForeground(bool already_running) { ...@@ -244,8 +243,8 @@ void LacrosManager::StartForeground(bool already_running) {
base::BindOnce(&LacrosManager::OnAshChromeServiceReceiverReceived, base::BindOnce(&LacrosManager::OnAshChromeServiceReceiverReceived,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
} }
}
LOG(WARNING) << "Launched lacros-chrome with pid " << lacros_process_.Pid(); LOG(WARNING) << "Launched lacros-chrome with pid " << lacros_process_.Pid();
}
} }
void LacrosManager::OnAshChromeServiceReceiverReceived( void LacrosManager::OnAshChromeServiceReceiverReceived(
......
file://chromeos/LACROS_OWNERS
// Copyright 2020 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/lacros/lacros_chrome_service_delegate_impl.h"
#include "base/logging.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser_commands.h"
LacrosChromeServiceDelegateImpl::LacrosChromeServiceDelegateImpl() = default;
LacrosChromeServiceDelegateImpl::~LacrosChromeServiceDelegateImpl() = default;
void LacrosChromeServiceDelegateImpl::NewWindow() {
// TODO(crbug.com/1102815): Find what profile should be used.
Profile* profile = ProfileManager::GetLastUsedProfileAllowedByPolicy();
DCHECK(profile) << "No last used profile is found.";
chrome::NewEmptyWindow(profile);
}
// Copyright 2020 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.
#ifndef CHROME_BROWSER_LACROS_LACROS_CHROME_SERVICE_DELEGATE_IMPL_H_
#define CHROME_BROWSER_LACROS_LACROS_CHROME_SERVICE_DELEGATE_IMPL_H_
#include "chromeos/lacros/browser/lacros_chrome_service_delegate.h"
// Chrome implementation of LacrosChromeServiceDelegate.
class LacrosChromeServiceDelegateImpl
: public chromeos::LacrosChromeServiceDelegate {
public:
LacrosChromeServiceDelegateImpl();
LacrosChromeServiceDelegateImpl(const LacrosChromeServiceDelegateImpl&) =
delete;
LacrosChromeServiceDelegateImpl& operator=(
const LacrosChromeServiceDelegateImpl&) = delete;
~LacrosChromeServiceDelegateImpl() override;
// chromeos::LacrosChromeServiceDelegate:
void NewWindow() override;
};
#endif // CHROME_BROWSER_LACROS_LACROS_CHROME_SERVICE_DELEGATE_IMPL_H_
...@@ -28,4 +28,8 @@ interface LacrosChromeService { ...@@ -28,4 +28,8 @@ interface LacrosChromeService {
// sequentially, when ash-chrome binds the receiver to the service. // sequentially, when ash-chrome binds the receiver to the service.
RequestAshChromeServiceReceiver@0() => ( RequestAshChromeServiceReceiver@0() => (
pending_receiver<AshChromeService> receiver); pending_receiver<AshChromeService> receiver);
// Opens a new window in lacros-chrome with, currently, the last used profile.
// The callback is called on the command execution.
NewWindow@1() => ();
}; };
...@@ -21,6 +21,7 @@ component("browser") { ...@@ -21,6 +21,7 @@ component("browser") {
"//mojo/public/cpp/bindings", "//mojo/public/cpp/bindings",
] ]
sources = [ sources = [
"lacros_chrome_service_delegate.h",
"lacros_chrome_service_impl.cc", "lacros_chrome_service_impl.cc",
"lacros_chrome_service_impl.h", "lacros_chrome_service_impl.h",
] ]
......
// Copyright 2020 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.
#ifndef CHROMEOS_LACROS_BROWSER_LACROS_CHROME_SERVICE_DELEGATE_H_
#define CHROMEOS_LACROS_BROWSER_LACROS_CHROME_SERVICE_DELEGATE_H_
namespace chromeos {
// Interface to inject Chrome dependent behavior into LacrosChromeServiceImpl
// to split the dependency.
class LacrosChromeServiceDelegate {
public:
virtual ~LacrosChromeServiceDelegate() = default;
// Opens a new browser window.
virtual void NewWindow() = 0;
};
} // namespace chromeos
#endif // CHROMEOS_LACROS_BROWSER_LACROS_CHROME_SERVICE_DELEGATE_H_
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <utility> #include <utility>
#include "base/logging.h" #include "base/logging.h"
#include "chromeos/lacros/browser/lacros_chrome_service_delegate.h"
namespace chromeos { namespace chromeos {
namespace { namespace {
...@@ -20,8 +21,10 @@ LacrosChromeServiceImpl* LacrosChromeServiceImpl::Get() { ...@@ -20,8 +21,10 @@ LacrosChromeServiceImpl* LacrosChromeServiceImpl::Get() {
return g_instance; return g_instance;
} }
LacrosChromeServiceImpl::LacrosChromeServiceImpl() LacrosChromeServiceImpl::LacrosChromeServiceImpl(
: pending_ash_chrome_service_receiver_( std::unique_ptr<LacrosChromeServiceDelegate> delegate)
: delegate_(std::move(delegate)),
pending_ash_chrome_service_receiver_(
ash_chrome_service_.BindNewPipeAndPassReceiver()) { ash_chrome_service_.BindNewPipeAndPassReceiver()) {
// Bind remote interfaces in ash-chrome. These remote interfaces can be used // Bind remote interfaces in ash-chrome. These remote interfaces can be used
// immediately. Outgoing calls will be queued. // immediately. Outgoing calls will be queued.
...@@ -54,4 +57,9 @@ void LacrosChromeServiceImpl::RequestAshChromeServiceReceiver( ...@@ -54,4 +57,9 @@ void LacrosChromeServiceImpl::RequestAshChromeServiceReceiver(
std::move(callback).Run(std::move(pending_ash_chrome_service_receiver_)); std::move(callback).Run(std::move(pending_ash_chrome_service_receiver_));
} }
void LacrosChromeServiceImpl::NewWindow(NewWindowCallback callback) {
delegate_->NewWindow();
std::move(callback).Run();
}
} // namespace chromeos } // namespace chromeos
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef CHROMEOS_LACROS_BROWSER_LACROS_CHROME_SERVICE_IMPL_H_ #ifndef CHROMEOS_LACROS_BROWSER_LACROS_CHROME_SERVICE_IMPL_H_
#define CHROMEOS_LACROS_BROWSER_LACROS_CHROME_SERVICE_IMPL_H_ #define CHROMEOS_LACROS_BROWSER_LACROS_CHROME_SERVICE_IMPL_H_
#include <memory>
#include "base/component_export.h" #include "base/component_export.h"
#include "chromeos/crosapi/mojom/crosapi.mojom.h" #include "chromeos/crosapi/mojom/crosapi.mojom.h"
#include "chromeos/crosapi/mojom/screen_manager.mojom.h" #include "chromeos/crosapi/mojom/screen_manager.mojom.h"
...@@ -15,6 +17,8 @@ ...@@ -15,6 +17,8 @@
namespace chromeos { namespace chromeos {
class LacrosChromeServiceDelegate;
// Implements LacrosChromeService, which owns the mojo remote connection to // Implements LacrosChromeService, which owns the mojo remote connection to
// ash-chrome. // ash-chrome.
// This class is not thread safe. It can only be used on the main thread. // This class is not thread safe. It can only be used on the main thread.
...@@ -23,7 +27,8 @@ class COMPONENT_EXPORT(CHROMEOS_LACROS) LacrosChromeServiceImpl ...@@ -23,7 +27,8 @@ class COMPONENT_EXPORT(CHROMEOS_LACROS) LacrosChromeServiceImpl
public: public:
static LacrosChromeServiceImpl* Get(); static LacrosChromeServiceImpl* Get();
LacrosChromeServiceImpl(); explicit LacrosChromeServiceImpl(
std::unique_ptr<LacrosChromeServiceDelegate> delegate);
~LacrosChromeServiceImpl() override; ~LacrosChromeServiceImpl() override;
void BindReceiver( void BindReceiver(
...@@ -39,8 +44,12 @@ class COMPONENT_EXPORT(CHROMEOS_LACROS) LacrosChromeServiceImpl ...@@ -39,8 +44,12 @@ class COMPONENT_EXPORT(CHROMEOS_LACROS) LacrosChromeServiceImpl
// crosapi::mojom::LacrosChromeService: // crosapi::mojom::LacrosChromeService:
void RequestAshChromeServiceReceiver( void RequestAshChromeServiceReceiver(
RequestAshChromeServiceReceiverCallback callback) override; RequestAshChromeServiceReceiverCallback callback) override;
void NewWindow(NewWindowCallback callback) override;
private: private:
// Delegate instance to inject Chrome dependent code.
std::unique_ptr<LacrosChromeServiceDelegate> delegate_;
mojo::Receiver<crosapi::mojom::LacrosChromeService> receiver_{this}; mojo::Receiver<crosapi::mojom::LacrosChromeService> receiver_{this};
// Proxy to AshChromeService in ash-chrome. // Proxy to AshChromeService in ash-chrome.
......
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