| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/web_resource/promo_resource_service.h" | 5 #include "chrome/browser/web_resource/promo_resource_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kPromoServerURL); | 55 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kPromoServerURL); |
| 56 } | 56 } |
| 57 | 57 |
| 58 int GetCacheUpdateDelay() { | 58 int GetCacheUpdateDelay() { |
| 59 return IsTest() ? kTestCacheUpdateDelay : kCacheUpdateDelay; | 59 return IsTest() ? kTestCacheUpdateDelay : kCacheUpdateDelay; |
| 60 } | 60 } |
| 61 | 61 |
| 62 } // namespace | 62 } // namespace |
| 63 | 63 |
| 64 // static | 64 // static |
| 65 void PromoResourceService::RegisterPrefs(PrefService* local_state) { | 65 void PromoResourceService::RegisterPrefs(PrefServiceSimple* local_state) { |
| 66 // TODO(achuith): Delete this in M26. http://crbug.com/143773 | 66 // TODO(achuith): Delete this in M26. http://crbug.com/143773 |
| 67 // The promo service version number, and last locale. | 67 // The promo service version number, and last locale. |
| 68 const char kNtpPromoVersion[] = "ntp.promo_version"; | 68 const char kNtpPromoVersion[] = "ntp.promo_version"; |
| 69 const char kNtpPromoLocale[] = "ntp.promo_locale"; | 69 const char kNtpPromoLocale[] = "ntp.promo_locale"; |
| 70 local_state->RegisterIntegerPref(kNtpPromoVersion, 0); | 70 local_state->RegisterIntegerPref(kNtpPromoVersion, 0); |
| 71 local_state->RegisterStringPref(kNtpPromoLocale, std::string()); | 71 local_state->RegisterStringPref(kNtpPromoLocale, std::string()); |
| 72 local_state->ClearPref(kNtpPromoVersion); | 72 local_state->ClearPref(kNtpPromoVersion); |
| 73 local_state->ClearPref(kNtpPromoLocale); | 73 local_state->ClearPref(kNtpPromoLocale); |
| 74 } | 74 } |
| 75 | 75 |
| 76 // static | 76 // static |
| 77 void PromoResourceService::RegisterUserPrefs(PrefService* prefs) { | 77 void PromoResourceService::RegisterUserPrefs(PrefServiceSyncable* prefs) { |
| 78 prefs->RegisterStringPref(prefs::kNtpPromoResourceCacheUpdate, | 78 prefs->RegisterStringPref(prefs::kNtpPromoResourceCacheUpdate, |
| 79 "0", | 79 "0", |
| 80 PrefService::UNSYNCABLE_PREF); | 80 PrefServiceSyncable::UNSYNCABLE_PREF); |
| 81 NotificationPromo::RegisterUserPrefs(prefs); | 81 NotificationPromo::RegisterUserPrefs(prefs); |
| 82 } | 82 } |
| 83 | 83 |
| 84 PromoResourceService::PromoResourceService(Profile* profile) | 84 PromoResourceService::PromoResourceService(Profile* profile) |
| 85 : WebResourceService(profile->GetPrefs(), | 85 : WebResourceService(profile->GetPrefs(), |
| 86 GetPromoResourceURL(), | 86 GetPromoResourceURL(), |
| 87 true, // append locale to URL | 87 true, // append locale to URL |
| 88 prefs::kNtpPromoResourceCacheUpdate, | 88 prefs::kNtpPromoResourceCacheUpdate, |
| 89 kStartResourceFetchDelay, | 89 kStartResourceFetchDelay, |
| 90 GetCacheUpdateDelay()), | 90 GetCacheUpdateDelay()), |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 } | 166 } |
| 167 | 167 |
| 168 void PromoResourceService::Unpack(const DictionaryValue& parsed_json) { | 168 void PromoResourceService::Unpack(const DictionaryValue& parsed_json) { |
| 169 for (size_t i = 0; i < arraysize(kValidPromoTypes); ++i) { | 169 for (size_t i = 0; i < arraysize(kValidPromoTypes); ++i) { |
| 170 NotificationPromo notification_promo(profile_); | 170 NotificationPromo notification_promo(profile_); |
| 171 notification_promo.InitFromJson(parsed_json, kValidPromoTypes[i]); | 171 notification_promo.InitFromJson(parsed_json, kValidPromoTypes[i]); |
| 172 if (notification_promo.new_notification()) | 172 if (notification_promo.new_notification()) |
| 173 ScheduleNotification(notification_promo); | 173 ScheduleNotification(notification_promo); |
| 174 } | 174 } |
| 175 } | 175 } |
| OLD | NEW |