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

Side by Side Diff: chrome/browser/ui/webui/sync_promo/sync_promo_handler.cc

Issue 9003014: Replace WebUI::tab_contents() with web_contents() and switch all users to use web_contents.h inst... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/sync_promo/sync_promo_handler.h" 5 #include "chrome/browser/ui/webui/sync_promo/sync_promo_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/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/time.h" 10 #include "base/time.h"
11 #include "chrome/browser/prefs/pref_service.h" 11 #include "chrome/browser/prefs/pref_service.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/sync/profile_sync_service.h" 13 #include "chrome/browser/sync/profile_sync_service.h"
14 #include "chrome/browser/sync/sync_setup_flow.h" 14 #include "chrome/browser/sync/sync_setup_flow.h"
15 #include "chrome/browser/tabs/tab_strip_model.h" 15 #include "chrome/browser/tabs/tab_strip_model.h"
16 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_list.h" 17 #include "chrome/browser/ui/browser_list.h"
18 #include "chrome/browser/ui/webui/sync_promo/sync_promo_trial.h" 18 #include "chrome/browser/ui/webui/sync_promo/sync_promo_trial.h"
19 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" 19 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h"
20 #include "chrome/common/chrome_notification_types.h" 20 #include "chrome/common/chrome_notification_types.h"
21 #include "chrome/common/extensions/extension_constants.h" 21 #include "chrome/common/extensions/extension_constants.h"
22 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
23 #include "chrome/common/url_constants.h" 23 #include "chrome/common/url_constants.h"
24 #include "content/browser/tab_contents/tab_contents.h" 24 #include "content/browser/tab_contents/navigation_controller.h"
25 #include "content/public/browser/navigation_entry.h" 25 #include "content/public/browser/navigation_entry.h"
26 #include "content/public/browser/notification_details.h" 26 #include "content/public/browser/notification_details.h"
27 #include "content/public/browser/notification_service.h" 27 #include "content/public/browser/notification_service.h"
28 #include "content/public/browser/web_contents.h"
28 29
29 using content::OpenURLParams; 30 using content::OpenURLParams;
30 using content::Referrer; 31 using content::Referrer;
31 32
32 namespace { 33 namespace {
33 34
34 // User actions on the sync promo (aka "Sign in to Chrome"). 35 // User actions on the sync promo (aka "Sign in to Chrome").
35 enum SyncPromoUserFlowActionEnums { 36 enum SyncPromoUserFlowActionEnums {
36 SYNC_PROMO_VIEWED, 37 SYNC_PROMO_VIEWED,
37 SYNC_PROMO_LEARN_MORE_CLICKED, 38 SYNC_PROMO_LEARN_MORE_CLICKED,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 PrefService::UNSYNCABLE_PREF); 80 PrefService::UNSYNCABLE_PREF);
80 } 81 }
81 82
82 void SyncPromoHandler::RegisterMessages() { 83 void SyncPromoHandler::RegisterMessages() {
83 // Keep a reference to the preferences service for convenience and it's 84 // Keep a reference to the preferences service for convenience and it's
84 // probably a little faster that getting it via Profile::FromWebUI() every 85 // probably a little faster that getting it via Profile::FromWebUI() every
85 // time we need to interact with preferences. 86 // time we need to interact with preferences.
86 prefs_ = Profile::FromWebUI(web_ui())->GetPrefs(); 87 prefs_ = Profile::FromWebUI(web_ui())->GetPrefs();
87 DCHECK(prefs_); 88 DCHECK(prefs_);
88 // Ignore events from view-source:chrome://syncpromo. 89 // Ignore events from view-source:chrome://syncpromo.
89 if (!web_ui()->tab_contents()->GetController().GetActiveEntry()-> 90 if (!web_ui()->web_contents()->GetController().GetActiveEntry()->
90 IsViewSourceMode()) { 91 IsViewSourceMode()) {
91 // Listen to see if the tab we're in gets closed. 92 // Listen to see if the tab we're in gets closed.
92 registrar_.Add(this, content::NOTIFICATION_TAB_CLOSING, 93 registrar_.Add(this, content::NOTIFICATION_TAB_CLOSING,
93 content::Source<NavigationController>( 94 content::Source<NavigationController>(
94 &web_ui()->tab_contents()->GetController())); 95 &web_ui()->web_contents()->GetController()));
95 // Listen to see if the window we're in gets closed. 96 // Listen to see if the window we're in gets closed.
96 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSING, 97 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSING,
97 content::NotificationService::AllSources()); 98 content::NotificationService::AllSources());
98 } 99 }
99 100
100 web_ui()->RegisterMessageCallback("SyncPromo:Close", 101 web_ui()->RegisterMessageCallback("SyncPromo:Close",
101 base::Bind(&SyncPromoHandler::HandleCloseSyncPromo, 102 base::Bind(&SyncPromoHandler::HandleCloseSyncPromo,
102 base::Unretained(this))); 103 base::Unretained(this)));
103 web_ui()->RegisterMessageCallback("SyncPromo:Initialize", 104 web_ui()->RegisterMessageCallback("SyncPromo:Initialize",
104 base::Bind(&SyncPromoHandler::HandleInitializeSyncPromo, 105 base::Bind(&SyncPromoHandler::HandleInitializeSyncPromo,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 switch (type) { 157 switch (type) {
157 case content::NOTIFICATION_TAB_CLOSING: { 158 case content::NOTIFICATION_TAB_CLOSING: {
158 if (!window_already_closed_) 159 if (!window_already_closed_)
159 RecordUserFlowAction(SYNC_PROMO_CLOSED_TAB); 160 RecordUserFlowAction(SYNC_PROMO_CLOSED_TAB);
160 break; 161 break;
161 } 162 }
162 case chrome::NOTIFICATION_BROWSER_CLOSING: { 163 case chrome::NOTIFICATION_BROWSER_CLOSING: {
163 // Make sure we're in the tab strip of the closing window. 164 // Make sure we're in the tab strip of the closing window.
164 Browser* browser = content::Source<Browser>(source).ptr(); 165 Browser* browser = content::Source<Browser>(source).ptr();
165 if (browser->tabstrip_model()->GetWrapperIndex( 166 if (browser->tabstrip_model()->GetWrapperIndex(
166 web_ui()->tab_contents()) != TabStripModel::kNoTab) { 167 web_ui()->web_contents()) != TabStripModel::kNoTab) {
167 RecordUserFlowAction(SYNC_PROMO_CLOSED_WINDOW); 168 RecordUserFlowAction(SYNC_PROMO_CLOSED_WINDOW);
168 window_already_closed_ = true; 169 window_already_closed_ = true;
169 } 170 }
170 break; 171 break;
171 } 172 }
172 default: { 173 default: {
173 NOTREACHED(); 174 NOTREACHED();
174 } 175 }
175 } 176 }
176 } 177 }
(...skipping 15 matching lines...) Expand all
192 void SyncPromoHandler::HandleCloseSyncPromo(const base::ListValue* args) { 193 void SyncPromoHandler::HandleCloseSyncPromo(const base::ListValue* args) {
193 CloseSyncSetup(); 194 CloseSyncSetup();
194 195
195 // If the user has signed in then set the pref to show them NTP bubble 196 // If the user has signed in then set the pref to show them NTP bubble
196 // confirming that they're signed in. 197 // confirming that they're signed in.
197 std::string username = prefs_->GetString(prefs::kGoogleServicesUsername); 198 std::string username = prefs_->GetString(prefs::kGoogleServicesUsername);
198 if (!username.empty()) 199 if (!username.empty())
199 prefs_->SetBoolean(prefs::kSyncPromoShowNTPBubble, true); 200 prefs_->SetBoolean(prefs::kSyncPromoShowNTPBubble, true);
200 201
201 GURL url = SyncPromoUI::GetNextPageURLForSyncPromoURL( 202 GURL url = SyncPromoUI::GetNextPageURLForSyncPromoURL(
202 web_ui()->tab_contents()->GetURL()); 203 web_ui()->web_contents()->GetURL());
203 OpenURLParams params( 204 OpenURLParams params(
204 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, false); 205 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, false);
205 web_ui()->tab_contents()->OpenURL(params); 206 web_ui()->web_contents()->OpenURL(params);
206 } 207 }
207 208
208 void SyncPromoHandler::HandleInitializeSyncPromo(const base::ListValue* args) { 209 void SyncPromoHandler::HandleInitializeSyncPromo(const base::ListValue* args) {
209 // If the promo is also the Chrome launch page, we want to show the title and 210 // If the promo is also the Chrome launch page, we want to show the title and
210 // log an event if we are running an experiment. 211 // log an event if we are running an experiment.
211 bool is_launch_page = SyncPromoUI::GetIsLaunchPageForSyncPromoURL( 212 bool is_launch_page = SyncPromoUI::GetIsLaunchPageForSyncPromoURL(
212 web_ui()->tab_contents()->GetURL()); 213 web_ui()->web_contents()->GetURL());
213 if (is_launch_page && sync_promo_trial::IsExperimentActive()) 214 if (is_launch_page && sync_promo_trial::IsExperimentActive())
214 sync_promo_trial::RecordUserSawMessage(); 215 sync_promo_trial::RecordUserSawMessage();
215 base::FundamentalValue visible(is_launch_page); 216 base::FundamentalValue visible(is_launch_page);
216 web_ui()->CallJavascriptFunction("SyncSetupOverlay.setPromoTitleVisible", 217 web_ui()->CallJavascriptFunction("SyncSetupOverlay.setPromoTitleVisible",
217 visible); 218 visible);
218 219
219 OpenSyncSetup(); 220 OpenSyncSetup();
220 // We don't need to compute anything for this, just do this every time. 221 // We don't need to compute anything for this, just do this every time.
221 RecordUserFlowAction(SYNC_PROMO_VIEWED); 222 RecordUserFlowAction(SYNC_PROMO_VIEWED);
222 // Increment view count first and show natural numbers in stats rather than 0 223 // Increment view count first and show natural numbers in stats rather than 0
223 // based starting point (if it happened to be our first time showing this). 224 // based starting point (if it happened to be our first time showing this).
224 IncrementViewCountBy(1); 225 IncrementViewCountBy(1);
225 // Record +1 for every view. This is the only thing we record that's not part 226 // Record +1 for every view. This is the only thing we record that's not part
226 // of the user flow histogram. 227 // of the user flow histogram.
227 UMA_HISTOGRAM_COUNTS("SyncPromo.NumTimesViewed", GetViewCount()); 228 UMA_HISTOGRAM_COUNTS("SyncPromo.NumTimesViewed", GetViewCount());
228 } 229 }
229 230
230 void SyncPromoHandler::HandleShowAdvancedSettings( 231 void SyncPromoHandler::HandleShowAdvancedSettings(
231 const base::ListValue* args) { 232 const base::ListValue* args) {
232 CloseSyncSetup(); 233 CloseSyncSetup();
233 std::string url(chrome::kChromeUISettingsURL); 234 std::string url(chrome::kChromeUISettingsURL);
234 url += chrome::kSyncSetupSubPage; 235 url += chrome::kSyncSetupSubPage;
235 OpenURLParams params( 236 OpenURLParams params(
236 GURL(url), Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, false); 237 GURL(url), Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, false);
237 web_ui()->tab_contents()->OpenURL(params); 238 web_ui()->web_contents()->OpenURL(params);
238 RecordUserFlowAction(SYNC_PROMO_ADVANCED_CLICKED); 239 RecordUserFlowAction(SYNC_PROMO_ADVANCED_CLICKED);
239 } 240 }
240 241
241 // TODO(dbeam): Replace with metricsHandler:recordHistogramTime when it exists. 242 // TODO(dbeam): Replace with metricsHandler:recordHistogramTime when it exists.
242 void SyncPromoHandler::HandleRecordThrobberTime(const base::ListValue* args) { 243 void SyncPromoHandler::HandleRecordThrobberTime(const base::ListValue* args) {
243 double time_double; 244 double time_double;
244 CHECK(args->GetDouble(0, &time_double)); 245 CHECK(args->GetDouble(0, &time_double));
245 UMA_HISTOGRAM_TIMES("SyncPromo.ThrobberTime", 246 UMA_HISTOGRAM_TIMES("SyncPromo.ThrobberTime",
246 base::TimeDelta::FromMilliseconds(time_double)); 247 base::TimeDelta::FromMilliseconds(time_double));
247 } 248 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 int adjusted = GetViewCount() + amount; 281 int adjusted = GetViewCount() + amount;
281 prefs_->SetInteger(prefs::kSyncPromoViewCount, adjusted); 282 prefs_->SetInteger(prefs::kSyncPromoViewCount, adjusted);
282 return adjusted; 283 return adjusted;
283 } 284 }
284 285
285 void SyncPromoHandler::RecordExperimentOutcomesOnSignIn() { 286 void SyncPromoHandler::RecordExperimentOutcomesOnSignIn() {
286 if (sync_promo_trial::IsExperimentActive()) 287 if (sync_promo_trial::IsExperimentActive())
287 sync_promo_trial::RecordUserSignedIn(); 288 sync_promo_trial::RecordUserSignedIn();
288 if (sync_promo_trial::IsPartOfBrandTrialToEnable()) { 289 if (sync_promo_trial::IsPartOfBrandTrialToEnable()) {
289 bool is_start_up = SyncPromoUI::GetIsLaunchPageForSyncPromoURL( 290 bool is_start_up = SyncPromoUI::GetIsLaunchPageForSyncPromoURL(
290 web_ui()->tab_contents()->GetURL()); 291 web_ui()->web_contents()->GetURL());
291 Profile* profile = Profile::FromWebUI(web_ui()); 292 Profile* profile = Profile::FromWebUI(web_ui());
292 sync_promo_trial::RecordUserSignedInWithTrialBrand(is_start_up, profile); 293 sync_promo_trial::RecordUserSignedInWithTrialBrand(is_start_up, profile);
293 } 294 }
294 } 295 }
295 296
296 void SyncPromoHandler::RecordUserFlowAction(int action) { 297 void SyncPromoHandler::RecordUserFlowAction(int action) {
297 // Send an enumeration to our single user flow histogram. 298 // Send an enumeration to our single user flow histogram.
298 UMA_HISTOGRAM_ENUMERATION("SyncPromo.UserFlow", action, 299 UMA_HISTOGRAM_ENUMERATION("SyncPromo.UserFlow", action,
299 SYNC_PROMO_BUCKET_BOUNDARY); 300 SYNC_PROMO_BUCKET_BOUNDARY);
300 } 301 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/sync_internals_ui.cc ('k') | chrome/browser/ui/webui/sync_promo/sync_promo_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698