Commit bb9c2e17 authored by James Cook's avatar James Cook Committed by Commit Bot

Allow ash-chrome to launch lacros-chrome when running on linux

This allows working on mojo connections without deploying both binaries
to a device.

* Avoid DCHECK when calling lacros_process_.Pid() on a null process
  handle
* Forward ash-chrome's XDG_RUNTIME_DIR because on linux we can't
  write to /run/chrome
* Use a subdir of the ash-chrome user-data-dir instead of a
  hard-coded path

You can now launch lacros-chrome via the shelf icon if you run
ash-chrome like this:
XDG_RUNTIME_DIR=/tmp/ash_chrome_xdg_runtime ./out/Default/chrome --user-data-dir=/tmp/chrome --enable-wayland-server --no-startup-window --login-manager --enable-features=LacrosSupport --lacros-chrome-path=/w/chrome/src/out/LacrosDesktop

Bug: none
Change-Id: I94a5319174b5952cb6605bf2243821e51ae30ebf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2255032
Commit-Queue: James Cook <jamescook@chromium.org>
Reviewed-by: default avatarHidehiko Abe <hidehiko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#780909}
parent 0ed6cd1a
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/task/task_traits.h" #include "base/task/task_traits.h"
...@@ -34,7 +35,7 @@ bool CheckInstalledAndMaybeRemoveUserDirectory( ...@@ -34,7 +35,7 @@ bool CheckInstalledAndMaybeRemoveUserDirectory(
// shuts down during the directory remove, some partially-removed directory // shuts down during the directory remove, some partially-removed directory
// may be kept, and if the user flips the flag in the next time, that // may be kept, and if the user flips the flag in the next time, that
// partially-removed directory could be used. Fix this. // partially-removed directory could be used. Fix this.
base::DeleteFileRecursively(base::FilePath(lacros_util::kUserDataDir)); base::DeleteFileRecursively(lacros_util::GetUserDataDir());
return true; return true;
} }
......
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/environment.h"
#include "base/files/file.h" #include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/metrics/user_metrics.h" #include "base/metrics/user_metrics.h"
...@@ -36,7 +38,7 @@ namespace { ...@@ -36,7 +38,7 @@ namespace {
LacrosManager* g_instance = nullptr; LacrosManager* g_instance = nullptr;
base::FilePath LacrosLogPath() { base::FilePath LacrosLogPath() {
return base::FilePath(lacros_util::kUserDataDir).Append("lacros.log"); return lacros_util::GetUserDataDir().Append("lacros.log");
} }
// TODO(https://crbug.com/1091863): This logic is not robust against the // TODO(https://crbug.com/1091863): This logic is not robust against the
...@@ -82,6 +84,17 @@ bool StartBackground(base::ProcessId pid, const base::FilePath& lacros_path) { ...@@ -82,6 +84,17 @@ bool StartBackground(base::ProcessId pid, const base::FilePath& lacros_path) {
return already_running; return already_running;
} }
std::string GetXdgRuntimeDir() {
// If ash-chrome was given an environment variable, use it.
std::unique_ptr<base::Environment> env = base::Environment::Create();
std::string xdg_runtime_dir;
if (env->GetVar("XDG_RUNTIME_DIR", &xdg_runtime_dir))
return xdg_runtime_dir;
// Otherwise provide the default for Chrome OS devices.
return "/run/chrome";
}
} // namespace } // namespace
// static // static
...@@ -139,9 +152,10 @@ void LacrosManager::Start() { ...@@ -139,9 +152,10 @@ void LacrosManager::Start() {
scoped_refptr<base::SequencedTaskRunner> task_runner = scoped_refptr<base::SequencedTaskRunner> task_runner =
base::ThreadPool::CreateSequencedTaskRunner( base::ThreadPool::CreateSequencedTaskRunner(
{base::MayBlock(), base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}); {base::MayBlock(), base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN});
base::ProcessId pid =
lacros_process_.IsValid() ? lacros_process_.Pid() : base::kNullProcessId;
task_runner->PostTaskAndReplyWithResult( task_runner->PostTaskAndReplyWithResult(
FROM_HERE, FROM_HERE, base::BindOnce(&StartBackground, pid, lacros_path_),
base::BindOnce(&StartBackground, lacros_process_.Pid(), lacros_path_),
base::BindOnce(&LacrosManager::StartForeground, base::BindOnce(&LacrosManager::StartForeground,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
} }
...@@ -154,7 +168,7 @@ void LacrosManager::StartForeground(bool already_running) { ...@@ -154,7 +168,7 @@ void LacrosManager::StartForeground(bool already_running) {
base::LaunchOptions options; base::LaunchOptions options;
options.environment["EGL_PLATFORM"] = "surfaceless"; options.environment["EGL_PLATFORM"] = "surfaceless";
options.environment["XDG_RUNTIME_DIR"] = "/run/chrome"; options.environment["XDG_RUNTIME_DIR"] = GetXdgRuntimeDir();
std::string api_key; std::string api_key;
if (google_apis::HasAPIKeyConfigured()) if (google_apis::HasAPIKeyConfigured())
...@@ -169,14 +183,16 @@ void LacrosManager::StartForeground(bool already_running) { ...@@ -169,14 +183,16 @@ void LacrosManager::StartForeground(bool already_running) {
options.kill_on_parent_death = true; options.kill_on_parent_death = true;
std::vector<std::string> argv = { // Paths are UTF-8 safe on Chrome OS.
chrome_path, std::string user_data_dir = lacros_util::GetUserDataDir().AsUTF8Unsafe();
"--ozone-platform=wayland",
std::string("--user-data-dir=") + lacros_util::kUserDataDir, std::vector<std::string> argv = {chrome_path,
"--enable-gpu-rasterization", "--ozone-platform=wayland",
"--enable-oop-rasterization", "--user-data-dir=" + user_data_dir,
"--lang=en-US", "--enable-gpu-rasterization",
"--enable-crashpad"}; "--enable-oop-rasterization",
"--lang=en-US",
"--enable-crashpad"};
// We assume that if there's a custom chrome path, that this is a developer // We assume that if there's a custom chrome path, that this is a developer
// and they want to enable logging. // and they want to enable logging.
......
...@@ -4,8 +4,11 @@ ...@@ -4,8 +4,11 @@
#include "chrome/browser/chromeos/lacros/lacros_util.h" #include "chrome/browser/chromeos/lacros/lacros_util.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "chrome/common/channel_info.h" #include "chrome/common/channel_info.h"
#include "chrome/common/chrome_paths.h"
#include "components/user_manager/user.h" #include "components/user_manager/user.h"
#include "components/user_manager/user_manager.h" #include "components/user_manager/user_manager.h"
#include "components/user_manager/user_type.h" #include "components/user_manager/user_type.h"
...@@ -38,7 +41,12 @@ bool IsUserTypeAllowed(const User* user) { ...@@ -38,7 +41,12 @@ bool IsUserTypeAllowed(const User* user) {
} // namespace } // namespace
constexpr char kUserDataDir[] = "/home/chronos/user/lacros"; base::FilePath GetUserDataDir() {
// Return a subdirectory "lacros" inside of the ash-chrome user data dir.
base::FilePath path;
base::PathService::Get(chrome::DIR_USER_DATA, &path);
return path.Append("lacros");
}
bool IsLacrosAllowed() { bool IsLacrosAllowed() {
return IsLacrosAllowed(chrome::GetChannel()); return IsLacrosAllowed(chrome::GetChannel());
......
...@@ -5,14 +5,18 @@ ...@@ -5,14 +5,18 @@
#ifndef CHROME_BROWSER_CHROMEOS_LACROS_LACROS_UTIL_H_ #ifndef CHROME_BROWSER_CHROMEOS_LACROS_LACROS_UTIL_H_
#define CHROME_BROWSER_CHROMEOS_LACROS_LACROS_UTIL_H_ #define CHROME_BROWSER_CHROMEOS_LACROS_LACROS_UTIL_H_
namespace base {
class FilePath;
} // namespace base
namespace version_info { namespace version_info {
enum class Channel; enum class Channel;
} // namespace version_info } // namespace version_info
namespace lacros_util { namespace lacros_util {
// Path of the user directory for lacros-chrome. // Returns the user directory for lacros-chrome.
extern const char kUserDataDir[]; base::FilePath GetUserDataDir();
// Returns true if lacros is allowed for the current user type, chrome channel, // Returns true if lacros is allowed for the current user type, chrome channel,
// etc. // etc.
......
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