OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_ |
6 #define CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_ | 6 #define CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "chrome/browser/web_resource/web_resource_service.h" | 11 #include "chrome/browser/web_resource/web_resource_service.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 class DictionaryValue; | 14 class DictionaryValue; |
15 } | 15 } |
16 | 16 |
17 class NotificationPromo; | 17 class NotificationPromo; |
18 class PrefServiceSimple; | 18 class PrefServiceSimple; |
19 class PrefServiceSyncable; | 19 class PrefServiceSyncable; |
20 class Profile; | |
21 | 20 |
22 // A PromoResourceService fetches data from a web resource server to be used to | 21 // A PromoResourceService fetches data from a web resource server to be used to |
23 // dynamically change the appearance of the New Tab Page. For example, it has | 22 // dynamically change the appearance of the New Tab Page. For example, it has |
24 // been used to fetch "tips" to be displayed on the NTP, or to display | 23 // been used to fetch "tips" to be displayed on the NTP, or to display |
25 // promotional messages to certain groups of Chrome users. | 24 // promotional messages to certain groups of Chrome users. |
26 class PromoResourceService : public WebResourceService { | 25 class PromoResourceService : public WebResourceService { |
27 public: | 26 public: |
28 static void RegisterPrefs(PrefServiceSimple* local_state); | 27 static void RegisterPrefs(PrefServiceSimple* local_state); |
29 | |
30 static void RegisterUserPrefs(PrefServiceSyncable* prefs); | 28 static void RegisterUserPrefs(PrefServiceSyncable* prefs); |
31 | 29 |
32 explicit PromoResourceService(Profile* profile); | 30 PromoResourceService(); |
33 | 31 |
34 private: | 32 private: |
35 virtual ~PromoResourceService(); | 33 virtual ~PromoResourceService(); |
36 | 34 |
37 // Schedule a notification that a web resource is either going to become | 35 // Schedule a notification that a web resource is either going to become |
38 // available or be no longer valid. | 36 // available or be no longer valid. |
39 void ScheduleNotification(const NotificationPromo& notification_promo); | 37 void ScheduleNotification(const NotificationPromo& notification_promo); |
40 | 38 |
41 // Schedules the initial notification for when the web resource is going | 39 // Schedules the initial notification for when the web resource is going |
42 // to become available or no longer valid. This performs a few additional | 40 // to become available or no longer valid. This performs a few additional |
43 // checks than ScheduleNotification, namely it schedules updates immediately | 41 // checks than ScheduleNotification, namely it schedules updates immediately |
44 // if the promo service or Chrome locale has changed. | 42 // if the promo service or Chrome locale has changed. |
45 void ScheduleNotificationOnInit(); | 43 void ScheduleNotificationOnInit(); |
46 | 44 |
47 // If delay_ms is positive, schedule notification with the delay. | 45 // If delay_ms is positive, schedule notification with the delay. |
48 // If delay_ms is 0, notify immediately by calling WebResourceStateChange(). | 46 // If delay_ms is 0, notify immediately by calling WebResourceStateChange(). |
49 // If delay_ms is negative, do nothing. | 47 // If delay_ms is negative, do nothing. |
50 void PostNotification(int64 delay_ms); | 48 void PostNotification(int64 delay_ms); |
51 | 49 |
52 // Notify listeners that the state of a web resource has changed. | 50 // Notify listeners that the state of a web resource has changed. |
53 void PromoResourceStateChange(); | 51 void PromoResourceStateChange(); |
54 | 52 |
55 // WebResourceService override to process the parsed information. | 53 // WebResourceService override to process the parsed information. |
56 virtual void Unpack(const base::DictionaryValue& parsed_json) OVERRIDE; | 54 virtual void Unpack(const base::DictionaryValue& parsed_json) OVERRIDE; |
57 | 55 |
58 // The profile this service belongs to. | |
59 Profile* profile_; | |
60 | |
61 // Allows the creation of tasks to send a notification. | 56 // Allows the creation of tasks to send a notification. |
62 // This allows the PromoResourceService to notify the New Tab Page immediately | 57 // This allows the PromoResourceService to notify the New Tab Page immediately |
63 // when a new web resource should be shown or removed. | 58 // when a new web resource should be shown or removed. |
64 base::WeakPtrFactory<PromoResourceService> weak_ptr_factory_; | 59 base::WeakPtrFactory<PromoResourceService> weak_ptr_factory_; |
65 | 60 |
66 DISALLOW_COPY_AND_ASSIGN(PromoResourceService); | 61 DISALLOW_COPY_AND_ASSIGN(PromoResourceService); |
67 }; | 62 }; |
68 | 63 |
69 #endif // CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_ | 64 #endif // CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_ |
OLD | NEW |