Index: chrome/browser/web_resource/notification_promo.cc |
diff --git a/chrome/browser/web_resource/notification_promo.cc b/chrome/browser/web_resource/notification_promo.cc |
index 692d305233835fd197ddc18b0cfb9250ebe989ff..caa83fe292bfd52752570d24288bc54535328a00 100644 |
--- a/chrome/browser/web_resource/notification_promo.cc |
+++ b/chrome/browser/web_resource/notification_promo.cc |
@@ -12,10 +12,12 @@ |
#include "base/string_number_conversions.h" |
#include "base/string_util.h" |
#include "base/sys_info.h" |
+#include "base/threading/thread_restrictions.h" |
#include "base/time.h" |
#include "base/values.h" |
#include "chrome/browser/prefs/pref_service.h" |
-#include "chrome/browser/profiles/profile_impl.h" |
+#include "chrome/browser/prefs/pref_service_simple.h" |
+#include "chrome/browser/prefs/pref_service_syncable.h" |
#include "chrome/browser/web_resource/promo_resource_service.h" |
#include "chrome/common/chrome_version_info.h" |
#include "chrome/common/net/url_util.h" |
@@ -53,7 +55,6 @@ const char kPrefPromoMaxViews[] = "max_views"; |
const char kPrefPromoGroup[] = "group"; |
const char kPrefPromoViews[] = "views"; |
const char kPrefPromoClosed[] = "closed"; |
-const char kPrefPromoGPlusRequired[] = "gplus_required"; |
// Returns a string suitable for the Promo Server URL 'osname' value. |
std::string PlatformString() { |
@@ -189,9 +190,8 @@ void AppendQueryParameter(GURL* url, |
} // namespace |
-NotificationPromo::NotificationPromo(Profile* profile) |
- : profile_(profile), |
- prefs_(profile_->GetPrefs()), |
+NotificationPromo::NotificationPromo(PrefServiceSimple* prefs) |
+ : prefs_(prefs), |
promo_type_(NO_PROMO), |
promo_payload_(new base::DictionaryValue()), |
start_(0.0), |
@@ -205,9 +205,7 @@ NotificationPromo::NotificationPromo(Profile* profile) |
group_(0), |
views_(0), |
closed_(false), |
- gplus_required_(false), |
new_notification_(false) { |
- DCHECK(profile); |
DCHECK(prefs_); |
} |
@@ -271,9 +269,6 @@ void NotificationPromo::InitFromJson(const DictionaryValue& json, |
// Payload. |
const DictionaryValue* payload = NULL; |
if (promo->GetDictionary("payload", &payload)) { |
- payload->GetBoolean("gplus_required", &gplus_required_); |
- DVLOG(1) << "gplus_required_ = " << gplus_required_; |
- |
base::Value* ppcopy = DeepCopyAndResolveStrings(payload, strings); |
DCHECK(ppcopy && ppcopy->IsType(base::Value::TYPE_DICTIONARY)); |
promo_payload_.reset(static_cast<base::DictionaryValue*>(ppcopy)); |
@@ -296,7 +291,7 @@ void NotificationPromo::InitFromJson(const DictionaryValue& json, |
} |
void NotificationPromo::CheckForNewNotification() { |
- NotificationPromo old_promo(profile_); |
+ NotificationPromo old_promo(prefs_); |
old_promo.InitFromPrefs(promo_type_); |
const double old_start = old_promo.start_; |
const double old_end = old_promo.end_; |
@@ -316,10 +311,18 @@ void NotificationPromo::OnNewNotification() { |
} |
// static |
+void NotificationPromo::RegisterPrefs(PrefServiceSimple* local_state) { |
+ local_state->RegisterDictionaryPref(kPrefPromoObject, |
+ new base::DictionaryValue); |
Bernhard Bauer
2012/12/31 11:51:52
Nit: an empty dictionary is the default value for
Dan Beam
2013/01/02 04:36:35
OK, should I remove it from the below user pref re
Bernhard Bauer
2013/01/02 10:57:44
Please and thank you! :)
Dan Beam
2013/01/02 22:27:51
Done.
|
+} |
+ |
+// static |
void NotificationPromo::RegisterUserPrefs(PrefServiceSyncable* prefs) { |
+ // TODO(dbeam): Remove in M28 when we're reasonably sure all prefs are gone. |
prefs->RegisterDictionaryPref(kPrefPromoObject, |
new base::DictionaryValue, |
PrefServiceSyncable::UNSYNCABLE_PREF); |
+ prefs->ClearPref(kPrefPromoObject); |
} |
void NotificationPromo::WritePrefs() { |
@@ -341,8 +344,6 @@ void NotificationPromo::WritePrefs() { |
ntp_promo->SetInteger(kPrefPromoViews, views_); |
ntp_promo->SetBoolean(kPrefPromoClosed, closed_); |
- ntp_promo->SetBoolean(kPrefPromoGPlusRequired, gplus_required_); |
- |
base::ListValue* promo_list = new base::ListValue; |
promo_list->Set(0, ntp_promo); // Only support 1 promo for now. |
@@ -389,8 +390,6 @@ void NotificationPromo::InitFromPrefs(PromoType promo_type) { |
ntp_promo->GetInteger(kPrefPromoGroup, &group_); |
ntp_promo->GetInteger(kPrefPromoViews, &views_); |
ntp_promo->GetBoolean(kPrefPromoClosed, &closed_); |
- |
- ntp_promo->GetBoolean(kPrefPromoGPlusRequired, &gplus_required_); |
} |
bool NotificationPromo::CanShow() const { |
@@ -399,14 +398,14 @@ bool NotificationPromo::CanShow() const { |
!ExceedsMaxGroup() && |
!ExceedsMaxViews() && |
base::Time::FromDoubleT(StartTimeForGroup()) < base::Time::Now() && |
- base::Time::FromDoubleT(EndTime()) > base::Time::Now() && |
- IsGPlusRequired(); |
+ base::Time::FromDoubleT(EndTime()) > base::Time::Now(); |
} |
// static |
-void NotificationPromo::HandleClosed(Profile* profile, PromoType promo_type) { |
+void NotificationPromo::HandleClosed(PrefServiceSimple* prefs, |
+ PromoType promo_type) { |
content::RecordAction(UserMetricsAction("NTPPromoClosed")); |
- NotificationPromo promo(profile); |
+ NotificationPromo promo(prefs); |
promo.InitFromPrefs(promo_type); |
if (!promo.closed_) { |
promo.closed_ = true; |
@@ -415,9 +414,10 @@ void NotificationPromo::HandleClosed(Profile* profile, PromoType promo_type) { |
} |
// static |
-bool NotificationPromo::HandleViewed(Profile* profile, PromoType promo_type) { |
+bool NotificationPromo::HandleViewed(PrefServiceSimple* prefs, |
+ PromoType promo_type) { |
content::RecordAction(UserMetricsAction("NTPPromoShown")); |
- NotificationPromo promo(profile); |
+ NotificationPromo promo(prefs); |
promo.InitFromPrefs(promo_type); |
++promo.views_; |
promo.WritePrefs(); |
@@ -432,10 +432,6 @@ bool NotificationPromo::ExceedsMaxViews() const { |
return (max_views_ == 0) ? false : views_ >= max_views_; |
} |
-bool NotificationPromo::IsGPlusRequired() const { |
- return !gplus_required_ || prefs_->GetBoolean(prefs::kIsGooglePlusUser); |
-} |
- |
// static |
GURL NotificationPromo::PromoServerURL() { |
GURL url(promo_server_url); |