Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Side by Side Diff: chrome/browser/web_resource/notification_promo.h

Issue 11689004: Move PromoResourceService from Profile to BrowserProcessImpl/local_state(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 PrefServiceSimple;
22 class PrefServiceSyncable; 23 class PrefServiceSyncable;
23 class Profile;
24 24
25 // Helper class for PromoResourceService that parses promo notification info 25 // Helper class for PromoResourceService that parses promo notification info
26 // from json or prefs. 26 // from json or prefs.
27 class NotificationPromo { 27 class NotificationPromo {
28 public: 28 public:
29 static GURL PromoServerURL(); 29 static GURL PromoServerURL();
30 30
31 enum PromoType { 31 enum PromoType {
32 NO_PROMO, 32 NO_PROMO,
33 NTP_NOTIFICATION_PROMO, 33 NTP_NOTIFICATION_PROMO,
34 NTP_BUBBLE_PROMO, 34 NTP_BUBBLE_PROMO,
35 MOBILE_NTP_SYNC_PROMO, 35 MOBILE_NTP_SYNC_PROMO,
36 }; 36 };
37 37
38 explicit NotificationPromo(Profile* profile); 38 NotificationPromo();
39 ~NotificationPromo(); 39 ~NotificationPromo();
40 40
41 // Initialize from json/prefs. 41 // Initialize from json/prefs.
42 void InitFromJson(const base::DictionaryValue& json, PromoType promo_type); 42 void InitFromJson(const base::DictionaryValue& json, PromoType promo_type);
43 void InitFromPrefs(PromoType promo_type); 43 void InitFromPrefs(PromoType promo_type);
44 44
45 // Can this promo be shown? 45 // Can this promo be shown?
46 bool CanShow() const; 46 bool CanShow() const;
47 47
48 // Calculates promo notification start time with group-based time slice 48 // Calculates promo notification start time with group-based time slice
49 // offset. 49 // offset.
50 double StartTimeForGroup() const; 50 double StartTimeForGroup() const;
51 double EndTime() const; 51 double EndTime() const;
52 52
53 // Helpers for NewTabPageHandler. 53 // Helpers for NewTabPageHandler.
54 // Mark the promo as closed when the user dismisses it. 54 // Mark the promo as closed when the user dismisses it.
55 static void HandleClosed(Profile* profile, PromoType promo_type); 55 static void HandleClosed(PromoType promo_type);
56 // Mark the promo has having been viewed. This returns true if views 56 // Mark the promo has having been viewed. This returns true if views
57 // exceeds the maximum allowed. 57 // exceeds the maximum allowed.
58 static bool HandleViewed(Profile* profile, PromoType promo_type); 58 static bool HandleViewed(PromoType promo_type);
59 59
60 bool new_notification() const { return new_notification_; } 60 bool new_notification() const { return new_notification_; }
61 61
62 const std::string& promo_text() const { return promo_text_; } 62 const std::string& promo_text() const { return promo_text_; }
63 PromoType promo_type() const { return promo_type_; } 63 PromoType promo_type() const { return promo_type_; }
64 const base::DictionaryValue* promo_payload() const { 64 const base::DictionaryValue* promo_payload() const {
65 return promo_payload_.get(); 65 return promo_payload_.get();
66 } 66 }
67 67
68 // Register preferences. 68 // Register preferences.
69 static void RegisterPrefs(PrefServiceSimple* local_state);
69 static void RegisterUserPrefs(PrefServiceSyncable* prefs); 70 static void RegisterUserPrefs(PrefServiceSyncable* prefs);
70 71
71 private: 72 private:
73 static void HandleClosedInternal(NotificationPromo* promo,
74 PromoType promo_type);
75 static bool HandleViewedInternal(NotificationPromo* promo,
76 PromoType promo_type);
77
72 // For testing. 78 // For testing.
79 NotificationPromo(PrefService* prefs);
80 static void HandleClosedForTesting(PrefService* prefs, PromoType promo_type);
81 static bool HandleViewedForTesting(PrefService* prefs, PromoType promo_type);
73 friend class NotificationPromoTest; 82 friend class NotificationPromoTest;
Robert Sesek 2013/01/03 21:40:10 friend declarations come first
Dan Beam 2013/01/03 22:47:38 Done. (removed *Internal methods)
83 friend class PromoResourceService;
74 84
75 // Check if this promo notification is new based on start/end times, 85 // Check if this promo notification is new based on start/end times,
76 // and trigger events accordingly. 86 // and trigger events accordingly.
77 void CheckForNewNotification(); 87 void CheckForNewNotification();
78 88
79 // Actions on receiving a new promo notification. 89 // Actions on receiving a new promo notification.
80 void OnNewNotification(); 90 void OnNewNotification();
81 91
82 // Flush data members to prefs for storage. 92 // Flush data members to prefs for storage.
83 void WritePrefs(); 93 void WritePrefs();
84 94
85 // Tests group_ against max_group_. 95 // Tests group_ against max_group_.
86 // When max_group_ is 0, all groups pass. 96 // When max_group_ is 0, all groups pass.
87 bool ExceedsMaxGroup() const; 97 bool ExceedsMaxGroup() const;
88 98
89 // Tests views_ against max_views_. 99 // Tests views_ against max_views_.
90 // When max_views_ is 0, we don't cap the number of views. 100 // When max_views_ is 0, we don't cap the number of views.
91 bool ExceedsMaxViews() const; 101 bool ExceedsMaxViews() const;
92 102
93 // True if this promo is not targeted to G+ users, or if this is a G+ user.
94 bool IsGPlusRequired() const;
95
96 Profile* profile_;
97 PrefService* prefs_; 103 PrefService* prefs_;
98 104
99 PromoType promo_type_; 105 PromoType promo_type_;
100 std::string promo_text_; 106 std::string promo_text_;
101 107
102 // Note that promo_payload_ isn't currently used for desktop promos. 108 // Note that promo_payload_ isn't currently used for desktop promos.
103 scoped_ptr<const base::DictionaryValue> promo_payload_; 109 scoped_ptr<const base::DictionaryValue> promo_payload_;
104 110
105 double start_; 111 double start_;
106 double end_; 112 double end_;
107 113
108 int num_groups_; 114 int num_groups_;
109 int initial_segment_; 115 int initial_segment_;
110 int increment_; 116 int increment_;
111 int time_slice_; 117 int time_slice_;
112 int max_group_; 118 int max_group_;
113 119
114 // When max_views_ is 0, we don't cap the number of views. 120 // When max_views_ is 0, we don't cap the number of views.
115 int max_views_; 121 int max_views_;
116 122
117 int group_; 123 int group_;
118 int views_; 124 int views_;
119 bool closed_; 125 bool closed_;
120 126
121 bool gplus_required_;
122
123 bool new_notification_; 127 bool new_notification_;
124 128
125 DISALLOW_COPY_AND_ASSIGN(NotificationPromo); 129 DISALLOW_COPY_AND_ASSIGN(NotificationPromo);
126 }; 130 };
127 131
128 #endif // CHROME_BROWSER_WEB_RESOURCE_NOTIFICATION_PROMO_H_ 132 #endif // CHROME_BROWSER_WEB_RESOURCE_NOTIFICATION_PROMO_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698