diff options
author | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-04 16:08:52 +0000 |
---|---|---|
committer | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-04 16:08:52 +0000 |
commit | 81bb1092f354f3cb3c597ab3c9ed568905078e49 (patch) | |
tree | 7e8c5f324f49fc7302e6f1ee742c39169340e03f /chrome/browser/ui | |
parent | 96dcc176c46003af0176f0f4772affc741aa772a (diff) | |
download | chromium_src-81bb1092f354f3cb3c597ab3c9ed568905078e49.zip chromium_src-81bb1092f354f3cb3c597ab3c9ed568905078e49.tar.gz chromium_src-81bb1092f354f3cb3c597ab3c9ed568905078e49.tar.bz2 |
Detach the PromoResourceService and WebResourceService from the Profile; have them store web resource data in local state instead.
We don't need multiple services for different Profiles; instead, there is a single service that captures data in local_state. The only preference stored in the Profile about the promo will be a bool indicating whether it's been closed or not, which will now be set outside the service.
Reviewers:
arv for general changes to PromoResourceService, & unittest.
erg for pulling the service out of the Profile and serving it up as a Singleton.
zmo for the changes I made to gpu_data_manager.
jstritar FYI, for changes to the PromoResourceService.
BUG=77155
TEST=promo resource service unittests.
Review URL: http://codereview.chromium.org/6736028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80318 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui')
-rw-r--r-- | chrome/browser/ui/browser.cc | 1 | ||||
-rw-r--r-- | chrome/browser/ui/webui/new_tab_ui.cc | 2 | ||||
-rw-r--r-- | chrome/browser/ui/webui/ntp_resource_cache.cc | 40 |
3 files changed, 27 insertions, 16 deletions
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index 57e3f8b..e90afd3 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -2074,6 +2074,7 @@ void Browser::RegisterUserPrefs(PrefService* prefs) { prefs->RegisterBooleanPref(prefs::kDeleteFormData, false); prefs->RegisterIntegerPref(prefs::kDeleteTimePeriod, 0); prefs->RegisterBooleanPref(prefs::kCheckDefaultBrowser, true); + prefs->RegisterBooleanPref(prefs::kNTPPromoClosed, false); prefs->RegisterBooleanPref(prefs::kShowOmniboxSearchHint, true); prefs->RegisterBooleanPref(prefs::kWebAppCreateOnDesktop, true); prefs->RegisterBooleanPref(prefs::kWebAppCreateInAppsMenu, true); diff --git a/chrome/browser/ui/webui/new_tab_ui.cc b/chrome/browser/ui/webui/new_tab_ui.cc index 1f0604d..4bd9100 100644 --- a/chrome/browser/ui/webui/new_tab_ui.cc +++ b/chrome/browser/ui/webui/new_tab_ui.cc @@ -275,7 +275,7 @@ void NewTabPageClosePromoHandler::HandleClosePromo( const ListValue* args) { web_ui_->GetProfile()->GetPrefs()->SetBoolean(prefs::kNTPPromoClosed, true); NotificationService* service = NotificationService::current(); - service->Notify(NotificationType::PROMO_RESOURCE_STATE_CHANGED, + service->Notify(NotificationType::PROMO_CLOSED, Source<NewTabPageClosePromoHandler>(this), NotificationService::NoDetails()); } diff --git a/chrome/browser/ui/webui/ntp_resource_cache.cc b/chrome/browser/ui/webui/ntp_resource_cache.cc index 438cb64..2cfbab4 100644 --- a/chrome/browser/ui/webui/ntp_resource_cache.cc +++ b/chrome/browser/ui/webui/ntp_resource_cache.cc @@ -15,6 +15,7 @@ #include "base/time.h" #include "base/utf_string_conversions.h" #include "base/values.h" +#include "chrome/browser/browser_process.h" #include "chrome/browser/google/google_util.h" #include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/prefs/pref_service.h" @@ -153,6 +154,8 @@ NTPResourceCache::NTPResourceCache(Profile* profile) : profile_(profile) { NotificationService::AllSources()); registrar_.Add(this, NotificationType::PROMO_RESOURCE_STATE_CHANGED, NotificationService::AllSources()); + registrar_.Add(this, NotificationType::PROMO_CLOSED, + NotificationService::AllSources()); // Watch for pref changes that cause us to need to invalidate the HTML cache. pref_change_registrar_.Init(profile_->GetPrefs()); @@ -191,13 +194,18 @@ RefCountedBytes* NTPResourceCache::GetNewTabCSS(bool is_incognito) { void NTPResourceCache::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { // Invalidate the cache. - if (NotificationType::BROWSER_THEME_CHANGED == type || - NotificationType::PROMO_RESOURCE_STATE_CHANGED == type) { + if (type == NotificationType::BROWSER_THEME_CHANGED || + type == NotificationType::PROMO_RESOURCE_STATE_CHANGED || + type == NotificationType::PROMO_CLOSED) { new_tab_incognito_html_ = NULL; new_tab_html_ = NULL; new_tab_incognito_css_ = NULL; new_tab_css_ = NULL; - } else if (NotificationType::PREF_CHANGED == type) { + // Reset the promo closed preference if a new promo is being displayed. + if (type == NotificationType::PROMO_RESOURCE_STATE_CHANGED) { + profile_->GetPrefs()->SetBoolean(prefs::kNTPPromoClosed, false); + } + } else if (type == NotificationType::PREF_CHANGED) { std::string* pref_name = Details<std::string>(details).ptr(); if (*pref_name == prefs::kShowBookmarkBar || *pref_name == prefs::kHomePageIsNewTabPage || @@ -368,11 +376,13 @@ void NTPResourceCache::CreateNewTabHTML() { // 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)) { + DCHECK(g_browser_process); + PrefService* local_state = g_browser_process->local_state(); + if (local_state->FindPreference(prefs::kNTPCustomLogoStart) && + local_state->FindPreference(prefs::kNTPCustomLogoEnd)) { localized_strings.SetString("customlogo", - InDateRange(profile_->GetPrefs()->GetDouble(prefs::kNTPCustomLogoStart), - profile_->GetPrefs()->GetDouble(prefs::kNTPCustomLogoEnd)) ? + InDateRange(local_state->GetDouble(prefs::kNTPCustomLogoStart), + local_state->GetDouble(prefs::kNTPCustomLogoEnd)) ? "true" : "false"); } else { localized_strings.SetString("customlogo", "false"); @@ -380,15 +390,15 @@ void NTPResourceCache::CreateNewTabHTML() { // 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) && - PromoResourceServiceUtil::CanShowPromo(profile_)) { + if (local_state->FindPreference(prefs::kNTPPromoStart) && + local_state->FindPreference(prefs::kNTPPromoEnd) && + local_state->FindPreference(prefs::kNTPPromoLine) && + web_resource::CanShowPromo(profile_)) { localized_strings.SetString("serverpromo", - InDateRange(profile_->GetPrefs()->GetDouble(prefs::kNTPPromoStart), - profile_->GetPrefs()->GetDouble(prefs::kNTPPromoEnd)) ? - profile_->GetPrefs()->GetString(prefs::kNTPPromoLine) : - std::string()); + InDateRange(local_state->GetDouble(prefs::kNTPPromoStart), + local_state->GetDouble(prefs::kNTPPromoEnd)) ? + local_state->GetString(prefs::kNTPPromoLine) : + std::string()); UserMetrics::RecordAction(UserMetricsAction("NTPPromoShown")); } |