summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorguohui@google.com <guohui@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-20 20:06:55 +0000
committerguohui@google.com <guohui@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-20 20:06:55 +0000
commit27e96a97391301dc58bf64ecd63573b2ebc0eb92 (patch)
tree3486514212890b323ab8553c12e9d8a26fb72de1 /chrome
parentedca205868de864a21b709b402e772ecceb4ea08 (diff)
downloadchromium_src-27e96a97391301dc58bf64ecd63573b2ebc0eb92.zip
chromium_src-27e96a97391301dc58bf64ecd63573b2ebc0eb92.tar.gz
chromium_src-27e96a97391301dc58bf64ecd63573b2ebc0eb92.tar.bz2
Make NTP4 bubble profile independent
BUG=99503 TEST=Dismiss NTP4 bubble and create a new profile. Confirm that the NTP4 bubble does not show up for the new profile. Review URL: http://codereview.chromium.org/8244009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106553 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/prefs/browser_prefs.cc3
-rw-r--r--chrome/browser/ui/browser.cc2
-rw-r--r--chrome/browser/ui/webui/ntp/new_tab_page_handler.cc37
-rw-r--r--chrome/browser/ui/webui/ntp/new_tab_page_handler.h8
-rw-r--r--chrome/browser/ui/webui/ntp/ntp_resource_cache.cc6
-rw-r--r--chrome/common/chrome_notification_types.h4
6 files changed, 45 insertions, 15 deletions
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index 8b1420a..f82d27d 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -52,6 +52,7 @@
#include "chrome/browser/ui/search_engines/keyword_editor_controller.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/browser/ui/webui/flags_ui.h"
+#include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h"
#include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
#include "chrome/browser/ui/webui/options/extension_settings_handler.h"
#include "chrome/browser/ui/webui/plugins_ui.h"
@@ -103,8 +104,10 @@ void RegisterLocalState(PrefService* local_state) {
KeywordEditorController::RegisterPrefs(local_state);
MetricsLog::RegisterPrefs(local_state);
MetricsService::RegisterPrefs(local_state);
+ NewTabPageHandler::RegisterPrefs(local_state);
printing::PrintJobManager::RegisterPrefs(local_state);
PromoResourceService::RegisterPrefs(local_state);
+
#if defined(ENABLE_SAFE_BROWSING)
SafeBrowsingService::RegisterPrefs(local_state);
#endif
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index 3ab3c19..09a522d 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -519,7 +519,7 @@ void Browser::InitBrowserWindow() {
// Permanently dismiss ntp4 bubble for new users.
if (FirstRun::IsChromeFirstRun())
- NewTabPageHandler::DismissIntroMessage(profile_->GetPrefs());
+ NewTabPageHandler::DismissIntroMessage(local_state);
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/chrome/browser/ui/webui/ntp/new_tab_page_handler.cc b/chrome/browser/ui/webui/ntp/new_tab_page_handler.cc
index 59f451b..62b94cd 100644
--- a/chrome/browser/ui/webui/ntp/new_tab_page_handler.cc
+++ b/chrome/browser/ui/webui/ntp/new_tab_page_handler.cc
@@ -8,13 +8,13 @@
#include "base/bind_helpers.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram.h"
+#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/default_apps_trial.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
#include "chrome/browser/web_resource/notification_promo.h"
-#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/notification_service.h"
#include "grit/chromium_strings.h"
@@ -69,15 +69,14 @@ void NewTabPageHandler::HandleCloseNotificationPromo(const ListValue* args) {
NotificationPromo notification_promo(
Profile::FromWebUI(web_ui())->GetPrefs(), NULL);
notification_promo.HandleClosed();
- NotifyPromoResourceChanged();
+ Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED);
}
void NewTabPageHandler::HandleNotificationPromoViewed(const ListValue* args) {
NotificationPromo notification_promo(
Profile::FromWebUI(web_ui_)->GetPrefs(), NULL);
- if (notification_promo.HandleViewed()) {
- NotifyPromoResourceChanged();
- }
+ if (notification_promo.HandleViewed())
+ Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED);
}
void NewTabPageHandler::HandlePageSelected(const ListValue* args) {
@@ -107,14 +106,16 @@ void NewTabPageHandler::HandlePageSelected(const ListValue* args) {
}
void NewTabPageHandler::HandleIntroMessageDismissed(const ListValue* args) {
- PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
+ PrefService* prefs = g_browser_process->local_state();
prefs->SetInteger(prefs::kNTP4IntroDisplayCount, kIntroDisplayMax + 1);
+ Notify(chrome::NTP4_INTRO_PREF_CHANGED);
}
void NewTabPageHandler::HandleIntroMessageSeen(const ListValue* args) {
- PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
+ PrefService* prefs = g_browser_process->local_state();
int intro_displays = prefs->GetInteger(prefs::kNTP4IntroDisplayCount);
prefs->SetInteger(prefs::kNTP4IntroDisplayCount, intro_displays + 1);
+ Notify(chrome::NTP4_INTRO_PREF_CHANGED);
}
// static
@@ -122,6 +123,10 @@ void NewTabPageHandler::RegisterUserPrefs(PrefService* prefs) {
// TODO(estade): should be syncable.
prefs->RegisterIntegerPref(prefs::kNTPShownPage, APPS_PAGE_ID,
PrefService::UNSYNCABLE_PREF);
+}
+
+// static
+void NewTabPageHandler::RegisterPrefs(PrefService* prefs) {
prefs->RegisterIntegerPref(prefs::kNTP4IntroDisplayCount, 0,
PrefService::UNSYNCABLE_PREF);
}
@@ -141,7 +146,17 @@ void NewTabPageHandler::GetLocalizedValues(Profile* profile,
values->SetInteger("shown_page_type", shown_page & ~INDEX_MASK);
values->SetInteger("shown_page_index", shown_page & INDEX_MASK);
- int intro_displays = prefs->GetInteger(prefs::kNTP4IntroDisplayCount);
+ PrefService* local_state = g_browser_process->local_state();
+ int intro_displays = local_state->GetInteger(prefs::kNTP4IntroDisplayCount);
+ // This preference used to exist in profile, so check the profile if it has
+ // not been set in local state yet.
+ if (!intro_displays) {
+ prefs->RegisterIntegerPref(prefs::kNTP4IntroDisplayCount, 0,
+ PrefService::UNSYNCABLE_PREF);
+ intro_displays = prefs->GetInteger(prefs::kNTP4IntroDisplayCount);
+ if (intro_displays)
+ local_state->SetInteger(prefs::kNTP4IntroDisplayCount, intro_displays);
+ }
if (intro_displays <= kIntroDisplayMax) {
values->SetString("ntp4_intro_message",
l10n_util::GetStringUTF16(IDS_NTP4_INTRO_MESSAGE));
@@ -154,12 +169,14 @@ void NewTabPageHandler::GetLocalizedValues(Profile* profile,
// static
void NewTabPageHandler::DismissIntroMessage(PrefService* prefs) {
prefs->SetInteger(prefs::kNTP4IntroDisplayCount, kIntroDisplayMax + 1);
+ // No need to send notification to update resource cache, because this method
+ // is only called during startup before the ntp resource cache is constructed.
}
-void NewTabPageHandler::NotifyPromoResourceChanged() {
+void NewTabPageHandler::Notify(chrome::NotificationType notification_type) {
content::NotificationService* service =
content::NotificationService::current();
- service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED,
+ service->Notify(notification_type,
content::Source<NewTabPageHandler>(this),
content::NotificationService::NoDetails());
}
diff --git a/chrome/browser/ui/webui/ntp/new_tab_page_handler.h b/chrome/browser/ui/webui/ntp/new_tab_page_handler.h
index 39858b7..599ee4c 100644
--- a/chrome/browser/ui/webui/ntp/new_tab_page_handler.h
+++ b/chrome/browser/ui/webui/ntp/new_tab_page_handler.h
@@ -6,6 +6,7 @@
#define CHROME_BROWSER_UI_WEBUI_NTP_NEW_TAB_PAGE_HANDLER_H_
#include "base/values.h"
+#include "chrome/common/chrome_notification_types.h"
#include "content/browser/webui/web_ui.h"
class PrefService;
@@ -39,9 +40,12 @@ class NewTabPageHandler : public WebUIMessageHandler {
// message is displayed.
void HandleIntroMessageSeen(const ListValue* args);
- // Register NTP preferences.
+ // Register NTP per-profile preferences.
static void RegisterUserPrefs(PrefService* prefs);
+ // Register NTP profile-independent preferences.
+ static void RegisterPrefs(PrefService* prefs);
+
// Registers values (strings etc.) for the page.
static void GetLocalizedValues(Profile* profile, DictionaryValue* values);
@@ -65,7 +69,7 @@ class NewTabPageHandler : public WebUIMessageHandler {
(LAST_PAGE_ID >> kPageIdOffset) + 1;
// Helper to send out promo resource change notification.
- void NotifyPromoResourceChanged();
+ void Notify(chrome::NotificationType notification_type);
DISALLOW_COPY_AND_ASSIGN(NewTabPageHandler);
};
diff --git a/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc b/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc
index 21a7f27..a862436 100644
--- a/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc
+++ b/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc
@@ -173,6 +173,8 @@ NTPResourceCache::NTPResourceCache(Profile* profile) : profile_(profile) {
ThemeServiceFactory::GetForProfile(profile)));
registrar_.Add(this, chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED,
content::NotificationService::AllSources());
+ registrar_.Add(this, chrome::NTP4_INTRO_PREF_CHANGED,
+ content::NotificationService::AllSources());
// Watch for pref changes that cause us to need to invalidate the HTML cache.
pref_change_registrar_.Init(profile_->GetPrefs());
@@ -181,7 +183,6 @@ NTPResourceCache::NTPResourceCache(Profile* profile) : profile_(profile) {
pref_change_registrar_.Add(prefs::kHomePageIsNewTabPage, this);
pref_change_registrar_.Add(prefs::kNTPShownSections, this);
pref_change_registrar_.Add(prefs::kNTPShownPage, this);
- pref_change_registrar_.Add(prefs::kNTP4IntroDisplayCount, this);
}
NTPResourceCache::~NTPResourceCache() {}
@@ -222,7 +223,8 @@ void NTPResourceCache::Observe(int type,
new_tab_html_ = NULL;
new_tab_incognito_css_ = NULL;
new_tab_css_ = NULL;
- } else if (chrome::NOTIFICATION_PREF_CHANGED == type) {
+ } else if (chrome::NOTIFICATION_PREF_CHANGED == type ||
+ chrome::NTP4_INTRO_PREF_CHANGED) {
// A change occurred to one of the preferences we care about, so flush the
// cache.
new_tab_incognito_html_ = NULL;
diff --git a/chrome/common/chrome_notification_types.h b/chrome/common/chrome_notification_types.h
index e6cee1b..5c90236 100644
--- a/chrome/common/chrome_notification_types.h
+++ b/chrome/common/chrome_notification_types.h
@@ -308,6 +308,10 @@ enum NotificationType {
// details are NoDetails.
NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED,
+ // The number of times that NTP4 bubble is shown has been changed. The NTP
+ // resource cache has to be refreshed to remove the NTP4 bubble.
+ NTP4_INTRO_PREF_CHANGED,
+
// Autocomplete ------------------------------------------------------------
// Sent by the autocomplete controller when done. The source is the