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

lacros: Start lacros-chrome if it was running in the last session

Specifically, record a "launch_on_login" pref whenever lacros
successfully starts. Set the pref false when lacros terminates.

Prefs are flushed to disk periodically, so this means the pref is in
the right state even if ash-chrome crashes mid-session.

Bug: 1109050
Change-Id: If7ca21a570b73b56cbbef838cf59526034092b9e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2318648Reviewed-by: default avatarErik Chen <erikchen@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791968}
parent a10038e6
...@@ -25,8 +25,10 @@ ...@@ -25,8 +25,10 @@
#include "chrome/browser/chromeos/crosapi/lacros_loader.h" #include "chrome/browser/chromeos/crosapi/lacros_loader.h"
#include "chrome/browser/chromeos/crosapi/lacros_util.h" #include "chrome/browser/chromeos/crosapi/lacros_util.h"
#include "chrome/browser/component_updater/cros_component_manager.h" #include "chrome/browser/component_updater/cros_component_manager.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chromeos/constants/chromeos_features.h" #include "chromeos/constants/chromeos_features.h"
#include "chromeos/constants/chromeos_switches.h" #include "chromeos/constants/chromeos_switches.h"
#include "components/prefs/pref_service.h"
#include "components/session_manager/core/session_manager.h" #include "components/session_manager/core/session_manager.h"
#include "google_apis/google_api_keys.h" #include "google_apis/google_api_keys.h"
#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/pending_remote.h"
...@@ -76,6 +78,16 @@ void TerminateLacrosChrome(base::Process process) { ...@@ -76,6 +78,16 @@ void TerminateLacrosChrome(base::Process process) {
LOG_IF(ERROR, !success) << "Failed to terminate the lacros-chrome."; LOG_IF(ERROR, !success) << "Failed to terminate the lacros-chrome.";
} }
void SetLaunchOnLoginPref(bool launch_on_login) {
ProfileManager::GetPrimaryUserProfile()->GetPrefs()->SetBoolean(
lacros_util::kLaunchOnLoginPref, launch_on_login);
}
bool GetLaunchOnLoginPref() {
return ProfileManager::GetPrimaryUserProfile()->GetPrefs()->GetBoolean(
lacros_util::kLaunchOnLoginPref);
}
} // namespace } // namespace
// static // static
...@@ -240,6 +252,10 @@ void LacrosManager::OnAshChromeServiceReceiverReceived( ...@@ -240,6 +252,10 @@ void LacrosManager::OnAshChromeServiceReceiverReceived(
ash_chrome_service_ = ash_chrome_service_ =
std::make_unique<AshChromeServiceImpl>(std::move(pending_receiver)); std::make_unique<AshChromeServiceImpl>(std::move(pending_receiver));
state_ = State::RUNNING; state_ = State::RUNNING;
// Set the launch-on-login pref every time lacros-chrome successfully starts,
// instead of once during ash-chrome shutdown, so we have the right value
// even if ash-chrome crashes.
SetLaunchOnLoginPref(true);
LOG(WARNING) << "Connection to lacros-chrome is established."; LOG(WARNING) << "Connection to lacros-chrome is established.";
} }
...@@ -262,6 +278,9 @@ void LacrosManager::OnLacrosChromeTerminated() { ...@@ -262,6 +278,9 @@ void LacrosManager::OnLacrosChromeTerminated() {
DCHECK_EQ(state_, State::TERMINATING); DCHECK_EQ(state_, State::TERMINATING);
LOG(WARNING) << "Lacros-chrome is terminated"; LOG(WARNING) << "Lacros-chrome is terminated";
state_ = State::STOPPED; state_ = State::STOPPED;
// TODO(https://crbug.com/1109366): Restart lacros-chrome if it exits
// abnormally (e.g. crashes). For now, assume the user meant to close it.
SetLaunchOnLoginPref(false);
} }
void LacrosManager::OnUserSessionStarted(bool is_primary_user) { void LacrosManager::OnUserSessionStarted(bool is_primary_user) {
...@@ -299,4 +318,8 @@ void LacrosManager::OnLoadComplete(const base::FilePath& path) { ...@@ -299,4 +318,8 @@ void LacrosManager::OnLoadComplete(const base::FilePath& path) {
const bool success = !path.empty(); const bool success = !path.empty();
std::move(load_complete_callback_).Run(success); std::move(load_complete_callback_).Run(success);
} }
if (state_ == State::STOPPED && GetLaunchOnLoginPref()) {
Start();
}
} }
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/system/sys_info.h" #include "base/system/sys_info.h"
#include "chrome/common/channel_info.h" #include "chrome/common/channel_info.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
#include "components/prefs/pref_registry_simple.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"
...@@ -42,6 +43,12 @@ bool IsUserTypeAllowed(const User* user) { ...@@ -42,6 +43,12 @@ bool IsUserTypeAllowed(const User* user) {
} // namespace } // namespace
const char kLaunchOnLoginPref[] = "lacros.launch_on_login";
void RegisterProfilePrefs(PrefRegistrySimple* registry) {
registry->RegisterBooleanPref(kLaunchOnLoginPref, /*default_value=*/false);
}
base::FilePath GetUserDataDir() { base::FilePath GetUserDataDir() {
base::FilePath base_path; base::FilePath base_path;
if (base::SysInfo::IsRunningOnChromeOS()) { if (base::SysInfo::IsRunningOnChromeOS()) {
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_CHROMEOS_CROSAPI_LACROS_UTIL_H_ #ifndef CHROME_BROWSER_CHROMEOS_CROSAPI_LACROS_UTIL_H_
#define CHROME_BROWSER_CHROMEOS_CROSAPI_LACROS_UTIL_H_ #define CHROME_BROWSER_CHROMEOS_CROSAPI_LACROS_UTIL_H_
class PrefRegistrySimple;
namespace base { namespace base {
class FilePath; class FilePath;
} // namespace base } // namespace base
...@@ -15,6 +17,12 @@ enum class Channel; ...@@ -15,6 +17,12 @@ enum class Channel;
namespace lacros_util { namespace lacros_util {
// Boolean preference. Whether to launch lacros-chrome on login.
extern const char kLaunchOnLoginPref[];
// Registers user profile preferences related to the lacros-chrome binary.
void RegisterProfilePrefs(PrefRegistrySimple* registry);
// Returns the user directory for lacros-chrome. // Returns the user directory for lacros-chrome.
base::FilePath GetUserDataDir(); base::FilePath GetUserDataDir();
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "chrome/browser/chromeos/accessibility/magnification_manager.h" #include "chrome/browser/chromeos/accessibility/magnification_manager.h"
#include "chrome/browser/chromeos/base/locale_util.h" #include "chrome/browser/chromeos/base/locale_util.h"
#include "chrome/browser/chromeos/child_accounts/parent_access_code/parent_access_service.h" #include "chrome/browser/chromeos/child_accounts/parent_access_code/parent_access_service.h"
#include "chrome/browser/chromeos/crosapi/lacros_util.h"
#include "chrome/browser/chromeos/drive/file_system_util.h" #include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/chromeos/first_run/help_app_first_run_field_trial.h" #include "chrome/browser/chromeos/first_run/help_app_first_run_field_trial.h"
#include "chrome/browser/chromeos/input_method/input_method_syncer.h" #include "chrome/browser/chromeos/input_method/input_method_syncer.h"
...@@ -182,6 +183,7 @@ void Preferences::RegisterProfilePrefs( ...@@ -182,6 +183,7 @@ void Preferences::RegisterProfilePrefs(
// Some classes register their own prefs. // Some classes register their own prefs.
TurnSyncOnHelper::RegisterProfilePrefs(registry); TurnSyncOnHelper::RegisterProfilePrefs(registry);
input_method::InputMethodSyncer::RegisterProfilePrefs(registry); input_method::InputMethodSyncer::RegisterProfilePrefs(registry);
lacros_util::RegisterProfilePrefs(registry);
std::string hardware_keyboard_id; std::string hardware_keyboard_id;
// TODO(yusukes): Remove the runtime hack. // TODO(yusukes): Remove the runtime hack.
......
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