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_
10 #include "base/memory/weak_ptr.h"
11 #include "chrome/browser/web_resource/chrome_web_resource_service.h"
13 class NotificationPromo
;
14 class PrefRegistrySimple
;
18 class DictionaryValue
;
21 namespace user_prefs
{
22 class PrefRegistrySyncable
;
25 // A PromoResourceService fetches data from a web resource server to be used to
26 // dynamically change the appearance of the New Tab Page. For example, it has
27 // been used to fetch "tips" to be displayed on the NTP, or to display
28 // promotional messages to certain groups of Chrome users.
29 class PromoResourceService
: public ChromeWebResourceService
{
31 static void RegisterPrefs(PrefRegistrySimple
* registry
);
32 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable
* registry
);
33 static void MigrateUserPrefs(PrefService
* user_prefs
);
35 PromoResourceService();
36 ~PromoResourceService() override
;
39 // Schedule a notification that a web resource is either going to become
40 // available or be no longer valid.
41 void ScheduleNotification(const NotificationPromo
& notification_promo
);
43 // Schedules the initial notification for when the web resource is going
44 // to become available or no longer valid. This performs a few additional
45 // checks than ScheduleNotification, namely it schedules updates immediately
46 // if the promo service or Chrome locale has changed.
47 void ScheduleNotificationOnInit();
49 // If delay_ms is positive, schedule notification with the delay.
50 // If delay_ms is 0, notify immediately by calling WebResourceStateChange().
51 // If delay_ms is negative, do nothing.
52 void PostNotification(int64 delay_ms
);
54 // Notify listeners that the state of a web resource has changed.
55 void PromoResourceStateChange();
57 // WebResourceService override to process the parsed information.
58 void Unpack(const base::DictionaryValue
& parsed_json
) override
;
60 // Allows the creation of tasks to send a notification.
61 // This allows the PromoResourceService to notify the New Tab Page immediately
62 // when a new web resource should be shown or removed.
63 base::WeakPtrFactory
<PromoResourceService
> weak_ptr_factory_
;
65 DISALLOW_COPY_AND_ASSIGN(PromoResourceService
);
68 #endif // CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_