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

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

Issue 10211010: Sync UI: Remove the StopSyncingHandler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes. Created 8 years, 7 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/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"
(...skipping 15 matching lines...) Expand all
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 #include "content/public/browser/web_contents.h"
29 29
30 using content::NavigationController; 30 using content::NavigationController;
31 using content::OpenURLParams; 31 using content::OpenURLParams;
32 using content::Referrer; 32 using content::Referrer;
33 33
34 namespace { 34 namespace {
35 35
36 // User actions on the sync promo (aka "Sign in to Chrome"). 36 // User actions on the sync promo, i.e., "Sign in to Chrome".
37 enum SyncPromoUserFlowActionEnums { 37 enum SyncPromoUserFlowActionEnums {
38 SYNC_PROMO_VIEWED, 38 SYNC_PROMO_VIEWED,
39 SYNC_PROMO_LEARN_MORE_CLICKED, 39 SYNC_PROMO_LEARN_MORE_CLICKED,
40 SYNC_PROMO_ACCOUNT_HELP_CLICKED, 40 SYNC_PROMO_ACCOUNT_HELP_CLICKED,
41 SYNC_PROMO_CREATE_ACCOUNT_CLICKED, 41 SYNC_PROMO_CREATE_ACCOUNT_CLICKED,
42 SYNC_PROMO_SKIP_CLICKED, 42 SYNC_PROMO_SKIP_CLICKED,
43 SYNC_PROMO_SIGN_IN_ATTEMPTED, 43 SYNC_PROMO_SIGN_IN_ATTEMPTED,
44 SYNC_PROMO_SIGNED_IN_SUCCESSFULLY, 44 SYNC_PROMO_SIGNED_IN_SUCCESSFULLY,
45 SYNC_PROMO_ADVANCED_CLICKED, 45 SYNC_PROMO_ADVANCED_CLICKED,
46 SYNC_PROMO_ENCRYPTION_HELP_CLICKED, 46 SYNC_PROMO_ENCRYPTION_HELP_CLICKED,
47 SYNC_PROMO_CANCELLED_AFTER_SIGN_IN, 47 SYNC_PROMO_CANCELLED_AFTER_SIGN_IN,
48 SYNC_PROMO_CONFIRMED_AFTER_SIGN_IN, 48 SYNC_PROMO_CONFIRMED_AFTER_SIGN_IN,
49 SYNC_PROMO_CLOSED_TAB, 49 SYNC_PROMO_CLOSED_TAB,
50 SYNC_PROMO_CLOSED_WINDOW, 50 SYNC_PROMO_CLOSED_WINDOW,
51 SYNC_PROMO_LEFT_DURING_THROBBER, 51 SYNC_PROMO_LEFT_DURING_THROBBER,
52 SYNC_PROMO_BUCKET_BOUNDARY, 52 SYNC_PROMO_BUCKET_BOUNDARY,
53 SYNC_PROMO_FIRST_VALID_JS_ACTION = SYNC_PROMO_LEARN_MORE_CLICKED, 53 SYNC_PROMO_FIRST_VALID_JS_ACTION = SYNC_PROMO_LEARN_MORE_CLICKED,
54 SYNC_PROMO_LAST_VALID_JS_ACTION = SYNC_PROMO_CONFIRMED_AFTER_SIGN_IN, 54 SYNC_PROMO_LAST_VALID_JS_ACTION = SYNC_PROMO_CONFIRMED_AFTER_SIGN_IN,
55 }; 55 };
56 56
57 // This was added because of the need to change the existing UMA enum for the 57 // This was added because of the need to change the existing UMA enum for the
58 // sync promo mid-flight. Ideally these values would be contiguous, but the 58 // sync promo mid-flight. Ideally these values would be contiguous, but the real
59 // real world is not always ideal. 59 // world is not always ideal.
60 static bool IsValidUserFlowAction(int action) { 60 static bool IsValidUserFlowAction(int action) {
61 return (action >= SYNC_PROMO_FIRST_VALID_JS_ACTION && 61 return (action >= SYNC_PROMO_FIRST_VALID_JS_ACTION &&
62 action <= SYNC_PROMO_LAST_VALID_JS_ACTION) || 62 action <= SYNC_PROMO_LAST_VALID_JS_ACTION) ||
63 action == SYNC_PROMO_LEFT_DURING_THROBBER; 63 action == SYNC_PROMO_LEFT_DURING_THROBBER;
64 } 64 }
65 65
66 } // namespace 66 } // namespace
67 67
68 SyncPromoHandler::SyncPromoHandler(ProfileManager* profile_manager) 68 SyncPromoHandler::SyncPromoHandler(ProfileManager* profile_manager)
69 : SyncSetupHandler(profile_manager), 69 : SyncSetupHandler(profile_manager),
70 prefs_(NULL),
70 window_already_closed_(false) { 71 window_already_closed_(false) {
71 } 72 }
72 73
73 SyncPromoHandler::~SyncPromoHandler() { 74 SyncPromoHandler::~SyncPromoHandler() {
74 } 75 }
75 76
76 // static 77 // static
77 void SyncPromoHandler::RegisterUserPrefs(PrefService* prefs) { 78 void SyncPromoHandler::RegisterUserPrefs(PrefService* prefs) {
78 prefs->RegisterIntegerPref(prefs::kSyncPromoViewCount, 0, 79 prefs->RegisterIntegerPref(prefs::kSyncPromoViewCount, 0,
79 PrefService::UNSYNCABLE_PREF); 80 PrefService::UNSYNCABLE_PREF);
(...skipping 12 matching lines...) Expand all
92 IsViewSourceMode()) { 93 IsViewSourceMode()) {
93 // Listen to see if the tab we're in gets closed. 94 // Listen to see if the tab we're in gets closed.
94 registrar_.Add(this, chrome::NOTIFICATION_TAB_CLOSING, 95 registrar_.Add(this, chrome::NOTIFICATION_TAB_CLOSING,
95 content::Source<NavigationController>( 96 content::Source<NavigationController>(
96 &web_ui()->GetWebContents()->GetController())); 97 &web_ui()->GetWebContents()->GetController()));
97 // Listen to see if the window we're in gets closed. 98 // Listen to see if the window we're in gets closed.
98 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSING, 99 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSING,
99 content::NotificationService::AllSources()); 100 content::NotificationService::AllSources());
100 } 101 }
101 102
102 web_ui()->RegisterMessageCallback("SyncPromo:Close", 103 web_ui()->RegisterMessageCallback(
104 "SyncPromo:Close",
103 base::Bind(&SyncPromoHandler::HandleCloseSyncPromo, 105 base::Bind(&SyncPromoHandler::HandleCloseSyncPromo,
104 base::Unretained(this))); 106 base::Unretained(this)));
105 web_ui()->RegisterMessageCallback("SyncPromo:Initialize", 107 web_ui()->RegisterMessageCallback(
108 "SyncPromo:Initialize",
106 base::Bind(&SyncPromoHandler::HandleInitializeSyncPromo, 109 base::Bind(&SyncPromoHandler::HandleInitializeSyncPromo,
107 base::Unretained(this))); 110 base::Unretained(this)));
108 web_ui()->RegisterMessageCallback("SyncPromo:RecordSignInAttempts", 111 web_ui()->RegisterMessageCallback(
112 "SyncPromo:RecordSignInAttempts",
109 base::Bind(&SyncPromoHandler::HandleRecordSignInAttempts, 113 base::Bind(&SyncPromoHandler::HandleRecordSignInAttempts,
110 base::Unretained(this))); 114 base::Unretained(this)));
111 web_ui()->RegisterMessageCallback("SyncPromo:RecordThrobberTime", 115 web_ui()->RegisterMessageCallback(
116 "SyncPromo:RecordThrobberTime",
112 base::Bind(&SyncPromoHandler::HandleRecordThrobberTime, 117 base::Bind(&SyncPromoHandler::HandleRecordThrobberTime,
113 base::Unretained(this))); 118 base::Unretained(this)));
114 web_ui()->RegisterMessageCallback("SyncPromo:ShowAdvancedSettings", 119 web_ui()->RegisterMessageCallback(
120 "SyncPromo:ShowAdvancedSettings",
115 base::Bind(&SyncPromoHandler::HandleShowAdvancedSettings, 121 base::Bind(&SyncPromoHandler::HandleShowAdvancedSettings,
116 base::Unretained(this))); 122 base::Unretained(this)));
117 web_ui()->RegisterMessageCallback("SyncPromo:UserFlowAction", 123 web_ui()->RegisterMessageCallback(
124 "SyncPromo:UserFlowAction",
118 base::Bind(&SyncPromoHandler::HandleUserFlowAction, 125 base::Bind(&SyncPromoHandler::HandleUserFlowAction,
119 base::Unretained(this))); 126 base::Unretained(this)));
120 web_ui()->RegisterMessageCallback("SyncPromo:UserSkipped", 127 web_ui()->RegisterMessageCallback(
128 "SyncPromo:UserSkipped",
121 base::Bind(&SyncPromoHandler::HandleUserSkipped, 129 base::Bind(&SyncPromoHandler::HandleUserSkipped,
122 base::Unretained(this))); 130 base::Unretained(this)));
123 SyncSetupHandler::RegisterMessages(); 131 SyncSetupHandler::RegisterMessages();
124 } 132 }
125 133
126 void SyncPromoHandler::RecordSignin() { 134 void SyncPromoHandler::RecordSignin() {
127 sync_promo_trial::RecordUserSignedIn(web_ui()); 135 sync_promo_trial::RecordUserSignedIn(web_ui());
128 } 136 }
129 137
130 void SyncPromoHandler::DisplayConfigureSync(bool show_advanced, 138 void SyncPromoHandler::DisplayConfigureSync(bool show_advanced,
131 bool passphrase_failed) { 139 bool passphrase_failed) {
132 ProfileSyncService* service = GetSyncService(); 140 ProfileSyncService* service = GetSyncService();
133 DCHECK(service); 141 DCHECK(service);
134 if (service->IsPassphraseRequired()) { 142 if (service->IsPassphraseRequired()) {
135 // If a passphrase is required then we must show the configure pane. 143 // If a passphrase is required then we must show the configure pane.
136 SyncSetupHandler::DisplayConfigureSync(true, passphrase_failed); 144 SyncSetupHandler::DisplayConfigureSync(true, passphrase_failed);
137 } else { 145 } else {
138 // If no passphrase is required then skip the configure pane and sync 146 // If no passphrase is required then skip the configure pane and sync
139 // everything by default. This makes the first run experience simpler. 147 // everything by default. This makes the first run experience simpler. Note,
140 // Note, there's an advanced link in the sync promo that takes users 148 // there's an advanced link in the sync promo that takes users to Settings
141 // to Settings where the configure pane is not skipped. 149 // where the configure pane is not skipped.
142 service->OnUserChoseDatatypes(true, syncable::ModelTypeSet()); 150 service->OnUserChoseDatatypes(true, syncable::ModelTypeSet());
143 ConfigureSyncDone(); 151 ConfigureSyncDone();
144 } 152 }
145 } 153 }
146 154
147 void SyncPromoHandler::Observe(int type, 155 void SyncPromoHandler::Observe(int type,
148 const content::NotificationSource& source, 156 const content::NotificationSource& source,
149 const content::NotificationDetails& details) { 157 const content::NotificationDetails& details) {
150 switch (type) { 158 switch (type) {
151 case chrome::NOTIFICATION_TAB_CLOSING: { 159 case chrome::NOTIFICATION_TAB_CLOSING: {
(...skipping 22 matching lines...) Expand all
174 182
175 void SyncPromoHandler::HandleCloseSyncPromo(const base::ListValue* args) { 183 void SyncPromoHandler::HandleCloseSyncPromo(const base::ListValue* args) {
176 CloseSyncSetup(); 184 CloseSyncSetup();
177 185
178 // If the user has signed in then set the pref to show them NTP bubble 186 // If the user has signed in then set the pref to show them NTP bubble
179 // confirming that they're signed in. 187 // confirming that they're signed in.
180 std::string username = prefs_->GetString(prefs::kGoogleServicesUsername); 188 std::string username = prefs_->GetString(prefs::kGoogleServicesUsername);
181 if (!username.empty()) 189 if (!username.empty())
182 prefs_->SetBoolean(prefs::kSyncPromoShowNTPBubble, true); 190 prefs_->SetBoolean(prefs::kSyncPromoShowNTPBubble, true);
183 191
184 // If the browser window is being closed then don't try to navigate to 192 // If the browser window is being closed then don't try to navigate to another
185 // another URL. This prevents the browser window from flashing during 193 // URL. This prevents the browser window from flashing during close.
186 // close.
187 Browser* browser = 194 Browser* browser =
188 BrowserList::FindBrowserWithWebContents(web_ui()->GetWebContents()); 195 BrowserList::FindBrowserWithWebContents(web_ui()->GetWebContents());
189 if (!browser || !browser->IsAttemptingToCloseBrowser()) { 196 if (!browser || !browser->IsAttemptingToCloseBrowser()) {
190 GURL url = SyncPromoUI::GetNextPageURLForSyncPromoURL( 197 GURL url = SyncPromoUI::GetNextPageURLForSyncPromoURL(
191 web_ui()->GetWebContents()->GetURL()); 198 web_ui()->GetWebContents()->GetURL());
192 OpenURLParams params( 199 OpenURLParams params(
193 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, false); 200 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, false);
194 web_ui()->GetWebContents()->OpenURL(params); 201 web_ui()->GetWebContents()->OpenURL(params);
195 } 202 }
196 } 203 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 int adjusted = GetViewCount() + amount; 268 int adjusted = GetViewCount() + amount;
262 prefs_->SetInteger(prefs::kSyncPromoViewCount, adjusted); 269 prefs_->SetInteger(prefs::kSyncPromoViewCount, adjusted);
263 return adjusted; 270 return adjusted;
264 } 271 }
265 272
266 void SyncPromoHandler::RecordUserFlowAction(int action) { 273 void SyncPromoHandler::RecordUserFlowAction(int action) {
267 // Send an enumeration to our single user flow histogram. 274 // Send an enumeration to our single user flow histogram.
268 UMA_HISTOGRAM_ENUMERATION("SyncPromo.UserFlow", action, 275 UMA_HISTOGRAM_ENUMERATION("SyncPromo.UserFlow", action,
269 SYNC_PROMO_BUCKET_BOUNDARY); 276 SYNC_PROMO_BUCKET_BOUNDARY);
270 } 277 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options2/stop_syncing_handler.cc ('k') | chrome/browser/ui/webui/sync_setup_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698