Commit ae5759d5 authored by Hidehiko Abe's avatar Hidehiko Abe Committed by Chromium LUCI CQ

Fix LacrosChrome init data passing.

chromeos::ReadStartupData() can be called in the process at most
once, and later calls will fail.
That caused initialization error.

This CL fixes it by removing the call from PolicyLoaderLacros.
Instead, LacrosChromeServiceImpl is instantiated at earlier
timing (the same timing as D-Bus for ash-chrome), so it should be
available on PolicyLoaderLacros use.

Bug: None
Test: Ran locally on DUT. Made sure no error logs.
Change-Id: I606348c2b1db72d237d05d5a485dfa4f0ae4492b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2626670
Auto-Submit: Hidehiko Abe <hidehiko@chromium.org>
Commit-Queue: Ken Rockot <rockot@google.com>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarMaksim Ivanov <emaxx@chromium.org>
Reviewed-by: default avatarIgor <igorcov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843222}
parent f3debc01
...@@ -527,6 +527,9 @@ void ChromeMainDelegate::PostEarlyInitialization(bool is_running_tests) { ...@@ -527,6 +527,9 @@ void ChromeMainDelegate::PostEarlyInitialization(bool is_running_tests) {
// a ChromeNetworkDelegate attached that selectively allows cookies again. // a ChromeNetworkDelegate attached that selectively allows cookies again.
net::URLRequest::SetDefaultCookiePolicyToBlock(); net::URLRequest::SetDefaultCookiePolicyToBlock();
// On Chrome OS, IPC (D-Bus, Crosapi) is required to create the FeatureList,
// which depends on policy from an OS service. So, initialize it at this
// timing.
#if BUILDFLAG(IS_CHROMEOS_ASH) #if BUILDFLAG(IS_CHROMEOS_ASH)
// The feature list depends on BrowserPolicyConnectorChromeOS which depends // The feature list depends on BrowserPolicyConnectorChromeOS which depends
// on DBus, so initialize it here. Some D-Bus clients may depend on feature // on DBus, so initialize it here. Some D-Bus clients may depend on feature
...@@ -534,6 +537,16 @@ void ChromeMainDelegate::PostEarlyInitialization(bool is_running_tests) { ...@@ -534,6 +537,16 @@ void ChromeMainDelegate::PostEarlyInitialization(bool is_running_tests) {
chromeos::InitializeDBus(); chromeos::InitializeDBus();
#endif #endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
// LacrosChromeServiceImpl instance needs the sequence of the main thread,
// and needs to be created earlier than incoming Mojo invitation handling.
// This also needs ThreadPool sequences to post some tasks internally.
// However, the tasks can be suspended until actual start of the ThreadPool
// sequences later.
lacros_chrome_service_ = std::make_unique<chromeos::LacrosChromeServiceImpl>(
std::make_unique<LacrosChromeServiceDelegateImpl>());
#endif
ChromeFeatureListCreator* chrome_feature_list_creator = ChromeFeatureListCreator* chrome_feature_list_creator =
chrome_content_browser_client_->startup_data() chrome_content_browser_client_->startup_data()
->chrome_feature_list_creator(); ->chrome_feature_list_creator();
...@@ -551,13 +564,6 @@ void ChromeMainDelegate::PostEarlyInitialization(bool is_running_tests) { ...@@ -551,13 +564,6 @@ void ChromeMainDelegate::PostEarlyInitialization(bool is_running_tests) {
chromeos::InitializeFeatureListDependentDBus(); chromeos::InitializeFeatureListDependentDBus();
#endif #endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
// LacrosChromeServiceImpl instance is needs the sequence of the main thread,
// and needs to be created earlier than incoming Mojo invitation handling.
lacros_chrome_service_ = std::make_unique<chromeos::LacrosChromeServiceImpl>(
std::make_unique<LacrosChromeServiceDelegateImpl>());
#endif
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
chrome_content_browser_client_->startup_data()->CreateProfilePrefService(); chrome_content_browser_client_->startup_data()->CreateProfilePrefService();
net::NetworkChangeNotifier::SetFactory( net::NetworkChangeNotifier::SetFactory(
......
...@@ -4,20 +4,18 @@ ...@@ -4,20 +4,18 @@
#include "components/policy/core/common/policy_loader_lacros.h" #include "components/policy/core/common/policy_loader_lacros.h"
#include <stddef.h> #include <stdint.h>
#include <algorithm> #include <memory>
#include <set>
#include <string> #include <string>
#include <utility>
#include <vector>
#include "base/bind.h" #include "base/check.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/stl_util.h" #include "base/memory/weak_ptr.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chromeos/lacros/lacros_chrome_service_impl.h" #include "chromeos/lacros/lacros_chrome_service_impl.h"
#include "chromeos/startup/startup.h"
#include "components/policy/core/common/cloud/cloud_policy_validator.h" #include "components/policy/core/common/cloud/cloud_policy_validator.h"
#include "components/policy/core/common/policy_bundle.h" #include "components/policy/core/common/policy_bundle.h"
#include "components/policy/core/common/policy_proto_decoders.h" #include "components/policy/core/common/policy_proto_decoders.h"
...@@ -38,37 +36,16 @@ void PolicyLoaderLacros::InitOnBackgroundThread() { ...@@ -38,37 +36,16 @@ void PolicyLoaderLacros::InitOnBackgroundThread() {
std::unique_ptr<PolicyBundle> PolicyLoaderLacros::Load() { std::unique_ptr<PolicyBundle> PolicyLoaderLacros::Load() {
std::unique_ptr<PolicyBundle> bundle = std::make_unique<PolicyBundle>(); std::unique_ptr<PolicyBundle> bundle = std::make_unique<PolicyBundle>();
crosapi::mojom::LacrosInitParamsPtr result;
const crosapi::mojom::LacrosInitParams* init_params;
auto* lacros_chrome_service = chromeos::LacrosChromeServiceImpl::Get(); auto* lacros_chrome_service = chromeos::LacrosChromeServiceImpl::Get();
if (lacros_chrome_service) { if (!lacros_chrome_service) {
init_params = lacros_chrome_service->init_params(); // LacrosChromeService should be available at this timing in production.
} else { // However, in some existing tests, it is not.
// On the first start of Lacros browser, the lacros_chrome_service is // TODO(crbug.com/1114069): Set up LacrosChromeServiceImpl in tests.
// not initialized yet, so take the data directly from the file. This always LOG(ERROR) << "No LacrosChromeService is found.";
// happens on first start after user login, because policy data is loaded return bundle;
// before the service is initialized. We cannot do other way, since there
// are other dependencies that create a cycle. The in-memory file is used
// to break the cycle. After that, if user reloads the policy the service
// is present.
// TODO(crbug.com/1114069): This code is duplicated in
// LacrosChromeServiceImpl. We could store the data in a static variable
// inside LacrosChromeServiceImpl and make a single static function to call.
base::Optional<std::string> content = chromeos::ReadStartupData();
if (!content) {
LOG(ERROR) << "No content in file for init params";
return bundle;
}
if (!crosapi::mojom::LacrosInitParams::Deserialize(
content->data(), content->size(), &result)) {
LOG(ERROR) << "Failed to parse startup data";
return bundle;
}
init_params = result.get();
} }
const crosapi::mojom::LacrosInitParams* init_params =
lacros_chrome_service->init_params();
if (!init_params) { if (!init_params) {
LOG(ERROR) << "No init params"; LOG(ERROR) << "No init params";
return bundle; return bundle;
......
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