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

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

Issue 8227038: Sync Promo: Close browser tab when closing promo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix merge issues Created 9 years, 2 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
« no previous file with comments | « chrome/browser/ui/webui/ntp/ntp_login_handler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_handler.h" 5 #include "chrome/browser/ui/webui/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 "chrome/browser/prefs/pref_service.h" 10 #include "chrome/browser/prefs/pref_service.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/sync/profile_sync_service.h" 12 #include "chrome/browser/sync/profile_sync_service.h"
13 #include "chrome/browser/sync/sync_setup_flow.h" 13 #include "chrome/browser/sync/sync_setup_flow.h"
14 #include "chrome/browser/tabs/tab_strip_model.h" 14 #include "chrome/browser/tabs/tab_strip_model.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_list.h"
16 #include "chrome/browser/ui/webui/sync_promo_ui.h" 17 #include "chrome/browser/ui/webui/sync_promo_ui.h"
17 #include "chrome/common/chrome_notification_types.h" 18 #include "chrome/common/chrome_notification_types.h"
18 #include "chrome/common/extensions/extension_constants.h" 19 #include "chrome/common/extensions/extension_constants.h"
19 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
20 #include "chrome/common/url_constants.h" 21 #include "chrome/common/url_constants.h"
21 #include "content/browser/tab_contents/tab_contents.h" 22 #include "content/browser/tab_contents/tab_contents.h"
22 #include "content/common/notification_details.h" 23 #include "content/common/notification_details.h"
23 #include "content/common/notification_service.h" 24 #include "content/common/notification_service.h"
24 25
25 SyncPromoHandler::SyncPromoHandler(ProfileManager* profile_manager) 26 SyncPromoHandler::SyncPromoHandler(ProfileManager* profile_manager)
26 : SyncSetupHandler(profile_manager), window_already_closed_(false) { 27 : SyncSetupHandler(profile_manager),
28 window_already_closed_(false) {
27 } 29 }
28 30
29 SyncPromoHandler::~SyncPromoHandler() { 31 SyncPromoHandler::~SyncPromoHandler() {
30 } 32 }
31 33
32 // static 34 // static
33 void SyncPromoHandler::RegisterUserPrefs(PrefService* prefs) { 35 void SyncPromoHandler::RegisterUserPrefs(PrefService* prefs) {
34 prefs->RegisterIntegerPref(prefs::kSyncPromoViewCount, 0, 36 prefs->RegisterIntegerPref(prefs::kSyncPromoViewCount, 0,
35 PrefService::UNSYNCABLE_PREF); 37 PrefService::UNSYNCABLE_PREF);
36 } 38 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } 118 }
117 119
118 void SyncPromoHandler::ShowSetupUI() { 120 void SyncPromoHandler::ShowSetupUI() {
119 ProfileSyncService* service = 121 ProfileSyncService* service =
120 Profile::FromWebUI(web_ui_)->GetProfileSyncService(); 122 Profile::FromWebUI(web_ui_)->GetProfileSyncService();
121 service->get_wizard().Step(SyncSetupWizard::GetLoginState()); 123 service->get_wizard().Step(SyncSetupWizard::GetLoginState());
122 } 124 }
123 125
124 void SyncPromoHandler::HandleCloseSyncPromo(const base::ListValue* args) { 126 void SyncPromoHandler::HandleCloseSyncPromo(const base::ListValue* args) {
125 CloseSyncSetup(); 127 CloseSyncSetup();
126 web_ui_->tab_contents()->OpenURL(GURL(chrome::kChromeUINewTabURL), 128
127 GURL(), CURRENT_TAB, 129 // If there's no previous page on this tab then it means that the promo was
128 PageTransition::LINK); 130 // displayed at startup. In this case we want to close the browser tab that
131 // the promo is in.
132 if (!web_ui_->tab_contents()->controller().CanGoBack()) {
133 Browser* browser =
134 BrowserList::FindBrowserWithTabContents(web_ui_->tab_contents());
135 browser->CloseTabContents(web_ui_->tab_contents());
136 } else {
137 web_ui_->tab_contents()->OpenURL(GURL(chrome::kChromeUINewTabURL),
138 GURL(), CURRENT_TAB,
139 PageTransition::LINK);
140 }
129 } 141 }
130 142
131 void SyncPromoHandler::HandleInitializeSyncPromo(const base::ListValue* args) { 143 void SyncPromoHandler::HandleInitializeSyncPromo(const base::ListValue* args) {
132 OpenSyncSetup(); 144 OpenSyncSetup();
133 // We don't need to compute anything for this, just do this every time. 145 // We don't need to compute anything for this, just do this every time.
134 RecordUserFlowAction(extension_misc::SYNC_PROMO_VIEWED); 146 RecordUserFlowAction(extension_misc::SYNC_PROMO_VIEWED);
135 // Increment view count first and show natural numbers in stats rather than 0 147 // Increment view count first and show natural numbers in stats rather than 0
136 // based starting point (if it happened to be our first time showing this). 148 // based starting point (if it happened to be our first time showing this).
137 IncrementViewCountBy(1); 149 IncrementViewCountBy(1);
138 // Record +1 for every view. This is the only thing we record that's not part 150 // Record +1 for every view. This is the only thing we record that's not part
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 int adjusted = GetViewCount() + amount; 187 int adjusted = GetViewCount() + amount;
176 prefs_->SetInteger(prefs::kSyncPromoViewCount, adjusted); 188 prefs_->SetInteger(prefs::kSyncPromoViewCount, adjusted);
177 return adjusted; 189 return adjusted;
178 } 190 }
179 191
180 void SyncPromoHandler::RecordUserFlowAction(int action) { 192 void SyncPromoHandler::RecordUserFlowAction(int action) {
181 // Send an enumeration to our single user flow histogram. 193 // Send an enumeration to our single user flow histogram.
182 UMA_HISTOGRAM_ENUMERATION("SyncPromo.UserFlow", action, 194 UMA_HISTOGRAM_ENUMERATION("SyncPromo.UserFlow", action,
183 extension_misc::SYNC_PROMO_BUCKET_BOUNDARY); 195 extension_misc::SYNC_PROMO_BUCKET_BOUNDARY);
184 } 196 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/ntp_login_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698