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_NOTIFICATION_PROMO_H_ | 5 #ifndef CHROME_BROWSER_WEB_RESOURCE_NOTIFICATION_PROMO_H_ |
6 #define CHROME_BROWSER_WEB_RESOURCE_NOTIFICATION_PROMO_H_ | 6 #define CHROME_BROWSER_WEB_RESOURCE_NOTIFICATION_PROMO_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
15 | 15 |
16 namespace base { | 16 namespace base { |
17 class DictionaryValue; | 17 class DictionaryValue; |
18 class ListValue; | 18 class ListValue; |
19 } | 19 } |
20 | 20 |
21 class PrefService; | 21 class PrefService; |
22 class Profile; | 22 class Profile; |
23 | 23 |
24 // Helper class for PromoResourceService that parses promo notification info | 24 // Helper class for PromoResourceService that parses promo notification info |
25 // from json or prefs. | 25 // from json or prefs. |
26 class NotificationPromo { | 26 class NotificationPromo { |
27 public: | 27 public: |
28 static GURL PromoServerURL(); | 28 static GURL PromoServerURL(); |
29 | 29 |
30 static const char kNtpNotificationPromoType[]; | 30 enum PromoType { |
31 static const char kBubblePromoType[]; | 31 NO_PROMO, |
| 32 NTP_NOTIFICATION_PROMO, |
| 33 BUBBLE_PROMO, |
| 34 MOBILE_NTP_SYNC_PROMO, |
| 35 }; |
32 | 36 |
33 explicit NotificationPromo(Profile* profile); | 37 explicit NotificationPromo(Profile* profile); |
34 ~NotificationPromo(); | 38 ~NotificationPromo(); |
35 | 39 |
36 // Initialize from json/prefs. | 40 // Initialize from json/prefs. |
37 void InitFromJson(const base::DictionaryValue& json); | 41 void InitFromJson(const base::DictionaryValue& json, PromoType promo_type); |
38 void InitFromPrefs(); | 42 void InitFromPrefs(PromoType promo_type); |
39 | 43 |
40 // Can this promo be shown? | 44 // Can this promo be shown? |
41 bool CanShow() const; | 45 bool CanShow() const; |
42 | 46 |
43 // Calculates promo notification start time with group-based time slice | 47 // Calculates promo notification start time with group-based time slice |
44 // offset. | 48 // offset. |
45 double StartTimeForGroup() const; | 49 double StartTimeForGroup() const; |
46 double EndTime() const; | 50 double EndTime() const; |
47 | 51 |
48 // Helpers for NewTabPageHandler. | 52 // Helpers for NewTabPageHandler. |
49 void HandleClosed(); | 53 // Mark the promo as closed when the user dismisses it. |
50 bool HandleViewed(); // returns true if views exceeds maximum allowed. | 54 static void HandleClosed(Profile* profile, PromoType promo_type); |
| 55 // Mark the promo has having been viewed. This returns true if views |
| 56 // exceeds the maximum allowed. |
| 57 static bool HandleViewed(Profile* profile, PromoType promo_type); |
51 | 58 |
52 bool new_notification() const { return new_notification_; } | 59 bool new_notification() const { return new_notification_; } |
53 | 60 |
54 const std::string& promo_text() const { return promo_text_; } | 61 const std::string& promo_text() const { return promo_text_; } |
55 #if defined(OS_ANDROID) || defined(OS_IOS) | 62 #if defined(OS_ANDROID) || defined(OS_IOS) |
56 const std::string& promo_text_long() const { return promo_text_long_; } | 63 const std::string& promo_text_long() const { return promo_text_long_; } |
57 const std::string& promo_action_type() const { return promo_action_type_; } | 64 const std::string& promo_action_type() const { return promo_action_type_; } |
58 const base::ListValue* promo_action_args() const { | 65 const base::ListValue* promo_action_args() const { |
59 return promo_action_args_.get(); | 66 return promo_action_args_.get(); |
60 } | 67 } |
(...skipping 23 matching lines...) Expand all Loading... |
84 // Tests views_ against max_views_. | 91 // Tests views_ against max_views_. |
85 // When max_views_ is 0, we don't cap the number of views. | 92 // When max_views_ is 0, we don't cap the number of views. |
86 bool ExceedsMaxViews() const; | 93 bool ExceedsMaxViews() const; |
87 | 94 |
88 // True if this promo is not targeted to G+ users, or if this is a G+ user. | 95 // True if this promo is not targeted to G+ users, or if this is a G+ user. |
89 bool IsGPlusRequired() const; | 96 bool IsGPlusRequired() const; |
90 | 97 |
91 Profile* profile_; | 98 Profile* profile_; |
92 PrefService* prefs_; | 99 PrefService* prefs_; |
93 | 100 |
94 std::string promo_type_; | 101 PromoType promo_type_; |
95 std::string promo_text_; | 102 std::string promo_text_; |
96 #if defined(OS_ANDROID) || defined(OS_IOS) | 103 #if defined(OS_ANDROID) || defined(OS_IOS) |
97 std::string promo_text_long_; | 104 std::string promo_text_long_; |
98 std::string promo_action_type_; | 105 std::string promo_action_type_; |
99 scoped_ptr<base::ListValue> promo_action_args_; | 106 scoped_ptr<base::ListValue> promo_action_args_; |
100 #endif // defined(OS_ANDROID) || defined(OS_IOS) | 107 #endif // defined(OS_ANDROID) || defined(OS_IOS) |
101 | 108 |
102 double start_; | 109 double start_; |
103 double end_; | 110 double end_; |
104 | 111 |
(...skipping 11 matching lines...) Expand all Loading... |
116 bool closed_; | 123 bool closed_; |
117 | 124 |
118 bool gplus_required_; | 125 bool gplus_required_; |
119 | 126 |
120 bool new_notification_; | 127 bool new_notification_; |
121 | 128 |
122 DISALLOW_COPY_AND_ASSIGN(NotificationPromo); | 129 DISALLOW_COPY_AND_ASSIGN(NotificationPromo); |
123 }; | 130 }; |
124 | 131 |
125 #endif // CHROME_BROWSER_WEB_RESOURCE_NOTIFICATION_PROMO_H_ | 132 #endif // CHROME_BROWSER_WEB_RESOURCE_NOTIFICATION_PROMO_H_ |
OLD | NEW |