#include "chrome/browser/badging/badge_manager.h"
#include <tuple>
#include <utility>
#include "base/i18n/number_formatting.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/default_clock.h"
#include "build/build_config.h"
#include "chrome/browser/badging/badge_manager_delegate.h"
#include "chrome/browser/badging/badge_manager_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/web_applications/app_browser_controller.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/browser/web_applications/web_app_registrar.h"
#include "chrome/browser/web_applications/web_app_sync_bridge.h"
#include "components/ukm/app_source_url_recorder.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "services/metrics/public/cpp/delegating_ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/strings/grit/ui_strings.h"
#if BUILDFLAG(IS_MAC)
#include "chrome/browser/badging/badge_manager_delegate_mac.h"
#elif BUILDFLAG(IS_WIN)
#include "chrome/browser/badging/badge_manager_delegate_win.h"
#endif
WebAppProvider;
namespace {
bool IsLastBadgingTimeWithin(base::TimeDelta time_frame,
const webapps::AppId& app_id,
const base::Clock* clock,
Profile* profile) { … }
web_app::WebAppSyncBridge* GetWebAppSyncBridgeForProfile(Profile* profile) { … }
}
namespace badging {
BadgeManager::BadgeManager(Profile* profile)
: … { … }
BadgeManager::~BadgeManager() = default;
void BadgeManager::SetDelegate(std::unique_ptr<BadgeManagerDelegate> delegate) { … }
void BadgeManager::BindFrameReceiverIfAllowed(
content::RenderFrameHost* frame,
mojo::PendingReceiver<blink::mojom::BadgeService> receiver) { … }
void BadgeManager::BindServiceWorkerReceiverIfAllowed(
content::RenderProcessHost* service_worker_process_host,
const content::ServiceWorkerVersionBaseInfo& info,
mojo::PendingReceiver<blink::mojom::BadgeService> receiver) { … }
std::optional<BadgeManager::BadgeValue> BadgeManager::GetBadgeValue(
const webapps::AppId& app_id) { … }
bool BadgeManager::HasRecentApiUsage(const webapps::AppId& app_id) const { … }
void BadgeManager::SetBadgeForTesting(const webapps::AppId& app_id,
BadgeValue value,
ukm::UkmRecorder* test_recorder) { … }
void BadgeManager::ClearBadgeForTesting(const webapps::AppId& app_id,
ukm::UkmRecorder* test_recorder) { … }
const base::Clock* BadgeManager::SetClockForTesting(const base::Clock* clock) { … }
void BadgeManager::UpdateBadge(const webapps::AppId& app_id,
std::optional<BadgeValue> value) { … }
void BadgeManager::SetBadge(blink::mojom::BadgeValuePtr mojo_value) { … }
void BadgeManager::ClearBadge() { … }
std::vector<std::tuple<webapps::AppId, GURL>>
BadgeManager::FrameBindingContext::GetAppIdsAndUrlsForBadging() const { … }
std::vector<std::tuple<webapps::AppId, GURL>>
BadgeManager::ServiceWorkerBindingContext::GetAppIdsAndUrlsForBadging() const { … }
std::string GetBadgeString(std::optional<uint64_t> badge_content) { … }
}