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

Unified Diff: chrome/browser/instant/promo_counter.h

Issue 5023001: Handful of related instant changes: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix linux build Created 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/instant/instant_opt_in.cc ('k') | chrome/browser/instant/promo_counter.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/instant/promo_counter.h
diff --git a/chrome/browser/instant/promo_counter.h b/chrome/browser/instant/promo_counter.h
new file mode 100644
index 0000000000000000000000000000000000000000..480f67714f3a6cf4b7d3c4faf588df04349203a5
--- /dev/null
+++ b/chrome/browser/instant/promo_counter.h
@@ -0,0 +1,78 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_INSTANT_PROMO_COUNTER_H_
+#define CHROME_BROWSER_INSTANT_PROMO_COUNTER_H_
+#pragma once
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/time.h"
+
+class PrefService;
+class Profile;
+
+// PromoCounter is used to track whether a promo should be shown. The promo is
+// shown for a specified number of days or sessions (launches of chrome).
+class PromoCounter {
+ public:
+ // Creates a new PromoCounter. |pref_key| is used to store prefs related to
+ // the promo. |histogram_key| is the key used to store histograms related to
+ // the promo. See the .cc file for the exact prefs and histogram values used.
+ // |ShouldShow| returns true until the users restarts chrome |max_sessions| or
+ // runs Chrome for |max_days|, or |Hide| is invoked.
+ PromoCounter(Profile* profile,
+ const std::string& pref_key,
+ const std::string& histogram_key,
+ int max_sessions,
+ int max_days);
+ ~PromoCounter();
+
+ // Registers the preferences used by PromoCounter.
+ static void RegisterUserPrefs(PrefService* prefs,
+ const std::string& base_key);
+
+ // Returns true if the promo should be shown.
+ bool ShouldShow(base::Time current_time);
+
+ // Permanently hides the promo.
+ void Hide();
+
+ private:
+ // Called the first time ShouldShow is invoked. Updates the necessary pref
+ // state and show_.
+ void Init(base::Time current_time);
+
+ // Invoked if the max number of sessions has been encountered.
+ void MaxSessionsEncountered(base::Time current_time);
+
+ // Invoked if the max number of days has elapsed.
+ void MaxTimeLapsed(base::Time current_time);
+
+ Profile* profile_;
+
+ // Base key all prefs are stored under.
+ const std::string pref_key_;
+
+ // Base key used for histograms.
+ const std::string histogram_key_;
+
+ // Max number of sessions/days before the promo stops.
+ const int max_sessions_;
+ const int max_days_;
+
+ // Has Init been invoked?
+ bool did_init_;
+
+ // Return value from ShouldShow.
+ bool show_;
+
+ // Initial time the promo was first shown.
+ base::Time initial_show_;
+
+ DISALLOW_COPY_AND_ASSIGN(PromoCounter);
+};
+
+#endif // CHROME_BROWSER_INSTANT_PROMO_COUNTER_H_
« no previous file with comments | « chrome/browser/instant/instant_opt_in.cc ('k') | chrome/browser/instant/promo_counter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698