Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add an is_app_launcher_promo key to NotificationPromo.

If the "is_app_launcher_promo" key is set in the promo payload, the promo won't be shown if the user has enabled the app launcher. Which is useful if the promo is asking the user to enable the app launcher :)

R=rsesek@chromium.org
BUG=178936


Review URL: https://chromiumcodereview.appspot.com/12601014

git-svn-id: http://src.chromium.org/svn/trunk/src/chrome/browser@189193 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
  • Loading branch information...
commit bb380b5e069de3f15fcf21aa8de9a29aa9a1a079 1 parent d8cedbc
jeremya@chromium.org authored
View
11 web_resource/notification_promo.cc
@@ -7,6 +7,7 @@
#include <cmath>
#include <vector>
+#include "apps/pref_names.h"
#include "base/bind.h"
#include "base/prefs/pref_registry_simple.h"
#include "base/prefs/pref_service.h"
@@ -395,11 +396,21 @@ void NotificationPromo::InitFromPrefs(PromoType promo_type) {
ntp_promo->GetBoolean(kPrefPromoClosed, &closed_);
}
+bool NotificationPromo::CheckAppLauncher() const {
+ bool is_app_launcher_promo = false;
+ if (!promo_payload_->GetBoolean("is_app_launcher_promo",
+ &is_app_launcher_promo))
+ return true;
+ return !is_app_launcher_promo ||
+ !prefs_->GetBoolean(apps::prefs::kAppLauncherIsEnabled);
+}
+
bool NotificationPromo::CanShow() const {
return !closed_ &&
!promo_text_.empty() &&
!ExceedsMaxGroup() &&
!ExceedsMaxViews() &&
+ CheckAppLauncher() &&
base::Time::FromDoubleT(StartTimeForGroup()) < base::Time::Now() &&
base::Time::FromDoubleT(EndTime()) > base::Time::Now();
}
View
5 web_resource/notification_promo.h
@@ -92,12 +92,15 @@ class NotificationPromo {
// When max_views_ is 0, we don't cap the number of views.
bool ExceedsMaxViews() const;
+ // Returns false if this promo should not be displayed because it is a promo
+ // for the app launcher, and the user has already enabled the app launcher.
+ bool CheckAppLauncher() const;
+
PrefService* prefs_;
PromoType promo_type_;
std::string promo_text_;
- // Note that promo_payload_ isn't currently used for desktop promos.
scoped_ptr<const base::DictionaryValue> promo_payload_;
double start_;
View
49 web_resource/promo_resource_service_unittest.cc
@@ -5,6 +5,7 @@
#include <utility>
#include <vector>
+#include "apps/pref_names.h"
#include "base/json/json_reader.h"
#include "base/message_loop.h"
#include "base/prefs/pref_service.h"
@@ -334,6 +335,8 @@ class NotificationPromoTest {
EXPECT_TRUE(notification_promo_.CanShow());
}
+ const NotificationPromo& promo() const { return notification_promo_; }
+
private:
NotificationPromo notification_promo_;
bool received_notification_;
@@ -530,3 +533,49 @@ TEST_F(PromoResourceServiceTest, PromoServerURLTest) {
EXPECT_TRUE(promo_server_url.SchemeIs(chrome::kHttpsScheme));
// TODO(achuith): Test this better.
}
+
+TEST_F(PromoResourceServiceTest, AppLauncherPromoTest) {
+ // Check that prefs are set correctly.
+ NotificationPromoTest promo_test;
+
+ // Set up start date and promo line in a Dictionary as if parsed from the
+ // service. date[0].end is replaced with a date 1 year in the future.
+ promo_test.Init("{"
+ " \"ntp_notification_promo\": ["
+ " {"
+ " \"date\":"
+ " ["
+ " {"
+ " \"start\":\"3 Aug 1999 9:26:06 GMT\","
+ " \"end\":\"$1\""
+ " }"
+ " ],"
+ " \"grouping\":"
+ " {"
+ " \"buckets\":1000,"
+ " \"segment\":200,"
+ " \"increment\":100,"
+ " \"increment_frequency\":3600,"
+ " \"increment_max\":400"
+ " },"
+ " \"payload\":"
+ " {"
+ " \"promo_message_short\":"
+ " \"What do you think of Chrome?\","
+ " \"days_active\":7,"
+ " \"install_age_days\":21,"
+ " \"is_app_launcher_promo\":true"
+ " },"
+ " \"max_views\":30"
+ " }"
+ " ]"
+ "}",
+ "What do you think of Chrome?",
+ // The starting date is in 1999 to make tests pass
+ // on Android devices with incorrect or unset date/time.
+ 933672366, // unix epoch for 3 Aug 1999 9:26:06 GMT.
+ 1000, 200, 100, 3600, 400, 30);
+ promo_test.InitPromoFromJson(true);
+ local_state_.Get()->SetBoolean(apps::prefs::kAppLauncherIsEnabled, true);
+ EXPECT_FALSE(promo_test.promo().CanShow());
+}
Please sign in to comment.
Something went wrong with that request. Please try again.