Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / web_resource / promo_resource_service.h
blob3af6226100fba4e187bdf764231406d33e7868f2
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_
6 #define CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_
8 #include <string>
10 #include "base/callback_forward.h"
11 #include "base/callback_list.h"
12 #include "base/memory/weak_ptr.h"
13 #include "chrome/browser/web_resource/chrome_web_resource_service.h"
15 class NotificationPromo;
16 class PrefRegistrySimple;
17 class PrefService;
19 namespace base {
20 class DictionaryValue;
23 namespace user_prefs {
24 class PrefRegistrySyncable;
27 // A PromoResourceService fetches data from a web resource server to be used to
28 // dynamically change the appearance of the New Tab Page. For example, it has
29 // been used to fetch "tips" to be displayed on the NTP, or to display
30 // promotional messages to certain groups of Chrome users.
31 class PromoResourceService : public ChromeWebResourceService {
32 public:
33 using StateChangedCallbackList = base::CallbackList<void()>;
34 using StateChangedSubscription = StateChangedCallbackList::Subscription;
36 static void RegisterPrefs(PrefRegistrySimple* registry);
37 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
38 static void MigrateUserPrefs(PrefService* user_prefs);
40 PromoResourceService();
41 ~PromoResourceService() override;
43 // Registers a callback called when the state of a web resource has been
44 // changed. A resource may have been added, removed, or altered.
45 scoped_ptr<StateChangedSubscription> RegisterStateChangedCallback(
46 const base::Closure& closure);
48 private:
49 // Schedule a notification that a web resource is either going to become
50 // available or be no longer valid.
51 void ScheduleNotification(const NotificationPromo& notification_promo);
53 // Schedules the initial notification for when the web resource is going
54 // to become available or no longer valid. This performs a few additional
55 // checks than ScheduleNotification, namely it schedules updates immediately
56 // if the promo service or Chrome locale has changed.
57 void ScheduleNotificationOnInit();
59 // If delay_ms is positive, schedule notification with the delay.
60 // If delay_ms is 0, notify immediately by calling WebResourceStateChange().
61 // If delay_ms is negative, do nothing.
62 void PostNotification(int64 delay_ms);
64 // Notify listeners that the state of a web resource has changed.
65 void PromoResourceStateChange();
67 // WebResourceService override to process the parsed information.
68 void Unpack(const base::DictionaryValue& parsed_json) override;
70 // List of callbacks called when the state of a web resource has changed.
71 StateChangedCallbackList callback_list_;
73 // Allows the creation of tasks to send a notification.
74 // This allows the PromoResourceService to notify the New Tab Page immediately
75 // when a new web resource should be shown or removed.
76 base::WeakPtrFactory<PromoResourceService> weak_ptr_factory_;
78 DISALLOW_COPY_AND_ASSIGN(PromoResourceService);
81 #endif // CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_