| 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/location.h" | 9 #include "base/location.h" |
| 10 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 registry->RegisterStringPref(prefs::kNtpPromoResourceCacheUpdate, "0"); | 75 registry->RegisterStringPref(prefs::kNtpPromoResourceCacheUpdate, "0"); |
| 76 NotificationPromo::RegisterProfilePrefs(registry); | 76 NotificationPromo::RegisterProfilePrefs(registry); |
| 77 } | 77 } |
| 78 | 78 |
| 79 // static | 79 // static |
| 80 void PromoResourceService::MigrateUserPrefs(PrefService* user_prefs) { | 80 void PromoResourceService::MigrateUserPrefs(PrefService* user_prefs) { |
| 81 user_prefs->ClearPref(prefs::kNtpPromoResourceCacheUpdate); | 81 user_prefs->ClearPref(prefs::kNtpPromoResourceCacheUpdate); |
| 82 NotificationPromo::MigrateUserPrefs(user_prefs); | 82 NotificationPromo::MigrateUserPrefs(user_prefs); |
| 83 } | 83 } |
| 84 | 84 |
| 85 PromoResourceService::PromoResourceService(PrefService* local_state, | 85 PromoResourceService::PromoResourceService( |
| 86 version_info::Channel channel) | 86 PrefService* local_state, |
| 87 : ChromeWebResourceService(local_state, | 87 version_info::Channel channel, |
| 88 GetPromoResourceURL(channel), | 88 const std::string& application_locale, |
| 89 true, // append locale to URL | 89 net::URLRequestContextGetter* request_context, |
| 90 prefs::kNtpPromoResourceCacheUpdate, | 90 const char* disable_network_switch, |
| 91 kStartResourceFetchDelay, | 91 const ParseJSONCallback& parse_json_callback) |
| 92 GetCacheUpdateDelay()), | 92 : web_resource::WebResourceService( |
| 93 local_state, |
| 94 GetPromoResourceURL(channel), |
| 95 application_locale, // append locale to URL |
| 96 prefs::kNtpPromoResourceCacheUpdate, |
| 97 kStartResourceFetchDelay, |
| 98 GetCacheUpdateDelay(), |
| 99 request_context, |
| 100 disable_network_switch, |
| 101 parse_json_callback), |
| 93 weak_ptr_factory_(this) { | 102 weak_ptr_factory_(this) { |
| 94 ScheduleNotificationOnInit(); | 103 ScheduleNotificationOnInit(); |
| 95 } | 104 } |
| 96 | 105 |
| 97 PromoResourceService::~PromoResourceService() { | 106 PromoResourceService::~PromoResourceService() { |
| 98 } | 107 } |
| 99 | 108 |
| 100 scoped_ptr<PromoResourceService::StateChangedSubscription> | 109 scoped_ptr<PromoResourceService::StateChangedSubscription> |
| 101 PromoResourceService::RegisterStateChangedCallback( | 110 PromoResourceService::RegisterStateChangedCallback( |
| 102 const base::Closure& closure) { | 111 const base::Closure& closure) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 } | 176 } |
| 168 | 177 |
| 169 void PromoResourceService::Unpack(const base::DictionaryValue& parsed_json) { | 178 void PromoResourceService::Unpack(const base::DictionaryValue& parsed_json) { |
| 170 for (size_t i = 0; i < arraysize(kValidPromoTypes); ++i) { | 179 for (size_t i = 0; i < arraysize(kValidPromoTypes); ++i) { |
| 171 NotificationPromo notification_promo(prefs_); | 180 NotificationPromo notification_promo(prefs_); |
| 172 notification_promo.InitFromJson(parsed_json, kValidPromoTypes[i]); | 181 notification_promo.InitFromJson(parsed_json, kValidPromoTypes[i]); |
| 173 if (notification_promo.new_notification()) | 182 if (notification_promo.new_notification()) |
| 174 ScheduleNotification(notification_promo); | 183 ScheduleNotification(notification_promo); |
| 175 } | 184 } |
| 176 } | 185 } |
| OLD | NEW |