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

Unified Diff: chrome/browser/dom_ui/ntp_resource_cache.cc

Issue 4804001: Add new promotional line for NTP.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/dom_ui/new_tab_ui.cc ('k') | chrome/browser/dom_ui/tips_handler.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/dom_ui/ntp_resource_cache.cc
===================================================================
--- chrome/browser/dom_ui/ntp_resource_cache.cc (revision 67122)
+++ chrome/browser/dom_ui/ntp_resource_cache.cc (working copy)
@@ -26,6 +26,7 @@
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/themes/browser_theme_provider.h"
+#include "chrome/browser/web_resource/web_resource_service.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_constants.h"
@@ -135,12 +136,19 @@
return BrowserThemeProvider::TilingToString(repeat_mode);
}
+// Is the current time within a given date range?
+bool InDateRange(double begin, double end) {
+ Time start_time = Time::FromDoubleT(begin);
+ Time end_time = Time::FromDoubleT(end);
+ return start_time < Time::Now() && end_time > Time::Now();
+}
+
} // namespace
NTPResourceCache::NTPResourceCache(Profile* profile) : profile_(profile) {
registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
NotificationService::AllSources());
- registrar_.Add(this, NotificationType::WEB_RESOURCE_AVAILABLE,
+ registrar_.Add(this, NotificationType::WEB_RESOURCE_STATE_CHANGED,
NotificationService::AllSources());
// Watch for pref changes that cause us to need to invalidate the HTML cache.
@@ -181,7 +189,7 @@
const NotificationSource& source, const NotificationDetails& details) {
// Invalidate the cache.
if (NotificationType::BROWSER_THEME_CHANGED == type ||
- NotificationType::WEB_RESOURCE_AVAILABLE == type) {
+ NotificationType::WEB_RESOURCE_STATE_CHANGED == type) {
new_tab_incognito_html_ = NULL;
new_tab_html_ = NULL;
new_tab_incognito_css_ = NULL;
@@ -350,17 +358,27 @@
// and the time now is between these two times, show the custom logo.
if (profile_->GetPrefs()->FindPreference(prefs::kNTPCustomLogoStart) &&
profile_->GetPrefs()->FindPreference(prefs::kNTPCustomLogoEnd)) {
- Time start_time = Time::FromDoubleT(
- profile_->GetPrefs()->GetReal(prefs::kNTPCustomLogoStart));
- Time end_time = Time::FromDoubleT(
- profile_->GetPrefs()->GetReal(prefs::kNTPCustomLogoEnd));
localized_strings.SetString("customlogo",
- (start_time < Time::Now() && end_time > Time::Now()) ?
+ InDateRange(profile_->GetPrefs()->GetReal(prefs::kNTPCustomLogoStart),
+ profile_->GetPrefs()->GetReal(prefs::kNTPCustomLogoEnd)) ?
"true" : "false");
} else {
localized_strings.SetString("customlogo", "false");
}
+ // If the user has preferences for a start and end time for a promo from
+ // the server, and this promo string exists, set the localized string.
+ if (profile_->GetPrefs()->FindPreference(prefs::kNTPPromoStart) &&
+ profile_->GetPrefs()->FindPreference(prefs::kNTPPromoEnd) &&
+ profile_->GetPrefs()->FindPreference(prefs::kNTPPromoLine) &&
+ WebResourceServiceUtil::CanShowPromo(profile_)) {
+ localized_strings.SetString("serverpromo",
+ InDateRange(profile_->GetPrefs()->GetReal(prefs::kNTPPromoStart),
+ profile_->GetPrefs()->GetReal(prefs::kNTPPromoEnd)) ?
+ profile_->GetPrefs()->GetString(prefs::kNTPPromoLine) :
+ std::string());
+ }
+
base::StringPiece new_tab_html(ResourceBundle::GetSharedInstance().
GetRawDataResource(IDR_NEW_NEW_TAB_HTML));
« no previous file with comments | « chrome/browser/dom_ui/new_tab_ui.cc ('k') | chrome/browser/dom_ui/tips_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698