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

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

Issue 8520009: Only show G+ promo for users logged into G+ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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) 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"
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
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.
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:
61 NotificationPromo(Profile* profile, Delegate* delegate);
achuithb 2011/11/16 20:33:11 please make these private (the ctor, friend decl a
Cait (Slow) 2011/11/16 23:05:24 Done.
62
63 friend class base::RefCountedThreadSafe<NotificationPromo>;
64 virtual ~NotificationPromo();
65
52 private: 66 private:
53 // For testing. 67 // For testing.
54 friend class NotificationPromoTestDelegate; 68 friend class NotificationPromoTestDelegate;
55 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, GetNextQuestionValueTest); 69 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, GetNextQuestionValueTest);
56 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, NewGroupTest); 70 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, NewGroupTest);
57 71
58 // Users are randomly assigned to one of kMaxGroupSize + 1 buckets, in order 72 // 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 73 // to be able to roll out promos slowly, or display different promos to
60 // different groups. 74 // different groups.
61 static const int kMaxGroupSize = 99; 75 static const int kMaxGroupSize = 99;
62 76
achuithb 2011/11/16 20:33:11 Please add an enum here like: enum FEATURE { NO_
Cait (Slow) 2011/11/16 23:05:24 I agree that this is a cleaner way to go, but it s
63 // Parse the answers array element. Set the data members of this instance 77 // Parse the answers array element. Set the data members of this instance
64 // and trigger OnNewNotification callback if necessary. 78 // and trigger OnNewNotification callback if necessary.
65 void Parse(const base::DictionaryValue* dict); 79 void Parse(const base::DictionaryValue* dict);
66 80
67 // Set promo notification params from a question string, which is of the form 81 // Set promo notification params from a question string, which is of the form
68 // <build_type>:<time_slice>:<max_group>:<max_views> 82 // <build_type>:<time_slice>:<max_group>:<max_views>
69 void ParseParams(const base::DictionaryValue* dict); 83 void ParseParams(const base::DictionaryValue* dict);
70 84
71 // 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,
72 // and trigger events accordingly. 86 // and trigger events accordingly.
73 void CheckForNewNotification(); 87 void CheckForNewNotification(bool found_cookie);
74 88
75 // Actions on receiving a new promo notification. 89 // Actions on receiving a new promo notification.
76 void OnNewNotification(); 90 void OnNewNotification();
77 91
92 void GetCookiesCallback(const std::string& cookies);
93
94 void GetCookies(net::URLRequestContextGetter* getter);
95
78 // Create a new promo notification group. 96 // Create a new promo notification group.
79 static int NewGroup(); 97 static int NewGroup();
80 98
81 // Returns an int converted from the question substring starting at index 99 // 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. 100 // 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. 101 // Returns 0 if *err is true, and sets *err to true upon error.
84 static int GetNextQuestionValue(const std::string& question, 102 static int GetNextQuestionValue(const std::string& question,
85 size_t* index, 103 size_t* index,
86 bool* err); 104 bool* err);
87 105
88 // Flush data members to prefs for storage. 106 // Flush data members to prefs for storage.
89 void WritePrefs(); 107 void WritePrefs();
90 108
91 // Match our channel with specified build type. 109 // Match our channel with specified build type.
92 bool IsBuildAllowed(int builds_allowed) const; 110 bool IsBuildAllowed(int builds_allowed) const;
93 111
94 // For testing. 112 // For testing.
95 bool operator==(const NotificationPromo& other) const; 113 bool operator==(const NotificationPromo& other) const;
96 114
97 PrefService* prefs_; 115 PrefService* prefs_;
116 Profile* profile_;
achuithb 2011/11/16 20:33:11 I think profile_ should be the first data member
Cait (Slow) 2011/11/16 23:05:24 Done.
98 Delegate* delegate_; 117 Delegate* delegate_;
99 118
100 double start_; 119 double start_;
101 double end_; 120 double end_;
102 121
103 int build_; 122 int build_;
104 int time_slice_; 123 int time_slice_;
105 int max_group_; 124 int max_group_;
106 int max_views_; 125 int max_views_;
126 int feature_mask_;
107 127
108 int group_; 128 int group_;
109 int views_; 129 int views_;
110 std::string text_; 130 std::string text_;
111 bool closed_; 131 bool closed_;
132 bool gplus_;
112 133
113 DISALLOW_COPY_AND_ASSIGN(NotificationPromo); 134 DISALLOW_COPY_AND_ASSIGN(NotificationPromo);
114 }; 135 };
115 136
116 #endif // CHROME_BROWSER_WEB_RESOURCE_NOTIFICATION_PROMO_H_ 137 #endif // CHROME_BROWSER_WEB_RESOURCE_NOTIFICATION_PROMO_H_
117 138
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/web_resource/notification_promo.cc » ('j') | chrome/browser/web_resource/notification_promo.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698