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/message_loop.h" | 9 #include "base/location.h" |
10 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/thread_task_runner_handle.h" |
12 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
13 #include "base/values.h" | 15 #include "base/values.h" |
14 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/web_resource/notification_promo.h" | 17 #include "chrome/browser/web_resource/notification_promo.h" |
16 #include "components/pref_registry/pref_registry_syncable.h" | 18 #include "components/pref_registry/pref_registry_syncable.h" |
17 #include "components/web_resource/web_resource_pref_names.h" | 19 #include "components/web_resource/web_resource_pref_names.h" |
18 #include "components/web_resource/web_resource_switches.h" | 20 #include "components/web_resource/web_resource_switches.h" |
19 #include "url/gurl.h" | 21 #include "url/gurl.h" |
20 | 22 |
21 namespace { | 23 namespace { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 } | 146 } |
145 | 147 |
146 void PromoResourceService::PostNotification(int64 delay_ms) { | 148 void PromoResourceService::PostNotification(int64 delay_ms) { |
147 // Note that this could cause re-issuing a notification every time | 149 // Note that this could cause re-issuing a notification every time |
148 // we receive an update from a server if something goes wrong. | 150 // we receive an update from a server if something goes wrong. |
149 // Given that this couldn't happen more frequently than every | 151 // Given that this couldn't happen more frequently than every |
150 // kCacheUpdateDelay milliseconds, we should be fine. | 152 // kCacheUpdateDelay milliseconds, we should be fine. |
151 // TODO(achuith): This crashes if we post delay_ms = 0 to the message loop. | 153 // TODO(achuith): This crashes if we post delay_ms = 0 to the message loop. |
152 // during startup. | 154 // during startup. |
153 if (delay_ms > 0) { | 155 if (delay_ms > 0) { |
154 base::MessageLoop::current()->PostDelayedTask( | 156 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
155 FROM_HERE, | 157 FROM_HERE, base::Bind(&PromoResourceService::PromoResourceStateChange, |
156 base::Bind(&PromoResourceService::PromoResourceStateChange, | 158 weak_ptr_factory_.GetWeakPtr()), |
157 weak_ptr_factory_.GetWeakPtr()), | |
158 base::TimeDelta::FromMilliseconds(delay_ms)); | 159 base::TimeDelta::FromMilliseconds(delay_ms)); |
159 } else if (delay_ms == 0) { | 160 } else if (delay_ms == 0) { |
160 PromoResourceStateChange(); | 161 PromoResourceStateChange(); |
161 } | 162 } |
162 } | 163 } |
163 | 164 |
164 void PromoResourceService::PromoResourceStateChange() { | 165 void PromoResourceService::PromoResourceStateChange() { |
165 callback_list_.Notify(); | 166 callback_list_.Notify(); |
166 } | 167 } |
167 | 168 |
168 void PromoResourceService::Unpack(const base::DictionaryValue& parsed_json) { | 169 void PromoResourceService::Unpack(const base::DictionaryValue& parsed_json) { |
169 for (size_t i = 0; i < arraysize(kValidPromoTypes); ++i) { | 170 for (size_t i = 0; i < arraysize(kValidPromoTypes); ++i) { |
170 NotificationPromo notification_promo; | 171 NotificationPromo notification_promo; |
171 notification_promo.InitFromJson(parsed_json, kValidPromoTypes[i]); | 172 notification_promo.InitFromJson(parsed_json, kValidPromoTypes[i]); |
172 if (notification_promo.new_notification()) | 173 if (notification_promo.new_notification()) |
173 ScheduleNotification(notification_promo); | 174 ScheduleNotification(notification_promo); |
174 } | 175 } |
175 } | 176 } |
OLD | NEW |