Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: chrome/browser/web_resource/promo_resource_service.cc

Issue 10541054: Immediate notification if active promotion arrives (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More comments and "else". Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 143
144 void PromoResourceService::ScheduleNotification(double promo_start, 144 void PromoResourceService::ScheduleNotification(double promo_start,
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 // Schedule the next notification to happen at the start of promotion.
154 PostNotification(ms_until_start); 155 PostNotification(ms_until_start);
155 if (ms_until_end > 0) { 156 } else if (ms_until_end > 0) {
156 PostNotification(ms_until_end);
157 if (ms_until_start <= 0) { 157 if (ms_until_start <= 0) {
158 // Notify immediately if time is between start and end. 158 // Notify immediately if time is between start and end.
159 PostNotification(0); 159 PostNotification(0);
160 } 160 }
161 // Schedule the next notification to happen at the end of promotion.
162 PostNotification(ms_until_end);
161 } 163 }
162 } 164 }
163 } 165 }
164 166
165 void PromoResourceService::ScheduleNotificationOnInit() { 167 void PromoResourceService::ScheduleNotificationOnInit() {
166 std::string locale = g_browser_process->GetApplicationLocale(); 168 std::string locale = g_browser_process->GetApplicationLocale();
167 if (GetPromoServiceVersion() != kPromoServiceVersion || 169 if (GetPromoServiceVersion() != kPromoServiceVersion ||
168 GetPromoLocale() != locale) { 170 GetPromoLocale() != locale) {
169 // If the promo service has been upgraded or Chrome switched locales, 171 // If the promo service has been upgraded or Chrome switched locales,
170 // refresh the promos. 172 // refresh the promos.
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 !(old_logo_end == logo_end)) { 384 !(old_logo_end == logo_end)) {
383 prefs_->SetDouble(prefs::kNtpCustomLogoStart, logo_start); 385 prefs_->SetDouble(prefs::kNtpCustomLogoStart, logo_start);
384 prefs_->SetDouble(prefs::kNtpCustomLogoEnd, logo_end); 386 prefs_->SetDouble(prefs::kNtpCustomLogoEnd, logo_end);
385 content::NotificationService* service = 387 content::NotificationService* service =
386 content::NotificationService::current(); 388 content::NotificationService::current();
387 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, 389 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED,
388 content::Source<WebResourceService>(this), 390 content::Source<WebResourceService>(this),
389 content::NotificationService::NoDetails()); 391 content::NotificationService::NoDetails());
390 } 392 }
391 } 393 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698