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