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

Side by Side Diff: chrome/browser/web_resource/promo_resource_service.cc

Issue 10860025: Remove promotion-type-specific JSON handling from NotificationPromo (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase. Created 8 years, 4 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 unified diff | Download patch
OLDNEW
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"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/prefs/pref_service.h" 13 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/common/chrome_notification_types.h" 15 #include "chrome/common/chrome_notification_types.h"
16 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
18 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/notification_service.h" 19 #include "content/public/browser/notification_service.h"
20 #include "googleurl/src/gurl.h" 20 #include "googleurl/src/gurl.h"
21 21
22 namespace { 22 namespace {
23 23
24 // Delay on first fetch so we don't interfere with startup. 24 // Delay on first fetch so we don't interfere with startup.
25 static const int kStartResourceFetchDelay = 5000; 25 static const int kStartResourceFetchDelay = 5000;
26 26
27 // Delay between calls to update the cache (12h), and 10s in debug mode. 27 // Delay between calls to update the cache (12 hours), and 3 min in debug mode.
28 static const int kCacheUpdateDelay = 12 * 60 * 60 * 1000; 28 static const int kCacheUpdateDelay = 12 * 60 * 60 * 1000;
29 static const int kTestCacheUpdateDelay = 10 * 1000; 29 static const int kTestCacheUpdateDelay = 3 * 60 * 1000;
30 30
31 // The version of the service (used to expire the cache when upgrading Chrome 31 // The version of the service (used to expire the cache when upgrading Chrome
32 // to versions with different types of promos). 32 // to versions with different types of promos).
33 static const int kPromoServiceVersion = 7; 33 static const int kPromoServiceVersion = 7;
34 34
35 GURL GetPromoResourceURL() { 35 GURL GetPromoResourceURL() {
36 const std::string promo_server_url = CommandLine::ForCurrentProcess()-> 36 const std::string promo_server_url = CommandLine::ForCurrentProcess()->
37 GetSwitchValueASCII(switches::kPromoServerURL); 37 GetSwitchValueASCII(switches::kPromoServerURL);
38 return promo_server_url.empty() ? 38 return promo_server_url.empty() ?
39 NotificationPromo::PromoServerURL() : GURL(promo_server_url); 39 NotificationPromo::PromoServerURL() : GURL(promo_server_url);
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 } 173 }
174 174
175 std::string PromoResourceService::GetPromoLocale() { 175 std::string PromoResourceService::GetPromoLocale() {
176 PrefService* local_state = g_browser_process->local_state(); 176 PrefService* local_state = g_browser_process->local_state();
177 return local_state->GetString(prefs::kNtpPromoLocale); 177 return local_state->GetString(prefs::kNtpPromoLocale);
178 } 178 }
179 179
180 void PromoResourceService::Unpack(const DictionaryValue& parsed_json) { 180 void PromoResourceService::Unpack(const DictionaryValue& parsed_json) {
181 NotificationPromo notification_promo(profile_); 181 NotificationPromo notification_promo(profile_);
182 NotificationPromo::PromoType promo_type = 182 NotificationPromo::PromoType promo_type =
183 #if !defined(OS_ANDROID) 183 #if defined(OS_ANDROID) || defined(OS_IOS)
184 NotificationPromo::MOBILE_NTP_SYNC_PROMO;
185 #else
184 NotificationPromo::NTP_NOTIFICATION_PROMO; 186 NotificationPromo::NTP_NOTIFICATION_PROMO;
185 #else
186 NotificationPromo::MOBILE_NTP_SYNC_PROMO;
187 #endif 187 #endif
188 notification_promo.InitFromJson(parsed_json, promo_type); 188 notification_promo.InitFromJson(parsed_json, promo_type);
189 189
190 if (notification_promo.new_notification()) { 190 if (notification_promo.new_notification()) {
191 ScheduleNotification(notification_promo.StartTimeForGroup(), 191 ScheduleNotification(notification_promo.StartTimeForGroup(),
192 notification_promo.EndTime()); 192 notification_promo.EndTime());
193 } 193 }
194 } 194 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698