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

Unified Diff: chrome/browser/web_resource/promo_notification.h

Issue 8045012: NotificationPromo (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: rebase Created 9 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/web_resource/promo_notification.h
===================================================================
--- chrome/browser/web_resource/promo_notification.h (revision 0)
+++ chrome/browser/web_resource/promo_notification.h (revision 0)
@@ -0,0 +1,117 @@
+// Copyright (c) 2011 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_WEB_RESOURCE_PROMO_NOTIFICATION_H_
+#define CHROME_BROWSER_WEB_RESOURCE_PROMO_NOTIFICATION_H_
+#pragma once
Dan Beam 2011/09/27 03:27:55 Why are you using this ^, exactly? Shouldn't a he
achuithb 2011/09/27 08:03:19 You're supposed to use it: http://dev.chromium.org
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/gtest_prod_util.h"
+
+namespace base {
+ class DictionaryValue;
+}
+
+class PrefService;
+
+// Helper class for PromoResourceService that parses promo notification info
+// from json or prefs.
+class PromoNotification {
+ public:
+ class Delegate {
+ public:
+ virtual ~Delegate() {}
+ virtual void OnNewNotification(double start, double end) = 0;
+ // For testing.
+ virtual bool IsBuildAllowed(int builds_targeted) const { return false; }
+ };
+
+ explicit PromoNotification(PrefService* prefs, Delegate* delegate);
+
+ // Initialize from json/prefs.
+ void InitFromJson(const base::DictionaryValue& json);
+ void InitFromPrefs();
+
+ // Can this promo be shown?
+ bool CanShow() const;
+
+ static void RegisterUserPrefs(PrefService* prefs);
+
+ // Calculates promo notification start time with group-based time slice
+ // offset.
+ double StartTimeWithOffset() const;
+
+ private:
+ // For testing.
+ friend class PromoNotificationTestDelegate;
+ FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, GetNextQuestionValueTest);
+ FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, NewGroupTest);
+
+ // Users are randomly assigned to one of kMaxGroupSize + 1 buckets, in order
+ // to be able to roll out promos slowly, or display different promos to
+ // different groups.
+ static const int kMaxGroupSize = 99;
+ static const int kMaxViews = 1000;
Miranda Callahan 2011/09/27 09:18:40 Can you add a comment for kMaxViews as well?
+
+ // Parse the answers array element.
+ void Parse(const base::DictionaryValue* dict);
+
+ // Set promo notification params from a question string, which is of the form
+ // <build_type>:<time_slice>:<max_group>:<max_views>
+ void GetParams(const base::DictionaryValue* dict);
+
+ // Check if this promo notification is new based on start/end times,
+ // and trigger events accordingly.
+ void CheckForNewNotification();
+
+ // Actions on receiving a new promo notification.
+ void OnNewNotification();
+
+ // Create a new promo notification group.
+ static int NewGroup();
+
+ // Parses question string.
+ static int GetNextQuestionValue(const std::string& question,
+ size_t* index,
+ bool* err);
+
+ static bool OutOfBounds(int var, int min, int max);
+
+ // Time getters.
+ static double GetTimeFromDict(const base::DictionaryValue* dict);
+ static double GetTimeFromString(const std::string& time_str);
+ double GetTimeFromPrefs(const char* pref) const;
Dan Beam 2011/09/27 03:27:55 Should these be returning Times or doubles? I gue
achuithb 2011/09/27 08:03:19 start_ and end_ are stored as doubles (because the
+
+ // Flush data members to prefs for storage.
+ void WritePrefs();
+
+ // Match our channel with specified build type.
+ bool IsBuildAllowed(int builds_allowed) const;
+
+ // For testing.
+ bool operator==(const PromoNotification& other) const;
+
+ PrefService* prefs_;
+ Delegate* delegate_;
+
+ double start_;
+ double end_;
+
+ int build_;
+ int time_slice_;
+ int max_group_;
+ int max_views_;
+
+ int group_;
+ int views_;
+ std::string text_;
+ bool closed_;
+
+ DISALLOW_COPY_AND_ASSIGN(PromoNotification);
+};
+
+#endif // CHROME_BROWSER_WEB_RESOURCE_PROMO_NOTIFICATION_H_
+
Property changes on: chrome/browser/web_resource/promo_notification.h
___________________________________________________________________
Added: svn:eol-style
+ LF

Powered by Google App Engine
This is Rietveld 408576698