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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 double promo_end) { | 145 double promo_end) { |
146 if (promo_start > 0 && promo_end > 0) { | 146 if (promo_start > 0 && promo_end > 0) { |
147 int64 ms_until_start = | 147 int64 ms_until_start = |
148 static_cast<int64>((base::Time::FromDoubleT( | 148 static_cast<int64>((base::Time::FromDoubleT( |
149 promo_start) - base::Time::Now()).InMilliseconds()); | 149 promo_start) - base::Time::Now()).InMilliseconds()); |
150 int64 ms_until_end = | 150 int64 ms_until_end = |
151 static_cast<int64>((base::Time::FromDoubleT( | 151 static_cast<int64>((base::Time::FromDoubleT( |
152 promo_end) - base::Time::Now()).InMilliseconds()); | 152 promo_end) - base::Time::Now()).InMilliseconds()); |
153 if (ms_until_start > 0) | 153 if (ms_until_start > 0) |
154 PostNotification(ms_until_start); | 154 PostNotification(ms_until_start); |
155 if (ms_until_end > 0) { | 155 if (ms_until_end > 0) { |
achuithb
2012/06/07 20:34:27
Maybe also add else here?
aruslan
2012/06/07 20:55:40
Done.
| |
156 PostNotification(ms_until_end); | |
157 if (ms_until_start <= 0) { | 156 if (ms_until_start <= 0) { |
158 // Notify immediately if time is between start and end. | 157 // Notify immediately if time is between start and end. |
159 PostNotification(0); | 158 PostNotification(0); |
160 } | 159 } |
160 // Schedule notification at the end of promotion. | |
achuithb
2012/06/07 20:34:27
Why not use an else block here? I think we are pro
aruslan
2012/06/07 20:55:40
We should call PostNotification twice -- once with
achuithb
2012/06/07 21:31:28
I see now, that PostNotification sets web_resource
| |
161 PostNotification(ms_until_end); | |
161 } | 162 } |
162 } | 163 } |
163 } | 164 } |
164 | 165 |
165 void PromoResourceService::ScheduleNotificationOnInit() { | 166 void PromoResourceService::ScheduleNotificationOnInit() { |
166 std::string locale = g_browser_process->GetApplicationLocale(); | 167 std::string locale = g_browser_process->GetApplicationLocale(); |
167 if (GetPromoServiceVersion() != kPromoServiceVersion || | 168 if (GetPromoServiceVersion() != kPromoServiceVersion || |
168 GetPromoLocale() != locale) { | 169 GetPromoLocale() != locale) { |
169 // If the promo service has been upgraded or Chrome switched locales, | 170 // If the promo service has been upgraded or Chrome switched locales, |
170 // refresh the promos. | 171 // refresh the promos. |
(...skipping 11 matching lines...) Expand all Loading... | |
182 // invalidate the NTP cache at the time of the promo start. | 183 // invalidate the NTP cache at the time of the promo start. |
183 double promo_start = prefs_->GetDouble(prefs::kNtpPromoStart); | 184 double promo_start = prefs_->GetDouble(prefs::kNtpPromoStart); |
184 double promo_end = prefs_->GetDouble(prefs::kNtpPromoEnd); | 185 double promo_end = prefs_->GetDouble(prefs::kNtpPromoEnd); |
185 ScheduleNotification(promo_start, promo_end); | 186 ScheduleNotification(promo_start, promo_end); |
186 } | 187 } |
187 } | 188 } |
188 | 189 |
189 void PromoResourceService::PostNotification(int64 delay_ms) { | 190 void PromoResourceService::PostNotification(int64 delay_ms) { |
190 if (web_resource_update_scheduled_) | 191 if (web_resource_update_scheduled_) |
191 return; | 192 return; |
192 // TODO(achuith): This crashes if we post delay_ms = 0 to the message loop. | 193 // TODO(achuith): This crashes if we post delay_ms = 0 to the message loop. |
achuithb
2012/06/07 21:31:28
Since we want 2 notifications to be scheduled, pos
| |
193 // during startup. | 194 // during startup. |
194 if (delay_ms > 0) { | 195 if (delay_ms > 0) { |
195 web_resource_update_scheduled_ = true; | 196 web_resource_update_scheduled_ = true; |
196 MessageLoop::current()->PostDelayedTask( | 197 MessageLoop::current()->PostDelayedTask( |
197 FROM_HERE, | 198 FROM_HERE, |
198 base::Bind(&PromoResourceService::PromoResourceStateChange, | 199 base::Bind(&PromoResourceService::PromoResourceStateChange, |
199 weak_ptr_factory_.GetWeakPtr()), | 200 weak_ptr_factory_.GetWeakPtr()), |
200 base::TimeDelta::FromMilliseconds(delay_ms)); | 201 base::TimeDelta::FromMilliseconds(delay_ms)); |
201 } else if (delay_ms == 0) { | 202 } else if (delay_ms == 0) { |
202 PromoResourceStateChange(); | 203 PromoResourceStateChange(); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
382 !(old_logo_end == logo_end)) { | 383 !(old_logo_end == logo_end)) { |
383 prefs_->SetDouble(prefs::kNtpCustomLogoStart, logo_start); | 384 prefs_->SetDouble(prefs::kNtpCustomLogoStart, logo_start); |
384 prefs_->SetDouble(prefs::kNtpCustomLogoEnd, logo_end); | 385 prefs_->SetDouble(prefs::kNtpCustomLogoEnd, logo_end); |
385 content::NotificationService* service = | 386 content::NotificationService* service = |
386 content::NotificationService::current(); | 387 content::NotificationService::current(); |
387 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, | 388 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, |
388 content::Source<WebResourceService>(this), | 389 content::Source<WebResourceService>(this), |
389 content::NotificationService::NoDetails()); | 390 content::NotificationService::NoDetails()); |
390 } | 391 } |
391 } | 392 } |
OLD | NEW |