1 // Copyright (c) 2010 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_INSTANT_PROMO_COUNTER_H_ 6 #define CHROME_BROWSER_INSTANT_PROMO_COUNTER_H_ 7 #pragma once 8 9 #include <string> 10 11 #include "base/basictypes.h" 12 #include "base/time.h" 13 14 class PrefService; 15 class Profile; 16 17 // PromoCounter is used to track whether a promo should be shown. The promo is 18 // shown for a specified number of days or sessions (launches of chrome). 19 class PromoCounter { 20 public: 21 // Creates a new PromoCounter. |pref_key| is used to store prefs related to 22 // the promo. |histogram_key| is the key used to store histograms related to 23 // the promo. See the .cc file for the exact prefs and histogram values used. 24 // |ShouldShow| returns true until the users restarts chrome |max_sessions| or 25 // runs Chrome for |max_days|, or |Hide| is invoked. 26 PromoCounter(Profile* profile, 27 const std::string& pref_key, 28 const std::string& histogram_key, 29 int max_sessions, 30 int max_days); 31 ~PromoCounter(); 32 33 // Registers the preferences used by PromoCounter. 34 static void RegisterUserPrefs(PrefService* prefs, 35 const std::string& base_key); 36 37 // Returns true if the promo should be shown. 38 bool ShouldShow(base::Time current_time); 39 40 // Permanently hides the promo. 41 void Hide(); 42 43 private: 44 // Called the first time ShouldShow is invoked. Updates the necessary pref 45 // state and show_. 46 void Init(base::Time current_time); 47 48 // Invoked if the max number of sessions has been encountered. 49 void MaxSessionsEncountered(base::Time current_time); 50 51 // Invoked if the max number of days has elapsed. 52 void MaxTimeLapsed(base::Time current_time); 53 54 Profile* profile_; 55 56 // Base key all prefs are stored under. 57 const std::string pref_key_; 58 59 // Base key used for histograms. 60 const std::string histogram_key_; 61 62 // Max number of sessions/days before the promo stops. 63 const int max_sessions_; 64 const int max_days_; 65 66 // Has Init been invoked? 67 bool did_init_; 68 69 // Return value from ShouldShow. 70 bool show_; 71 72 // Initial time the promo was first shown. 73 base::Time initial_show_; 74 75 DISALLOW_COPY_AND_ASSIGN(PromoCounter); 76 }; 77 78 #endif // CHROME_BROWSER_INSTANT_PROMO_COUNTER_H_ 79