Skip to content

Commit

Permalink
[M124] BrowserManager: Prepare lacros policy observers on each Launch
Browse files Browse the repository at this point in the history
This CL prepares Lacros Policy observers on StarttIfNeeded and
ResumeLaunch explicitly instead of on profile created.

This is a quick fix for the ARC boot bug.

(cherry picked from commit ffb0b9c)

Bug: 329823550, 330659545
Change-Id: Ie7bccb1f14a864b20a1cba2ff042818b1bcf30c2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5377682
Reviewed-by: Hidehiko Abe <hidehiko@chromium.org>
Commit-Queue: Eriko Kurimoto <elkurin@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1276635}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5387504
Commit-Queue: Hidehiko Abe <hidehiko@chromium.org>
Auto-Submit: Eriko Kurimoto <elkurin@chromium.org>
Cr-Commit-Position: refs/branch-heads/6367@{#188}
Cr-Branched-From: d158c6d-refs/heads/main@{#1274542}
  • Loading branch information
elkurin authored and Chromium LUCI CQ committed Mar 25, 2024
1 parent cc514a9 commit 86072a8
Showing 1 changed file with 39 additions and 23 deletions.
62 changes: 39 additions & 23 deletions chrome/browser/ash/crosapi/browser_manager.cc
Expand Up @@ -242,6 +242,41 @@ bool ShouldPrelaunchLacrosAtLoginScreen() {
return true;
}

// TODO(b/330659545): Investigate why we cannot run this inside
// OnUserProfileCreated.
void PrepareLacrosPolicies(BrowserManager* manager) {
const user_manager::User* user =
user_manager::UserManager::Get()->GetPrimaryUser();
if (!user) {
LOG(ERROR) << "No primary user.";
return;
}

// The lifetime of `BrowserManager` is longer than lifetime of various
// classes, for which we register as an observer below. The RemoveObserver
// function is therefore called in various handlers invoked by those classes
// and not in the destructor.
policy::CloudPolicyCore* core =
browser_util::GetCloudPolicyCoreForUser(*user);
if (core) {
core->AddObserver(manager);
if (core->refresh_scheduler()) {
core->refresh_scheduler()->AddObserver(manager);
}

policy::CloudPolicyStore* store = core->store();
if (store && store->policy_fetch_response()) {
store->AddObserver(manager);
}
}

policy::ComponentCloudPolicyService* component_policy_service =
browser_util::GetComponentCloudPolicyServiceForUser(*user);
if (component_policy_service) {
component_policy_service->AddObserver(manager);
}
}

// The delegate keeps track of the most recent lacros-chrome binary version
// loaded by the BrowserLoader.
// It is the single source of truth for what is the most up-to-date launchable
Expand Down Expand Up @@ -566,6 +601,8 @@ void BrowserManager::InitializeAndStartIfNeeded() {
// Ensure this isn't run multiple times.
session_manager::SessionManager::Get()->RemoveObserver(this);

PrepareLacrosPolicies(this);

// Perform the UMA recording for the current Lacros launch mode and migration
// status.
RecordLacrosLaunchModeAndMigrationStatus();
Expand Down Expand Up @@ -1087,29 +1124,6 @@ void BrowserManager::OnUserProfileCreated(const user_manager::User& user) {
return;
}

// The lifetime of `BrowserManager` is longer than lifetime of various
// classes, for which we register as an observer below. The RemoveObserver
// function is therefore called in various handlers invoked by those classes
// and not in the destructor.
policy::CloudPolicyCore* core = browser_util::GetCloudPolicyCoreForUser(user);
if (core) {
core->AddObserver(this);
if (core->refresh_scheduler()) {
core->refresh_scheduler()->AddObserver(this);
}

policy::CloudPolicyStore* store = core->store();
if (store && store->policy_fetch_response()) {
store->AddObserver(this);
}
}

policy::ComponentCloudPolicyService* component_policy_service =
browser_util::GetComponentCloudPolicyServiceForUser(user);
if (component_policy_service) {
component_policy_service->AddObserver(this);
}

// Record data version for primary user profile.
crosapi::browser_util::RecordDataVer(g_browser_process->local_state(),
user.username_hash(),
Expand Down Expand Up @@ -1234,6 +1248,8 @@ void BrowserManager::OnResumeLaunchComplete(
// Lacros launch is unblocked now.
SetState(State::STARTING);

PrepareLacrosPolicies(this);

// Perform the UMA recording for the current Lacros launch mode and migration
// status.
RecordLacrosLaunchModeAndMigrationStatus();
Expand Down

0 comments on commit 86072a8

Please sign in to comment.