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

Unified Diff: chrome/browser/web_resource/promo_resource_service.cc

Issue 11689004: Move PromoResourceService from Profile to BrowserProcessImpl/local_state(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 7 years, 12 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_resource_service.cc
diff --git a/chrome/browser/web_resource/promo_resource_service.cc b/chrome/browser/web_resource/promo_resource_service.cc
index ad4c185dae5b128acc71c6dec211bfb9c37d61c9..f8f3ef149eeba7ccc983766e146663a5d4c81cba 100644
--- a/chrome/browser/web_resource/promo_resource_service.cc
+++ b/chrome/browser/web_resource/promo_resource_service.cc
@@ -11,7 +11,8 @@
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/prefs/pref_service.h"
-#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/prefs/pref_service_simple.h"
+#include "chrome/browser/prefs/pref_service_syncable.h"
#include "chrome/browser/web_resource/notification_promo.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h"
@@ -34,7 +35,7 @@ const int kTestCacheUpdateDelay = 3 * 60 * 1000;
// to versions with different types of promos).
const int kPromoServiceVersion = 7;
-// The promotion type used for Unpack() and ScheduleNotificationOnInit.
+// The promotion type used for Unpack() and ScheduleNotificationOnInit().
const NotificationPromo::PromoType kValidPromoTypes[] = {
#if defined(OS_ANDROID) || defined(OS_IOS)
NotificationPromo::MOBILE_NTP_SYNC_PROMO,
@@ -63,32 +64,27 @@ int GetCacheUpdateDelay() {
// static
void PromoResourceService::RegisterPrefs(PrefServiceSimple* local_state) {
- // TODO(achuith): Delete this in M26. http://crbug.com/143773
- // The promo service version number, and last locale.
- const char kNtpPromoVersion[] = "ntp.promo_version";
- const char kNtpPromoLocale[] = "ntp.promo_locale";
- local_state->RegisterIntegerPref(kNtpPromoVersion, 0);
- local_state->RegisterStringPref(kNtpPromoLocale, std::string());
- local_state->ClearPref(kNtpPromoVersion);
- local_state->ClearPref(kNtpPromoLocale);
+ local_state->RegisterStringPref(prefs::kNtpPromoResourceCacheUpdate, "0");
+ NotificationPromo::RegisterPrefs(local_state);
}
// static
void PromoResourceService::RegisterUserPrefs(PrefServiceSyncable* prefs) {
+ // TODO(dbeam): remove in M28 when all prefs have been cleared.
prefs->RegisterStringPref(prefs::kNtpPromoResourceCacheUpdate,
"0",
PrefServiceSyncable::UNSYNCABLE_PREF);
+ prefs->ClearPref(prefs::kNtpPromoResourceCacheUpdate);
NotificationPromo::RegisterUserPrefs(prefs);
}
-PromoResourceService::PromoResourceService(Profile* profile)
- : WebResourceService(profile->GetPrefs(),
+PromoResourceService::PromoResourceService()
+ : WebResourceService(g_browser_process->local_state(),
GetPromoResourceURL(),
true, // append locale to URL
prefs::kNtpPromoResourceCacheUpdate,
kStartResourceFetchDelay,
GetCacheUpdateDelay()),
- profile_(profile),
ALLOW_THIS_IN_INITIALIZER_LIST(
weak_ptr_factory_(this)) {
ScheduleNotificationOnInit();
@@ -97,6 +93,30 @@ PromoResourceService::PromoResourceService(Profile* profile)
PromoResourceService::~PromoResourceService() {
}
+// For testing.
Evan Stade 2013/01/03 05:01:08 put this comment in the header only.
+PromoResourceService::PromoResourceService(PrefService* prefs)
+ : WebResourceService(prefs,
+ GetPromoResourceURL(),
+ true, // append locale to URL
+ prefs::kNtpPromoResourceCacheUpdate,
+ kStartResourceFetchDelay,
+ GetCacheUpdateDelay()),
+ ALLOW_THIS_IN_INITIALIZER_LIST(
+ weak_ptr_factory_(this)) {
+ ScheduleNotificationOnInitForTesting(prefs);
Dan Beam 2013/01/03 05:05:47 this is triggering a presubmit warning, I'll see i
achuithb 2013/01/03 05:42:51 This particular presubmit warning is not reliable,
+}
+
+void PromoResourceService::ScheduleNotificationOnInitForTesting(
+ PrefService* prefs) {
+ // If the promo start is in the future, set a notification task to
+ // invalidate the NTP cache at the time of the promo start.
+ for (size_t i = 0; i < arraysize(kValidPromoTypes); ++i) {
+ NotificationPromo notification_promo(prefs);
+ notification_promo.InitFromPrefs(kValidPromoTypes[i]);
+ ScheduleNotification(notification_promo);
+ }
+}
+
void PromoResourceService::ScheduleNotification(
const NotificationPromo& notification_promo) {
const double promo_start = notification_promo.StartTimeForGroup();
@@ -133,7 +153,7 @@ void PromoResourceService::ScheduleNotificationOnInit() {
// If the promo start is in the future, set a notification task to
// invalidate the NTP cache at the time of the promo start.
for (size_t i = 0; i < arraysize(kValidPromoTypes); ++i) {
- NotificationPromo notification_promo(profile_);
+ NotificationPromo notification_promo;
notification_promo.InitFromPrefs(kValidPromoTypes[i]);
ScheduleNotification(notification_promo);
}
@@ -167,7 +187,7 @@ void PromoResourceService::PromoResourceStateChange() {
void PromoResourceService::Unpack(const DictionaryValue& parsed_json) {
for (size_t i = 0; i < arraysize(kValidPromoTypes); ++i) {
- NotificationPromo notification_promo(profile_);
+ NotificationPromo notification_promo;
notification_promo.InitFromJson(parsed_json, kValidPromoTypes[i]);
if (notification_promo.new_notification())
ScheduleNotification(notification_promo);

Powered by Google App Engine
This is Rietveld 408576698