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

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

Issue 8045012: NotificationPromo (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix spacing nit Created 9 years, 2 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_WEB_RESOURCE_PROMO_NOTIFICATION_H_
6 #define CHROME_BROWSER_WEB_RESOURCE_PROMO_NOTIFICATION_H_
7 #pragma once
8
9 #include <string>
10
11 #include "base/basictypes.h"
12 #include "base/gtest_prod_util.h"
13
14 namespace base {
15 class DictionaryValue;
16 }
17
18 class PrefService;
19
20 // Helper class for PromoResourceService that parses promo notification info
21 // from json or prefs.
22 class PromoNotification {
23 public:
24 class Delegate {
25 public:
26 virtual ~Delegate() {}
27 virtual void OnNewNotification(double start, double end) = 0;
28 // For testing.
29 virtual bool IsBuildAllowed(int builds_targeted) const { return false; }
30 };
31
32 explicit PromoNotification(PrefService* prefs, Delegate* delegate);
33
34 // Initialize from json/prefs.
35 void InitFromJson(const base::DictionaryValue& json);
36 void InitFromPrefs();
37
38 // Can this promo be shown?
39 bool CanShow() const;
40
41 static void RegisterUserPrefs(PrefService* prefs);
42
43 // Calculates promo notification start time with group-based time slice
44 // offset.
45 double StartTimeWithOffset() const;
46
47 private:
48 // For testing.
49 friend class PromoNotificationTestDelegate;
50 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, GetNextQuestionValueTest);
51 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, NewGroupTest);
52
53 // Users are randomly assigned to one of kMaxGroupSize + 1 buckets, in order
54 // to be able to roll out promos slowly, or display different promos to
55 // different groups.
56 static const int kMaxGroupSize = 99;
57 static const int kMaxViews = 1000;
58
59 // Parse the answers array element.
Miranda Callahan 2011/09/27 09:18:40 Can you add to the comment to indicate that this f
achuithb 2011/09/28 01:40:14 Done.
60 void Parse(const base::DictionaryValue* dict);
61
62 // Set promo notification params from a question string, which is of the form
63 // <build_type>:<time_slice>:<max_group>:<max_views>
64 void GetParams(const base::DictionaryValue* dict);
65
66 // Check if this promo notification is new based on start/end times,
67 // and trigger events accordingly.
68 void CheckForNewNotification();
69
70 // Actions on receiving a new promo notification.
71 void OnNewNotification();
72
73 // Create a new promo notification group.
74 static int NewGroup();
75
76 // Parses question string.
Miranda Callahan 2011/09/27 09:18:40 Could you indicate in the comment that this method
achuithb 2011/09/28 01:40:14 Done.
77 static int GetNextQuestionValue(const std::string& question,
78 size_t* index,
79 bool* err);
80
81 static bool OutOfBounds(int var, int min, int max);
82
83 // Time getters.
84 static double GetTimeFromDict(const base::DictionaryValue* dict);
85 static double GetTimeFromString(const std::string& time_str);
86 double GetTimeFromPrefs(const char* pref) const;
87
88 // Flush data members to prefs for storage.
89 void WritePrefs();
90
91 // Match our channel with specified build type.
92 bool IsBuildAllowed(int builds_allowed) const;
93
94 // For testing.
95 bool operator==(const PromoNotification& other) const;
96
97 PrefService* prefs_;
98 Delegate* delegate_;
99
100 double start_;
101 double end_;
102
103 int build_;
104 int time_slice_;
105 int max_group_;
106 int max_views_;
107
108 int group_;
109 int views_;
110 std::string text_;
111 bool closed_;
112
113 DISALLOW_COPY_AND_ASSIGN(PromoNotification);
114 };
115
116 #endif // CHROME_BROWSER_WEB_RESOURCE_PROMO_NOTIFICATION_H_
117
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698