OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "net/url_request/url_request_context.h" | |
achuithb
2011/11/16 23:27:03
Shouldn't this be in the cc file? You're forward d
Cait (Slow)
2011/11/17 00:05:59
Done.
| |
13 | 14 |
14 namespace base { | 15 namespace base { |
15 class DictionaryValue; | 16 class DictionaryValue; |
16 } | 17 } |
17 | 18 |
19 namespace net { | |
20 class URLRequestContextGetter; | |
21 } | |
22 | |
18 class PrefService; | 23 class PrefService; |
19 | 24 class Profile; |
20 // Helper class for PromoResourceService that parses promo notification info | 25 // Helper class for PromoResourceService that parses promo notification info |
achuithb
2011/11/16 23:27:03
newline above this line please.
Cait (Slow)
2011/11/17 00:05:59
Done.
| |
21 // from json or prefs. | 26 // from json or prefs. |
22 class NotificationPromo { | 27 class NotificationPromo |
28 : public base::RefCountedThreadSafe<NotificationPromo> { | |
23 public: | 29 public: |
24 class Delegate { | 30 class Delegate { |
25 public: | 31 public: |
26 virtual ~Delegate() {} | 32 virtual ~Delegate() {} |
27 virtual void OnNewNotification(double start, double end) = 0; | 33 virtual void OnNewNotification(double start, double end) = 0; |
28 // For testing. | 34 // For testing. |
29 virtual bool IsBuildAllowed(int builds_targeted) const { return false; } | 35 virtual bool IsBuildAllowed(int builds_targeted) const { return false; } |
30 }; | 36 }; |
31 | 37 |
32 explicit NotificationPromo(PrefService* prefs, Delegate* delegate); | 38 // Static factory for creating new promo objects. |
achuithb
2011/11/16 23:27:03
Perhaps change this to 'Static factory for creatin
Cait (Slow)
2011/11/17 00:05:59
Done.
| |
39 static NotificationPromo* Factory(Profile* profile, Delegate* delegate); | |
40 | |
33 | 41 |
34 // Initialize from json/prefs. | 42 // Initialize from json/prefs. |
35 void InitFromJson(const base::DictionaryValue& json); | 43 void InitFromJson(const base::DictionaryValue& json); |
36 void InitFromPrefs(); | 44 void InitFromPrefs(); |
37 | 45 |
38 // Can this promo be shown? | 46 // Can this promo be shown? |
39 bool CanShow() const; | 47 bool CanShow() const; |
40 | 48 |
41 // Calculates promo notification start time with group-based time slice | 49 // Calculates promo notification start time with group-based time slice |
42 // offset. | 50 // offset. |
43 double StartTimeWithOffset() const; | 51 double StartTimeWithOffset() const; |
44 | 52 |
45 // Helpers for NewTabPageHandler. | 53 // Helpers for NewTabPageHandler. |
46 void HandleClosed(); | 54 void HandleClosed(); |
47 bool HandleViewed(); // returns true if views exceeds maximum allowed. | 55 bool HandleViewed(); // returns true if views exceeds maximum allowed. |
48 | 56 |
49 // Register preferences. | 57 // Register preferences. |
50 static void RegisterUserPrefs(PrefService* prefs); | 58 static void RegisterUserPrefs(PrefService* prefs); |
51 | 59 |
60 protected: | |
achuithb
2011/11/16 23:27:03
Remove these lines
Cait (Slow)
2011/11/17 00:05:59
Done.
| |
61 | |
62 | |
52 private: | 63 private: |
64 friend class base::RefCountedThreadSafe<NotificationPromo>; | |
65 NotificationPromo(Profile* profile, Delegate* delegate); | |
66 virtual ~NotificationPromo(); | |
67 | |
53 // For testing. | 68 // For testing. |
54 friend class NotificationPromoTestDelegate; | 69 friend class NotificationPromoTestDelegate; |
55 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, GetNextQuestionValueTest); | 70 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, GetNextQuestionValueTest); |
56 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, NewGroupTest); | 71 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, NewGroupTest); |
57 | 72 |
58 // Users are randomly assigned to one of kMaxGroupSize + 1 buckets, in order | 73 // Users are randomly assigned to one of kMaxGroupSize + 1 buckets, in order |
59 // to be able to roll out promos slowly, or display different promos to | 74 // to be able to roll out promos slowly, or display different promos to |
60 // different groups. | 75 // different groups. |
61 static const int kMaxGroupSize = 99; | 76 static const int kMaxGroupSize = 99; |
62 | 77 |
63 // Parse the answers array element. Set the data members of this instance | 78 // Parse the answers array element. Set the data members of this instance |
64 // and trigger OnNewNotification callback if necessary. | 79 // and trigger OnNewNotification callback if necessary. |
65 void Parse(const base::DictionaryValue* dict); | 80 void Parse(const base::DictionaryValue* dict); |
66 | 81 |
67 // Set promo notification params from a question string, which is of the form | 82 // Set promo notification params from a question string, which is of the form |
68 // <build_type>:<time_slice>:<max_group>:<max_views> | 83 // <build_type>:<time_slice>:<max_group>:<max_views> |
69 void ParseParams(const base::DictionaryValue* dict); | 84 void ParseParams(const base::DictionaryValue* dict); |
70 | 85 |
71 // Check if this promo notification is new based on start/end times, | 86 // Check if this promo notification is new based on start/end times, |
72 // and trigger events accordingly. | 87 // and trigger events accordingly. |
73 void CheckForNewNotification(); | 88 void CheckForNewNotification(bool found_cookie); |
74 | 89 |
75 // Actions on receiving a new promo notification. | 90 // Actions on receiving a new promo notification. |
76 void OnNewNotification(); | 91 void OnNewNotification(); |
77 | 92 |
93 void GetCookiesCallback(const std::string& cookies); | |
achuithb
2011/11/16 23:27:03
Switch the order of GetCookies and GetCookiesCallb
Cait (Slow)
2011/11/17 00:05:59
Done.
| |
94 | |
95 void GetCookies(net::URLRequestContextGetter* getter); | |
96 | |
78 // Create a new promo notification group. | 97 // Create a new promo notification group. |
79 static int NewGroup(); | 98 static int NewGroup(); |
80 | 99 |
81 // Returns an int converted from the question substring starting at index | 100 // Returns an int converted from the question substring starting at index |
82 // till the next colon. Sets index to the location right after the colon. | 101 // till the next colon. Sets index to the location right after the colon. |
83 // Returns 0 if *err is true, and sets *err to true upon error. | 102 // Returns 0 if *err is true, and sets *err to true upon error. |
84 static int GetNextQuestionValue(const std::string& question, | 103 static int GetNextQuestionValue(const std::string& question, |
85 size_t* index, | 104 size_t* index, |
86 bool* err); | 105 bool* err); |
87 | 106 |
88 // Flush data members to prefs for storage. | 107 // Flush data members to prefs for storage. |
89 void WritePrefs(); | 108 void WritePrefs(); |
90 | 109 |
91 // Match our channel with specified build type. | 110 // Match our channel with specified build type. |
92 bool IsBuildAllowed(int builds_allowed) const; | 111 bool IsBuildAllowed(int builds_allowed) const; |
93 | 112 |
94 // For testing. | 113 // For testing. |
95 bool operator==(const NotificationPromo& other) const; | 114 bool operator==(const NotificationPromo& other) const; |
96 | 115 |
116 Profile* profile_; | |
97 PrefService* prefs_; | 117 PrefService* prefs_; |
98 Delegate* delegate_; | 118 Delegate* delegate_; |
99 | 119 |
100 double start_; | 120 double start_; |
101 double end_; | 121 double end_; |
102 | 122 |
103 int build_; | 123 int build_; |
104 int time_slice_; | 124 int time_slice_; |
105 int max_group_; | 125 int max_group_; |
106 int max_views_; | 126 int max_views_; |
127 int feature_mask_; | |
107 | 128 |
108 int group_; | 129 int group_; |
109 int views_; | 130 int views_; |
110 std::string text_; | 131 std::string text_; |
111 bool closed_; | 132 bool closed_; |
133 bool gplus_; | |
112 | 134 |
113 DISALLOW_COPY_AND_ASSIGN(NotificationPromo); | 135 DISALLOW_COPY_AND_ASSIGN(NotificationPromo); |
114 }; | 136 }; |
115 | 137 |
116 #endif // CHROME_BROWSER_WEB_RESOURCE_NOTIFICATION_PROMO_H_ | 138 #endif // CHROME_BROWSER_WEB_RESOURCE_NOTIFICATION_PROMO_H_ |
117 | 139 |
OLD | NEW |