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)); |