summaryrefslogtreecommitdiffstats
path: root/chrome/browser/web_resource
diff options
context:
space:
mode:
authormirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-23 15:29:47 +0000
committermirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-23 15:29:47 +0000
commita17710f5cf04f0c6505fba73e58e668c71f8c2fa (patch)
treeedb084eced7a7aece73ef97e252ef19d303b3e54 /chrome/browser/web_resource
parentb1f5e28f36d1c8af1e35738b642b71f7e3382b83 (diff)
downloadchromium_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/browser/web_resource')
-rw-r--r--chrome/browser/web_resource/web_resource_service.cc62
-rw-r--r--chrome/browser/web_resource/web_resource_service.h54
2 files changed, 71 insertions, 45 deletions
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);
};