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" |
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_registry_simple.h" | 13 #include "chrome/browser/prefs/pref_registry_simple.h" |
14 #include "chrome/browser/prefs/pref_service_syncable.h" | 14 #include "chrome/browser/prefs/pref_registry_syncable.h" |
15 #include "chrome/browser/prefs/pref_service.h" | |
15 #include "chrome/browser/web_resource/notification_promo.h" | 16 #include "chrome/browser/web_resource/notification_promo.h" |
16 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
17 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
18 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
19 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
20 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 // Delay on first fetch so we don't interfere with startup. | 25 // Delay on first fetch so we don't interfere with startup. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 | 61 |
61 } // namespace | 62 } // namespace |
62 | 63 |
63 // static | 64 // static |
64 void PromoResourceService::RegisterPrefs(PrefRegistrySimple* registry) { | 65 void PromoResourceService::RegisterPrefs(PrefRegistrySimple* registry) { |
65 registry->RegisterStringPref(prefs::kNtpPromoResourceCacheUpdate, "0"); | 66 registry->RegisterStringPref(prefs::kNtpPromoResourceCacheUpdate, "0"); |
66 NotificationPromo::RegisterPrefs(registry); | 67 NotificationPromo::RegisterPrefs(registry); |
67 } | 68 } |
68 | 69 |
69 // static | 70 // static |
70 void PromoResourceService::RegisterUserPrefs(PrefServiceSyncable* prefs) { | 71 void PromoResourceService::RegisterUserPrefs(PrefService* prefs, |
72 PrefRegistrySyncable* registry) { | |
71 // TODO(dbeam): remove in M28 when all prefs have been cleared. | 73 // TODO(dbeam): remove in M28 when all prefs have been cleared. |
72 // http://crbug.com/168887 | 74 // http://crbug.com/168887 |
73 prefs->RegisterStringPref(prefs::kNtpPromoResourceCacheUpdate, | 75 registry->RegisterStringPref(prefs::kNtpPromoResourceCacheUpdate, |
74 "0", | 76 "0", |
75 PrefServiceSyncable::UNSYNCABLE_PREF); | 77 PrefRegistrySyncable::UNSYNCABLE_PREF); |
76 prefs->ClearPref(prefs::kNtpPromoResourceCacheUpdate); | 78 prefs->ClearPref(prefs::kNtpPromoResourceCacheUpdate); |
Mattias Nissler (ping if slow)
2013/02/06 17:53:33
TODO: move to migration code.
Jói
2013/02/07 14:52:32
Done.
| |
77 NotificationPromo::RegisterUserPrefs(prefs); | 79 NotificationPromo::RegisterUserPrefs(prefs, registry); |
78 } | 80 } |
79 | 81 |
80 PromoResourceService::PromoResourceService() | 82 PromoResourceService::PromoResourceService() |
81 : WebResourceService(g_browser_process->local_state(), | 83 : WebResourceService(g_browser_process->local_state(), |
82 GetPromoResourceURL(), | 84 GetPromoResourceURL(), |
83 true, // append locale to URL | 85 true, // append locale to URL |
84 prefs::kNtpPromoResourceCacheUpdate, | 86 prefs::kNtpPromoResourceCacheUpdate, |
85 kStartResourceFetchDelay, | 87 kStartResourceFetchDelay, |
86 GetCacheUpdateDelay()), | 88 GetCacheUpdateDelay()), |
87 ALLOW_THIS_IN_INITIALIZER_LIST( | 89 ALLOW_THIS_IN_INITIALIZER_LIST( |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 } | 163 } |
162 | 164 |
163 void PromoResourceService::Unpack(const DictionaryValue& parsed_json) { | 165 void PromoResourceService::Unpack(const DictionaryValue& parsed_json) { |
164 for (size_t i = 0; i < arraysize(kValidPromoTypes); ++i) { | 166 for (size_t i = 0; i < arraysize(kValidPromoTypes); ++i) { |
165 NotificationPromo notification_promo; | 167 NotificationPromo notification_promo; |
166 notification_promo.InitFromJson(parsed_json, kValidPromoTypes[i]); | 168 notification_promo.InitFromJson(parsed_json, kValidPromoTypes[i]); |
167 if (notification_promo.new_notification()) | 169 if (notification_promo.new_notification()) |
168 ScheduleNotification(notification_promo); | 170 ScheduleNotification(notification_promo); |
169 } | 171 } |
170 } | 172 } |
OLD | NEW |