Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / web_resource / notification_promo.h
blob9b3ee452fda56ac3b9bddfc87bb8691eff87d029
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_WEB_RESOURCE_NOTIFICATION_PROMO_H_
6 #define CHROME_BROWSER_WEB_RESOURCE_NOTIFICATION_PROMO_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/gtest_prod_util.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "url/gurl.h"
16 class PrefRegistrySimple;
17 class PrefService;
19 namespace base {
20 class DictionaryValue;
21 class ListValue;
24 namespace user_prefs {
25 class PrefRegistrySyncable;
28 // Helper class for PromoResourceService that parses promo notification info
29 // from json or prefs.
30 class NotificationPromo {
31 public:
32 static GURL PromoServerURL();
34 enum PromoType {
35 NO_PROMO,
36 NTP_NOTIFICATION_PROMO,
37 NTP_BUBBLE_PROMO,
38 MOBILE_NTP_SYNC_PROMO,
41 NotificationPromo();
42 ~NotificationPromo();
44 // Initialize from json/prefs.
45 void InitFromJson(const base::DictionaryValue& json, PromoType promo_type);
46 void InitFromPrefs(PromoType promo_type);
48 // Can this promo be shown?
49 bool CanShow() const;
51 // Calculates promo notification start time with group-based time slice
52 // offset.
53 double StartTimeForGroup() const;
54 double EndTime() const;
56 // Helpers for NewTabPageHandler.
57 // Mark the promo as closed when the user dismisses it.
58 static void HandleClosed(PromoType promo_type);
59 // Mark the promo has having been viewed. This returns true if views
60 // exceeds the maximum allowed.
61 static bool HandleViewed(PromoType promo_type);
63 bool new_notification() const { return new_notification_; }
65 const std::string& promo_text() const { return promo_text_; }
66 PromoType promo_type() const { return promo_type_; }
67 const base::DictionaryValue* promo_payload() const {
68 return promo_payload_.get();
71 // Register preferences.
72 static void RegisterPrefs(PrefRegistrySimple* registry);
73 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
74 static void MigrateUserPrefs(PrefService* user_prefs);
76 private:
77 // For testing.
78 friend class NotificationPromoTest;
80 // Check if this promo notification is new based on start/end times,
81 // and trigger events accordingly.
82 void CheckForNewNotification();
84 // Actions on receiving a new promo notification.
85 void OnNewNotification();
87 // Flush data members to prefs for storage.
88 void WritePrefs();
90 // Tests group_ against max_group_.
91 // When max_group_ is 0, all groups pass.
92 bool ExceedsMaxGroup() const;
94 // Tests views_ against max_views_.
95 // When max_views_ is 0, we don't cap the number of views.
96 bool ExceedsMaxViews() const;
98 // Returns false if this promo should not be displayed because it is a promo
99 // for the app launcher, and the user has already enabled the app launcher.
100 bool CheckAppLauncher() const;
102 PrefService* prefs_;
104 PromoType promo_type_;
105 std::string promo_text_;
107 scoped_ptr<const base::DictionaryValue> promo_payload_;
109 double start_;
110 double end_;
112 int num_groups_;
113 int initial_segment_;
114 int increment_;
115 int time_slice_;
116 int max_group_;
118 // When max_views_ is 0, we don't cap the number of views.
119 int max_views_;
121 int group_;
122 int views_;
123 bool closed_;
125 bool new_notification_;
127 DISALLOW_COPY_AND_ASSIGN(NotificationPromo);
130 #endif // CHROME_BROWSER_WEB_RESOURCE_NOTIFICATION_PROMO_H_