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/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 } | 142 } |
143 | 143 |
144 void PromoResourceService::PostNotification(int64 delay_ms) { | 144 void PromoResourceService::PostNotification(int64 delay_ms) { |
145 // Note that this could cause re-issuing a notification every time | 145 // Note that this could cause re-issuing a notification every time |
146 // we receive an update from a server if something goes wrong. | 146 // we receive an update from a server if something goes wrong. |
147 // Given that this couldn't happen more frequently than every | 147 // Given that this couldn't happen more frequently than every |
148 // kCacheUpdateDelay milliseconds, we should be fine. | 148 // kCacheUpdateDelay milliseconds, we should be fine. |
149 // TODO(achuith): This crashes if we post delay_ms = 0 to the message loop. | 149 // TODO(achuith): This crashes if we post delay_ms = 0 to the message loop. |
150 // during startup. | 150 // during startup. |
151 if (delay_ms > 0) { | 151 if (delay_ms > 0) { |
152 MessageLoop::current()->PostDelayedTask( | 152 base::MessageLoop::current()->PostDelayedTask( |
153 FROM_HERE, | 153 FROM_HERE, |
154 base::Bind(&PromoResourceService::PromoResourceStateChange, | 154 base::Bind(&PromoResourceService::PromoResourceStateChange, |
155 weak_ptr_factory_.GetWeakPtr()), | 155 weak_ptr_factory_.GetWeakPtr()), |
156 base::TimeDelta::FromMilliseconds(delay_ms)); | 156 base::TimeDelta::FromMilliseconds(delay_ms)); |
157 } else if (delay_ms == 0) { | 157 } else if (delay_ms == 0) { |
158 PromoResourceStateChange(); | 158 PromoResourceStateChange(); |
159 } | 159 } |
160 } | 160 } |
161 | 161 |
162 void PromoResourceService::PromoResourceStateChange() { | 162 void PromoResourceService::PromoResourceStateChange() { |
163 content::NotificationService* service = | 163 content::NotificationService* service = |
164 content::NotificationService::current(); | 164 content::NotificationService::current(); |
165 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, | 165 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, |
166 content::Source<WebResourceService>(this), | 166 content::Source<WebResourceService>(this), |
167 content::NotificationService::NoDetails()); | 167 content::NotificationService::NoDetails()); |
168 } | 168 } |
169 | 169 |
170 void PromoResourceService::Unpack(const DictionaryValue& parsed_json) { | 170 void PromoResourceService::Unpack(const DictionaryValue& parsed_json) { |
171 for (size_t i = 0; i < arraysize(kValidPromoTypes); ++i) { | 171 for (size_t i = 0; i < arraysize(kValidPromoTypes); ++i) { |
172 NotificationPromo notification_promo; | 172 NotificationPromo notification_promo; |
173 notification_promo.InitFromJson(parsed_json, kValidPromoTypes[i]); | 173 notification_promo.InitFromJson(parsed_json, kValidPromoTypes[i]); |
174 if (notification_promo.new_notification()) | 174 if (notification_promo.new_notification()) |
175 ScheduleNotification(notification_promo); | 175 ScheduleNotification(notification_promo); |
176 } | 176 } |
177 } | 177 } |
OLD | NEW |