0

Clean up usage of the background mode manager

There were some files that includes the background mode manager but
doesn't use that class at all and should be deleted.

In addition, the BackgroundModeManager::IsBackgroundWithoutWindows() is
only used for tab metrics and does not rely on internal background
mode manager state so the implementation is moved in line instead.

Low-Coverage-Reason: TRIVIAL_CHANGE

Bug: 378140958
Change-Id: Ib135c366a92d65536155a4316bc322f458910e22
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6283283
Reviewed-by: Colin Blundell <blundell@chromium.org>
Commit-Queue: Steven Luong <stluong@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1423227}
This commit is contained in:
Steven Luong
2025-02-21 09:47:10 -08:00
committed by Chromium LUCI CQ
parent 782dbb8052
commit 2d97c1abe0
7 changed files with 20 additions and 41 deletions

@ -443,25 +443,6 @@ bool BackgroundModeManager::IsBackgroundModeActive() {
return in_background_mode_;
}
bool BackgroundModeManager::IsBackgroundWithoutWindows() const {
return KeepAliveRegistry::GetInstance()->WouldRestartWithout({
// Transient startup related KeepAlives, not related to any UI.
KeepAliveOrigin::SESSION_RESTORE,
KeepAliveOrigin::BACKGROUND_MODE_MANAGER_STARTUP,
KeepAliveOrigin::BACKGROUND_SYNC,
// Notification KeepAlives are not dependent on the Chrome UI being
// loaded, and can be registered when we were in pure background mode.
// They just block it to avoid issues. Ignore them when determining if we
// are in that mode.
KeepAliveOrigin::NOTIFICATION,
KeepAliveOrigin::PENDING_NOTIFICATION_CLICK_EVENT,
KeepAliveOrigin::PENDING_NOTIFICATION_CLOSE_EVENT,
KeepAliveOrigin::IN_FLIGHT_PUSH_MESSAGE,
});
}
size_t BackgroundModeManager::NumberOfBackgroundModeData() {
return background_mode_data_.size();
}

@ -106,9 +106,6 @@ class BackgroundModeManager : public BrowserListObserver,
// Returns true if background mode is active.
virtual bool IsBackgroundModeActive();
// Returns true if we are in pure background mode, without windows.
bool IsBackgroundWithoutWindows() const;
// Suspends background mode until either ResumeBackgroundMode is called or
// Chrome is restarted. This has the same effect as ending background mode
// for the current browser session.

@ -35,6 +35,8 @@
#include "chrome/browser/ui/ui_features.h"
#include "chrome/common/buildflags.h"
#include "chrome/common/pref_names.h"
#include "components/keep_alive_registry/keep_alive_registry.h"
#include "components/keep_alive_registry/keep_alive_types.h"
#include "components/metrics/daily_event.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
@ -45,10 +47,6 @@
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#if BUILDFLAG(ENABLE_BACKGROUND_MODE)
#include "chrome/browser/background/background_mode_manager.h"
#endif // BUILDFLAG(ENABLE_BACKGROUND_MODE)
namespace metrics {
namespace {
@ -699,12 +697,25 @@ void TabStatsTracker::UmaStatsReportingDelegate::ReportTabDuplicateMetrics(
bool TabStatsTracker::UmaStatsReportingDelegate::
IsChromeBackgroundedWithoutWindows() {
#if BUILDFLAG(ENABLE_BACKGROUND_MODE)
if (g_browser_process && g_browser_process->background_mode_manager()
->IsBackgroundWithoutWindows()) {
return true;
}
#endif // BUILDFLAG(ENABLE_BACKGROUND_MODE)
return KeepAliveRegistry::GetInstance()->WouldRestartWithout({
// Transient startup related KeepAlives, not related to any UI.
KeepAliveOrigin::SESSION_RESTORE,
KeepAliveOrigin::BACKGROUND_MODE_MANAGER_STARTUP,
KeepAliveOrigin::BACKGROUND_SYNC,
// Notification KeepAlives are not dependent on the Chrome UI being
// loaded, and can be registered when we were in pure background mode.
// They just block it to avoid issues. Ignore them when determining if we
// are in that mode.
KeepAliveOrigin::NOTIFICATION,
KeepAliveOrigin::PENDING_NOTIFICATION_CLICK_EVENT,
KeepAliveOrigin::PENDING_NOTIFICATION_CLOSE_EVENT,
KeepAliveOrigin::IN_FLIGHT_PUSH_MESSAGE,
});
#else
return false;
#endif // BUILDFLAG(ENABLE_BACKGROUND_MODE)
}
TabStatsTracker::UmaStatsReportingDelegate::DuplicateData::DuplicateData() {

@ -81,10 +81,6 @@
#include "ui/base/window_open_disposition.h"
#include "ui/message_center/public/cpp/notification.h"
#if BUILDFLAG(ENABLE_BACKGROUND_MODE)
#include "chrome/browser/background/background_mode_manager.h"
#endif
namespace {
const char kManifestSenderId[] = "1234567890";

@ -72,7 +72,6 @@
#include "url/origin.h"
#if BUILDFLAG(ENABLE_BACKGROUND_MODE)
#include "chrome/browser/background/background_mode_manager.h"
#include "components/keep_alive_registry/keep_alive_types.h"
#include "components/keep_alive_registry/scoped_keep_alive.h"
#endif

@ -10,7 +10,6 @@
#include "build/build_config.h"
#include "chrome/browser/apps/app_service/launch_utils.h"
#include "chrome/browser/background/background_mode_manager.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/defaults.h"
#include "chrome/browser/prefs/session_startup_pref.h"

@ -16,10 +16,6 @@
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h"
#if BUILDFLAG(ENABLE_BACKGROUND_MODE)
#include "chrome/browser/background/background_mode_manager.h"
#endif // BUILDFLAG(ENABLE_BACKGROUND_MODE)
namespace {
// A type represending the possible RelaunchNotification policy setting values.