1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UPDATES_ANNOUNCEMENT_NOTIFICATION_ANNOUNCEMENT_NOTIFICATION_SERVICE_H_
#define CHROME_BROWSER_UPDATES_ANNOUNCEMENT_NOTIFICATION_ANNOUNCEMENT_NOTIFICATION_SERVICE_H_
#include <memory>
#include "base/feature_list.h"
#include "components/keyed_service/core/keyed_service.h"
#include "url/gurl.h"
namespace base {
class Clock;
} // namespace base
class PrefRegistrySimple;
class PrefService;
class Profile;
// Whether to enable announcement notification system.
BASE_DECLARE_FEATURE(kAnnouncementNotification);
// The Finch parameter name for a boolean value that whether to show
// notification on first run.
inline constexpr char kSkipFirstRun[] = "skip_first_run";
// The Finch parameter name for a string value that represents a time.
// If first run happens after this time, notification will not show.
// The string defined in Finch config should specify the time zone.
// e.g. 02 Feb 2020 13:00:00 GMT.
inline constexpr char kSkipFirstRunAfterTime[] = "skip_first_run_after_time";
// The Finch parameter name for a boolean value that whether to show
// notification for new profile.
inline constexpr char kSkipNewProfile[] = "skip_new_profile";
// The Finch parameter to control whether to skip notification display.
inline constexpr char kSkipDisplay[] = "skip_display";
// The Finch parameter to define the latest version number of the notification.
inline constexpr char kVersion[] = "version";
// The Finch parameter to define whether to show the announcement to users not
// signed in.
inline constexpr char kRequireSignout[] = "require_sign_out";
// The Finch parameter to define whether to show the announcement to users not
// signed in.
inline constexpr char kShowOneAllProfiles[] = "show_one_all_profiles";
// The Finch parameter to define the announcement URL.
inline constexpr char kAnnouncementUrl[] = "announcement_url";
// Preference name to persist the current version sent from Finch parameter.
inline constexpr char kCurrentVersionPrefName[] =
"announcement_notification_service_current_version";
// Preference name to persist the time of Chrome first run.
inline constexpr char kAnnouncementFirstRunTimePrefName[] =
"announcement_notification_service_first_run_time";
// Used to show a notification when the version defined in Finch parameter is
// higher than the last version saved in the preference service.
class AnnouncementNotificationService : public KeyedService {
public:
class Delegate {
public:
Delegate() = default;
Delegate(const Delegate&) = delete;
Delegate& operator=(const Delegate&) = delete;
virtual ~Delegate() = default;
// Show notification.
virtual void ShowNotification() = 0;
// Is Chrome first time to run.
virtual bool IsFirstRun() = 0;
};
static void RegisterProfilePrefs(PrefRegistrySimple* registry);
static std::unique_ptr<AnnouncementNotificationService> Create(
Profile* profile,
PrefService* pref_service,
std::unique_ptr<Delegate> delegate,
base::Clock* clock);
static GURL GetAnnouncementURL();
// Returns if the announcement can be opened.
static bool CanOpenAnnouncement(Profile* profile);
AnnouncementNotificationService();
AnnouncementNotificationService(const AnnouncementNotificationService&) =
delete;
AnnouncementNotificationService& operator=(
const AnnouncementNotificationService&) = delete;
~AnnouncementNotificationService() override;
// Show notification if needed based on a version number in Finch parameters
// and the version cached in PrefService.
virtual void MaybeShowNotification() = 0;
};
#endif // CHROME_BROWSER_UPDATES_ANNOUNCEMENT_NOTIFICATION_ANNOUNCEMENT_NOTIFICATION_SERVICE_H_
|