Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Side by Side Diff: chrome/browser/ui/webui/ntp/new_tab_page_handler.cc

Issue 10584040: Merge 142914 - Remove NTP4 intro bubble (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1180/src/
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h" 5 #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/extensions/default_apps_trial.h" 13 #include "chrome/browser/extensions/default_apps_trial.h"
14 #include "chrome/browser/prefs/pref_service.h" 14 #include "chrome/browser/prefs/pref_service.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/sync/profile_sync_service.h" 16 #include "chrome/browser/sync/profile_sync_service.h"
17 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" 17 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
18 #include "chrome/browser/web_resource/notification_promo.h" 18 #include "chrome/browser/web_resource/notification_promo.h"
19 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
20 #include "content/public/browser/notification_service.h" 20 #include "content/public/browser/notification_service.h"
21 #include "content/public/browser/web_ui.h" 21 #include "content/public/browser/web_ui.h"
22 #include "grit/chromium_strings.h" 22 #include "grit/chromium_strings.h"
23 #include "grit/generated_resources.h" 23 #include "grit/generated_resources.h"
24 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
25 25
26 static const int kIntroDisplayMax = 10;
27
28 // The URL of a knowledge-base article about the new NTP.
29 static const char kNtp4IntroURL[] =
30 "http://www.google.com/support/chrome/bin/answer.py?answer=95451";
31
32 static const char kDefaultPageTypeHistogram[] = 26 static const char kDefaultPageTypeHistogram[] =
33 "NewTabPage.DefaultPageType"; 27 "NewTabPage.DefaultPageType";
34 28
35 NewTabPageHandler::NewTabPageHandler() : page_switch_count_(0) { 29 NewTabPageHandler::NewTabPageHandler() : page_switch_count_(0) {
36 } 30 }
37 31
38 NewTabPageHandler::~NewTabPageHandler() { 32 NewTabPageHandler::~NewTabPageHandler() {
39 HISTOGRAM_COUNTS_100("NewTabPage.SingleSessionPageSwitches", 33 HISTOGRAM_COUNTS_100("NewTabPage.SingleSessionPageSwitches",
40 page_switch_count_); 34 page_switch_count_);
41 } 35 }
(...skipping 17 matching lines...) Expand all
59 53
60 web_ui()->RegisterMessageCallback("closeNotificationPromo", 54 web_ui()->RegisterMessageCallback("closeNotificationPromo",
61 base::Bind(&NewTabPageHandler::HandleCloseNotificationPromo, 55 base::Bind(&NewTabPageHandler::HandleCloseNotificationPromo,
62 base::Unretained(this))); 56 base::Unretained(this)));
63 web_ui()->RegisterMessageCallback("notificationPromoViewed", 57 web_ui()->RegisterMessageCallback("notificationPromoViewed",
64 base::Bind(&NewTabPageHandler::HandleNotificationPromoViewed, 58 base::Bind(&NewTabPageHandler::HandleNotificationPromoViewed,
65 base::Unretained(this))); 59 base::Unretained(this)));
66 web_ui()->RegisterMessageCallback("pageSelected", 60 web_ui()->RegisterMessageCallback("pageSelected",
67 base::Bind(&NewTabPageHandler::HandlePageSelected, 61 base::Bind(&NewTabPageHandler::HandlePageSelected,
68 base::Unretained(this))); 62 base::Unretained(this)));
69 web_ui()->RegisterMessageCallback("introMessageDismissed",
70 base::Bind(&NewTabPageHandler::HandleIntroMessageDismissed,
71 base::Unretained(this)));
72 web_ui()->RegisterMessageCallback("introMessageSeen",
73 base::Bind(&NewTabPageHandler::HandleIntroMessageSeen,
74 base::Unretained(this)));
75 } 63 }
76 64
77 void NewTabPageHandler::HandleCloseNotificationPromo(const ListValue* args) { 65 void NewTabPageHandler::HandleCloseNotificationPromo(const ListValue* args) {
78 NotificationPromo notification_promo(Profile::FromWebUI(web_ui())); 66 NotificationPromo notification_promo(Profile::FromWebUI(web_ui()));
79 notification_promo.HandleClosed(); 67 notification_promo.HandleClosed();
80 Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED); 68 Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED);
81 } 69 }
82 70
83 void NewTabPageHandler::HandleNotificationPromoViewed(const ListValue* args) { 71 void NewTabPageHandler::HandleNotificationPromoViewed(const ListValue* args) {
84 NotificationPromo notification_promo(Profile::FromWebUI(web_ui())); 72 NotificationPromo notification_promo(Profile::FromWebUI(web_ui()));
(...skipping 27 matching lines...) Expand all
112 static bool default_apps_trial_exists = 100 static bool default_apps_trial_exists =
113 base::FieldTrialList::TrialExists(kDefaultAppsTrialName); 101 base::FieldTrialList::TrialExists(kDefaultAppsTrialName);
114 if (default_apps_trial_exists) { 102 if (default_apps_trial_exists) {
115 UMA_HISTOGRAM_ENUMERATION( 103 UMA_HISTOGRAM_ENUMERATION(
116 base::FieldTrial::MakeName("NewTabPage.SelectedPageType", 104 base::FieldTrial::MakeName("NewTabPage.SelectedPageType",
117 kDefaultAppsTrialName), 105 kDefaultAppsTrialName),
118 shown_page_type, kHistogramEnumerationMax); 106 shown_page_type, kHistogramEnumerationMax);
119 } 107 }
120 } 108 }
121 109
122 void NewTabPageHandler::HandleIntroMessageDismissed(const ListValue* args) {
123 PrefService* prefs = g_browser_process->local_state();
124 prefs->SetInteger(prefs::kNtp4IntroDisplayCount, kIntroDisplayMax + 1);
125 Notify(chrome::NTP4_INTRO_PREF_CHANGED);
126 }
127
128 void NewTabPageHandler::HandleIntroMessageSeen(const ListValue* args) {
129 PrefService* prefs = g_browser_process->local_state();
130 int intro_displays = prefs->GetInteger(prefs::kNtp4IntroDisplayCount);
131 prefs->SetInteger(prefs::kNtp4IntroDisplayCount, intro_displays + 1);
132 Notify(chrome::NTP4_INTRO_PREF_CHANGED);
133 }
134
135 // static 110 // static
136 void NewTabPageHandler::RegisterUserPrefs(PrefService* prefs) { 111 void NewTabPageHandler::RegisterUserPrefs(PrefService* prefs) {
137 // TODO(estade): should be syncable. 112 // TODO(estade): should be syncable.
138 prefs->RegisterIntegerPref(prefs::kNtpShownPage, APPS_PAGE_ID, 113 prefs->RegisterIntegerPref(prefs::kNtpShownPage, APPS_PAGE_ID,
139 PrefService::UNSYNCABLE_PREF); 114 PrefService::UNSYNCABLE_PREF);
140 } 115 }
141 116
142 // static 117 // static
143 void NewTabPageHandler::RegisterPrefs(PrefService* prefs) {
144 prefs->RegisterIntegerPref(prefs::kNtp4IntroDisplayCount, 0,
145 PrefService::UNSYNCABLE_PREF);
146 }
147
148 // static
149 void NewTabPageHandler::GetLocalizedValues(Profile* profile, 118 void NewTabPageHandler::GetLocalizedValues(Profile* profile,
150 DictionaryValue* values) { 119 DictionaryValue* values) {
151 values->SetInteger("most_visited_page_id", MOST_VISITED_PAGE_ID); 120 values->SetInteger("most_visited_page_id", MOST_VISITED_PAGE_ID);
152 values->SetInteger("apps_page_id", APPS_PAGE_ID); 121 values->SetInteger("apps_page_id", APPS_PAGE_ID);
153 values->SetInteger("suggestions_page_id", SUGGESTIONS_PAGE_ID); 122 values->SetInteger("suggestions_page_id", SUGGESTIONS_PAGE_ID);
154 123
155 PrefService* prefs = profile->GetPrefs(); 124 PrefService* prefs = profile->GetPrefs();
156 int shown_page = prefs->GetInteger(prefs::kNtpShownPage); 125 int shown_page = prefs->GetInteger(prefs::kNtpShownPage);
157 values->SetInteger("shown_page_type", shown_page & ~INDEX_MASK); 126 values->SetInteger("shown_page_type", shown_page & ~INDEX_MASK);
158 values->SetInteger("shown_page_index", shown_page & INDEX_MASK); 127 values->SetInteger("shown_page_index", shown_page & INDEX_MASK);
159
160 #if !defined(USE_AURA)
161 // Only show intro bubble for non-aura build.
162
163 PrefService* local_state = g_browser_process->local_state();
164 int intro_displays = local_state->GetInteger(prefs::kNtp4IntroDisplayCount);
165 // This preference used to exist in profile, so check the profile if it has
166 // not been set in local state yet.
167 if (!intro_displays) {
168 prefs->RegisterIntegerPref(prefs::kNtp4IntroDisplayCount, 0,
169 PrefService::UNSYNCABLE_PREF);
170 intro_displays = prefs->GetInteger(prefs::kNtp4IntroDisplayCount);
171 if (intro_displays)
172 local_state->SetInteger(prefs::kNtp4IntroDisplayCount, intro_displays);
173 }
174 if (intro_displays <= kIntroDisplayMax) {
175 values->SetString("ntp4_intro_message",
176 l10n_util::GetStringUTF16(IDS_NTP4_INTRO_MESSAGE));
177 values->SetString("ntp4_intro_url", kNtp4IntroURL);
178 }
179 #endif
180 }
181
182 // static
183 void NewTabPageHandler::DismissIntroMessage(PrefService* prefs) {
184 prefs->SetInteger(prefs::kNtp4IntroDisplayCount, kIntroDisplayMax + 1);
185 // No need to send notification to update resource cache, because this method
186 // is only called during startup before the ntp resource cache is constructed.
187 } 128 }
188 129
189 void NewTabPageHandler::Notify(chrome::NotificationType notification_type) { 130 void NewTabPageHandler::Notify(chrome::NotificationType notification_type) {
190 content::NotificationService* service = 131 content::NotificationService* service =
191 content::NotificationService::current(); 132 content::NotificationService::current();
192 service->Notify(notification_type, 133 service->Notify(notification_type,
193 content::Source<NewTabPageHandler>(this), 134 content::Source<NewTabPageHandler>(this),
194 content::NotificationService::NoDetails()); 135 content::NotificationService::NoDetails());
195 } 136 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/new_tab_page_handler.h ('k') | chrome/browser/ui/webui/ntp/ntp_resource_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698