diff options
author | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-23 15:29:47 +0000 |
---|---|---|
committer | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-23 15:29:47 +0000 |
commit | a17710f5cf04f0c6505fba73e58e668c71f8c2fa (patch) | |
tree | edb084eced7a7aece73ef97e252ef19d303b3e54 /chrome | |
parent | b1f5e28f36d1c8af1e35738b642b71f7e3382b83 (diff) | |
download | chromium_src-a17710f5cf04f0c6505fba73e58e668c71f8c2fa.zip chromium_src-a17710f5cf04f0c6505fba73e58e668c71f8c2fa.tar.gz chromium_src-a17710f5cf04f0c6505fba73e58e668c71f8c2fa.tar.bz2 |
Allow web resource server to set custom logo display by start and end date.
BUG=56388
TEST=none
Review URL: http://codereview.chromium.org/3382014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60291 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/dom_ui/ntp_resource_cache.cc | 22 | ||||
-rw-r--r-- | chrome/browser/web_resource/web_resource_service.cc | 62 | ||||
-rw-r--r-- | chrome/browser/web_resource/web_resource_service.h | 54 | ||||
-rw-r--r-- | chrome/common/pref_names.cc | 6 | ||||
-rw-r--r-- | chrome/common/pref_names.h | 3 |
5 files changed, 95 insertions, 52 deletions
diff --git a/chrome/browser/dom_ui/ntp_resource_cache.cc b/chrome/browser/dom_ui/ntp_resource_cache.cc index 169aea0..600710f 100644 --- a/chrome/browser/dom_ui/ntp_resource_cache.cc +++ b/chrome/browser/dom_ui/ntp_resource_cache.cc @@ -15,6 +15,7 @@ #include "base/ref_counted_memory.h" #include "base/string16.h" #include "base/string_number_conversions.h" +#include "base/time.h" #include "base/utf_string_conversions.h" #include "base/values.h" #include "chrome/browser/chrome_thread.h" @@ -47,6 +48,8 @@ #include "chrome/browser/gtk/bookmark_bar_gtk.h" #endif +using base::Time; + namespace { // The URL for the the Learn More page shown on incognito new tab. @@ -288,10 +291,6 @@ void NTPResourceCache::CreateNewTabHTML() { l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE)); localized_strings.SetString("web_store_url", GetUrlWithLang(GURL(Extension::ChromeStoreURL()))); - localized_strings.SetString("customlogo", - profile_->GetPrefs()->FindPreference(prefs::kNTPCustomLogo) && - profile_->GetPrefs()->GetBoolean(prefs::kNTPCustomLogo) ? - "true" : "false"); // Don't initiate the sync related message passing with the page if the sync // code is not present. @@ -312,6 +311,21 @@ void NTPResourceCache::CreateNewTabHTML() { profile_->GetPrefs()); localized_strings.SetInteger("shown_sections", shown_sections); + // If the user has preferences for a start and end time for a custom logo, + // 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()) ? + "true" : "false"); + } else { + localized_strings.SetString("customlogo", "false"); + } + base::StringPiece new_tab_html(ResourceBundle::GetSharedInstance(). GetRawDataResource(IDR_NEW_NEW_TAB_HTML)); diff --git a/chrome/browser/web_resource/web_resource_service.cc b/chrome/browser/web_resource/web_resource_service.cc index ce34d1b..add7345 100644 --- a/chrome/browser/web_resource/web_resource_service.cc +++ b/chrome/browser/web_resource/web_resource_service.cc @@ -25,7 +25,6 @@ const char* WebResourceService::kCurrentTipPrefName = "current_tip"; const char* WebResourceService::kTipCachePrefName = "tips"; -const char* WebResourceService::kCustomLogoId = "1"; class WebResourceService::WebResourceFetcher : public URLFetcher::Delegate { @@ -185,7 +184,6 @@ class WebResourceService::UnpackerClient bool got_response_; }; -// TODO(mirandac): replace these servers tomorrow! const char* WebResourceService::kDefaultResourceServer = #if defined(OS_MACOSX) "https://clients2.google.com/tools/service/npredir?r=chrometips_mac&hl="; @@ -207,7 +205,8 @@ void WebResourceService::Init() { resource_dispatcher_host_ = g_browser_process->resource_dispatcher_host(); web_resource_fetcher_ = new WebResourceFetcher(this); prefs_->RegisterStringPref(prefs::kNTPWebResourceCacheUpdate, "0"); - prefs_->RegisterBooleanPref(prefs::kNTPCustomLogo, false); + prefs_->RegisterRealPref(prefs::kNTPCustomLogoStart, 0); + prefs_->RegisterRealPref(prefs::kNTPCustomLogoEnd, 0); std::string locale = g_browser_process->GetApplicationLocale(); if (prefs_->HasPrefPath(prefs::kNTPWebResourceServer)) { @@ -311,8 +310,19 @@ void WebResourceService::UnpackTips(const DictionaryValue& parsed_json) { void WebResourceService::UnpackLogoSignal(const DictionaryValue& parsed_json) { DictionaryValue* topic_dict; ListValue* answer_list; - std::string logo_id; + double old_logo_start = 0; + double old_logo_end = 0; + double logo_start = 0; + double logo_end = 0; + + // Check for preexisting start and end values. + if (prefs_->HasPrefPath(prefs::kNTPCustomLogoStart) && + prefs_->HasPrefPath(prefs::kNTPCustomLogoEnd)) { + old_logo_start = prefs_->GetReal(prefs::kNTPCustomLogoStart); + old_logo_end = prefs_->GetReal(prefs::kNTPCustomLogoEnd); + } + // Check for newly received start and end values. if (parsed_json.GetDictionary("topic", &topic_dict)) { if (topic_dict->GetList("answers", &answer_list)) { for (ListValue::const_iterator tip_iter = answer_list->begin(); @@ -321,23 +331,37 @@ void WebResourceService::UnpackLogoSignal(const DictionaryValue& parsed_json) { continue; DictionaryValue* a_dic = static_cast<DictionaryValue*>(*tip_iter); - if (a_dic->GetString("logo_id", &logo_id)) { - prefs_->SetBoolean(prefs::kNTPCustomLogo, - LowerCaseEqualsASCII(logo_id, kCustomLogoId)); - NotificationService* service = NotificationService::current(); - service->Notify(NotificationType::BROWSER_THEME_CHANGED, - Source<WebResourceService>(this), - NotificationService::NoDetails()); - return; + std::string logo_start_string; + std::string logo_end_string; + if (a_dic->GetString("custom_logo_start", &logo_start_string) && + a_dic->GetString("custom_logo_end", &logo_end_string)) { + // If both times can be correctly parsed, then set new logo + // start and end times. + base::Time start_time; + base::Time end_time; + if (base::Time::FromString( + ASCIIToWide(logo_start_string).c_str(), &start_time) && + base::Time::FromString( + ASCIIToWide(logo_end_string).c_str(), &end_time)) { + logo_start = start_time.ToDoubleT(); + logo_end = end_time.ToDoubleT(); + } } } } } - // If no logo_id is found in the tips, show regular logo. - prefs_->SetBoolean(prefs::kNTPCustomLogo, - LowerCaseEqualsASCII(logo_id, kCustomLogoId)); - NotificationService* service = NotificationService::current(); - service->Notify(NotificationType::BROWSER_THEME_CHANGED, - Source<WebResourceService>(this), - NotificationService::NoDetails()); + + // If logo start or end times have changed, trigger a theme change so that + // the logo on the NTP is updated. This check is outside the reading of the + // web resource data, because the absence of dates counts as a triggering + // change if there were dates before. + if (!(old_logo_start == logo_start) || + !(old_logo_end == logo_end)) { + prefs_->SetReal(prefs::kNTPCustomLogoStart, logo_start); + prefs_->SetReal(prefs::kNTPCustomLogoEnd, logo_end); + NotificationService* service = NotificationService::current(); + service->Notify(NotificationType::BROWSER_THEME_CHANGED, + Source<WebResourceService>(this), + NotificationService::NoDetails()); + } } diff --git a/chrome/browser/web_resource/web_resource_service.h b/chrome/browser/web_resource/web_resource_service.h index fd46e76..835c5fc 100644 --- a/chrome/browser/web_resource/web_resource_service.h +++ b/chrome/browser/web_resource/web_resource_service.h @@ -28,29 +28,6 @@ class WebResourceService // the process that will parse the JSON, and then update the cache. void UpdateResourceCache(const std::string& json_data); - static const char* kCurrentTipPrefName; - static const char* kTipCachePrefName; - static const char* kCustomLogoId; - - // Default server from which to gather resources. - static const char* kDefaultResourceServer; - - private: - class WebResourceFetcher; - friend class WebResourceFetcher; - - class UnpackerClient; - - ~WebResourceService(); - - void Init(); - - // Set in_fetch_ to false, clean up temp directories (in the future). - void EndFetch(); - - // Puts parsed json data in the right places, and writes to prefs file. - void OnWebResourceUnpacked(const DictionaryValue& parsed_json); - // Unpack the web resource as a set of tips. Expects json in the form of: // { // "lang": "en", @@ -68,6 +45,7 @@ class WebResourceService // } // } // + // Public for unit testing. void UnpackTips(const DictionaryValue& parsed_json); // Unpack the web resource as a custom logo signal. Expects json in the form @@ -76,15 +54,39 @@ class WebResourceService // "topic": { // "answers": [ // { - // "logo_id": "1" + // "custom_logo_start": "31/12/10 01:00", + // "custom_logo_end": "31/01/11 01:00" // }, // ... // ] // } // } // + // Public for unit testing. void UnpackLogoSignal(const DictionaryValue& parsed_json); + static const char* kCurrentTipPrefName; + static const char* kTipCachePrefName; + + // Default server from which to gather resources. + static const char* kDefaultResourceServer; + + private: + class WebResourceFetcher; + friend class WebResourceFetcher; + + class UnpackerClient; + + ~WebResourceService(); + + void Init(); + + // Set in_fetch_ to false, clean up temp directories (in the future). + void EndFetch(); + + // Puts parsed json data in the right places, and writes to prefs file. + void OnWebResourceUnpacked(const DictionaryValue& parsed_json); + // We need to be able to load parsed resource data into preferences file, // and get proper install directory. PrefService* prefs_; @@ -108,8 +110,8 @@ class WebResourceService // Delay on first fetch so we don't interfere with startup. static const int kStartResourceFetchDelay = 5000; - // Delay between calls to update the cache (12 hours). - static const int kCacheUpdateDelay = 12 * 60 * 60 * 1000; + // Delay between calls to update the cache (48 hours). + static const int kCacheUpdateDelay = 48 * 60 * 60 * 1000; DISALLOW_COPY_AND_ASSIGN(WebResourceService); }; diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index 2cd9111..a47eaa1 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -899,8 +899,10 @@ const char kNTPShownSections[] = "ntp.shown_sections"; // This pref is used for migrating the prefs for the NTP const char kNTPPrefVersion[] = "ntp.pref_version"; -// Used if the NTP should show a custom logo rather than the standard one. -const char kNTPCustomLogo[] = "ntp.custom_logo"; +// Dates between which the NTP should show a custom logo rather than the +// standard one. +const char kNTPCustomLogoStart[] = "ntp.custom_logo_start"; +const char kNTPCustomLogoEnd[] = "ntp.custom_logo_end"; // A boolean specifying whether dev tools window should be opened docked. const char kDevToolsOpenDocked[] = "devtools.open_docked"; diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index 295b804..86e33aa 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -327,7 +327,8 @@ extern const char kNTPWebResourceCacheUpdate[]; extern const char kNTPWebResourceServer[]; extern const char kNTPShownSections[]; extern const char kNTPPrefVersion[]; -extern const char kNTPCustomLogo[]; +extern const char kNTPCustomLogoStart[]; +extern const char kNTPCustomLogoEnd[]; extern const char kDevToolsOpenDocked[]; extern const char kDevToolsSplitLocation[]; |