blob: 940cff3bf192664330ff8f866db5c210d9ffd2b0 [file] [log] [blame]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <map>
#include <memory>
#include <string>
#include "base/macros.h"
#include "base/optional.h"
#include "chrome/browser/badging/badge_manager_delegate.h"
#include "components/keyed_service/core/keyed_service.h"
#include "extensions/common/extension_id.h"
class KeyedService;
class Profile;
namespace badging {
// Determines the text to put on the badge based on some badge_content.
std::string GetBadgeString(base::Optional<uint64_t> badge_content);
// Maintains a record of badge contents and dispatches badge changes to a
// delegate.
class BadgeManager : public KeyedService {
explicit BadgeManager(Profile* profile);
~BadgeManager() override;
// Records badge contents for an app and notifies the delegate if the badge
// contents have changed.
void UpdateBadge(const extensions::ExtensionId&, base::Optional<uint64_t>);
// Clears badge contents for an app (if existing) and notifies the delegate.
void ClearBadge(const extensions::ExtensionId&);
// Sets the delegate used for setting/clearing badges.
void SetDelegate(std::unique_ptr<BadgeManagerDelegate> delegate);
std::unique_ptr<BadgeManagerDelegate> delegate_;
// Maps extension id to badge contents.
std::map<extensions::ExtensionId, base::Optional<uint64_t>> badged_apps_;
} // namespace badging