Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "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_trial.h" | |
| 18 #include "chrome/browser/ui/webui/sync_promo_ui.h" | 19 #include "chrome/browser/ui/webui/sync_promo_ui.h" |
| 19 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
| 20 #include "chrome/common/extensions/extension_constants.h" | 21 #include "chrome/common/extensions/extension_constants.h" |
| 21 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 22 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| 23 #include "content/browser/tab_contents/tab_contents.h" | 24 #include "content/browser/tab_contents/tab_contents.h" |
| 24 #include "content/public/browser/notification_details.h" | 25 #include "content/public/browser/notification_details.h" |
| 25 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 base::Unretained(this))); | 114 base::Unretained(this))); |
| 114 web_ui_->RegisterMessageCallback("SyncPromo:UserFlowAction", | 115 web_ui_->RegisterMessageCallback("SyncPromo:UserFlowAction", |
| 115 base::Bind(&SyncPromoHandler::HandleUserFlowAction, | 116 base::Bind(&SyncPromoHandler::HandleUserFlowAction, |
| 116 base::Unretained(this))); | 117 base::Unretained(this))); |
| 117 web_ui_->RegisterMessageCallback("SyncPromo:UserSkipped", | 118 web_ui_->RegisterMessageCallback("SyncPromo:UserSkipped", |
| 118 base::Bind(&SyncPromoHandler::HandleUserSkipped, | 119 base::Bind(&SyncPromoHandler::HandleUserSkipped, |
| 119 base::Unretained(this))); | 120 base::Unretained(this))); |
| 120 SyncSetupHandler::RegisterMessages(); | 121 SyncSetupHandler::RegisterMessages(); |
| 121 } | 122 } |
| 122 | 123 |
| 124 void SyncPromoHandler::ShowGaiaSuccessAndClose() { | |
| 125 if (SyncPromoTrial::IsExperimentActive()) | |
| 126 SyncPromoTrial::RecordUserSignedIn(); | |
| 127 | |
| 128 SyncSetupHandler::ShowGaiaSuccessAndClose(); | |
| 129 } | |
| 130 | |
| 131 void SyncPromoHandler::ShowGaiaSuccessAndSettingUp() { | |
| 132 if (SyncPromoTrial::IsExperimentActive()) | |
| 133 SyncPromoTrial::RecordUserSignedIn(); | |
| 134 | |
| 135 SyncSetupHandler::ShowGaiaSuccessAndSettingUp(); | |
| 136 } | |
| 137 | |
| 123 void SyncPromoHandler::ShowConfigure(const base::DictionaryValue& args) { | 138 void SyncPromoHandler::ShowConfigure(const base::DictionaryValue& args) { |
| 124 bool usePassphrase = false; | 139 bool usePassphrase = false; |
| 125 args.GetBoolean("usePassphrase", &usePassphrase); | 140 args.GetBoolean("usePassphrase", &usePassphrase); |
| 126 | 141 |
| 127 if (usePassphrase) { | 142 if (usePassphrase) { |
| 128 // 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. |
| 129 SyncSetupHandler::ShowConfigure(args); | 144 SyncSetupHandler::ShowConfigure(args); |
| 130 } else { | 145 } else { |
| 131 // 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 |
| 132 // everything by default. This makes the first run experience simpler. | 147 // everything by default. This makes the first run experience simpler. |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 157 window_already_closed_ = true; | 172 window_already_closed_ = true; |
| 158 } | 173 } |
| 159 break; | 174 break; |
| 160 } | 175 } |
| 161 default: { | 176 default: { |
| 162 NOTREACHED(); | 177 NOTREACHED(); |
| 163 } | 178 } |
| 164 } | 179 } |
| 165 } | 180 } |
| 166 | 181 |
| 182 void SyncPromoHandler::HandleSubmitAuth(const base::ListValue* args) { | |
| 183 // Call the original implementation. | |
|
sail
2011/11/28 16:34:25
comment should say why you're doing something not
SteveT
2011/11/28 20:07:32
Oops sorry - this was from the remnants of some ea
| |
| 184 SyncSetupHandler::HandleSubmitAuth(args); | |
| 185 } | |
| 186 | |
| 167 void SyncPromoHandler::ShowSetupUI() { | 187 void SyncPromoHandler::ShowSetupUI() { |
| 168 ProfileSyncService* service = | 188 ProfileSyncService* service = |
| 169 Profile::FromWebUI(web_ui_)->GetProfileSyncService(); | 189 Profile::FromWebUI(web_ui_)->GetProfileSyncService(); |
| 170 service->get_wizard().Step(SyncSetupWizard::GetLoginState()); | 190 service->get_wizard().Step(SyncSetupWizard::GetLoginState()); |
| 171 } | 191 } |
| 172 | 192 |
| 173 void SyncPromoHandler::HandleCloseSyncPromo(const base::ListValue* args) { | 193 void SyncPromoHandler::HandleCloseSyncPromo(const base::ListValue* args) { |
| 174 CloseSyncSetup(); | 194 CloseSyncSetup(); |
| 175 | 195 |
| 176 // 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 |
| 177 // confirming that they're signed in. | 197 // confirming that they're signed in. |
| 178 std::string username = prefs_->GetString(prefs::kGoogleServicesUsername); | 198 std::string username = prefs_->GetString(prefs::kGoogleServicesUsername); |
| 179 if (!username.empty()) | 199 if (!username.empty()) |
| 180 prefs_->SetBoolean(prefs::kSyncPromoShowNTPBubble, true); | 200 prefs_->SetBoolean(prefs::kSyncPromoShowNTPBubble, true); |
| 181 | 201 |
| 182 GURL url = SyncPromoUI::GetNextPageURLForSyncPromoURL( | 202 GURL url = SyncPromoUI::GetNextPageURLForSyncPromoURL( |
| 183 web_ui_->tab_contents()->GetURL()); | 203 web_ui_->tab_contents()->GetURL()); |
| 184 web_ui_->tab_contents()->OpenURL(url, GURL(), CURRENT_TAB, | 204 web_ui_->tab_contents()->OpenURL(url, GURL(), CURRENT_TAB, |
| 185 content::PAGE_TRANSITION_LINK); | 205 content::PAGE_TRANSITION_LINK); |
| 186 } | 206 } |
| 187 | 207 |
| 188 void SyncPromoHandler::HandleInitializeSyncPromo(const base::ListValue* args) { | 208 void SyncPromoHandler::HandleInitializeSyncPromo(const base::ListValue* args) { |
| 189 base::FundamentalValue visible(SyncPromoUI::GetShowTitleForSyncPromoURL( | 209 // If the promo is also the Chrome launch page, we want to show the title and |
| 190 web_ui_->tab_contents()->GetURL())); | 210 // load the promo experiments for the page. |
| 211 bool is_launch_page = SyncPromoUI::GetLaunchPageForSyncPromoURL( | |
| 212 web_ui_->tab_contents()->GetURL()); | |
| 213 if (is_launch_page) | |
| 214 LoadPromoExperiments(); | |
| 215 base::FundamentalValue visible(is_launch_page); | |
| 191 web_ui_->CallJavascriptFunction("SyncSetupOverlay.setPromoTitleVisible", | 216 web_ui_->CallJavascriptFunction("SyncSetupOverlay.setPromoTitleVisible", |
| 192 visible); | 217 visible); |
| 193 | 218 |
| 194 OpenSyncSetup(); | 219 OpenSyncSetup(); |
| 195 // We don't need to compute anything for this, just do this every time. | 220 // We don't need to compute anything for this, just do this every time. |
| 196 RecordUserFlowAction(SYNC_PROMO_VIEWED); | 221 RecordUserFlowAction(SYNC_PROMO_VIEWED); |
| 197 // Increment view count first and show natural numbers in stats rather than 0 | 222 // Increment view count first and show natural numbers in stats rather than 0 |
| 198 // based starting point (if it happened to be our first time showing this). | 223 // based starting point (if it happened to be our first time showing this). |
| 199 IncrementViewCountBy(1); | 224 IncrementViewCountBy(1); |
| 200 // Record +1 for every view. This is the only thing we record that's not part | 225 // Record +1 for every view. This is the only thing we record that's not part |
| 201 // of the user flow histogram. | 226 // of the user flow histogram. |
| 202 UMA_HISTOGRAM_COUNTS("SyncPromo.NumTimesViewed", GetViewCount()); | 227 UMA_HISTOGRAM_COUNTS("SyncPromo.NumTimesViewed", GetViewCount()); |
| 203 } | 228 } |
| 204 | 229 |
| 230 void SyncPromoHandler::LoadPromoExperiments() { | |
| 231 // If we're not running the trial, we don't have to set the string since | |
| 232 // it is already set to the default. | |
| 233 if (!SyncPromoTrial::IsExperimentActive()) | |
| 234 return; | |
| 235 | |
| 236 std::string resource_name; | |
| 237 SyncPromoTrial::Group group = SyncPromoTrial::GetGroup(); | |
| 238 switch (group) { | |
| 239 case SyncPromoTrial::PROMO_MSG_A: | |
| 240 resource_name = "promoMessageBodyA"; | |
| 241 break; | |
| 242 case SyncPromoTrial::PROMO_MSG_B: | |
| 243 resource_name = "promoMessageBodyB"; | |
| 244 break; | |
| 245 case SyncPromoTrial::PROMO_MSG_C: | |
| 246 resource_name = "promoMessageBodyC"; | |
| 247 break; | |
| 248 case SyncPromoTrial::PROMO_MSG_D: | |
| 249 resource_name = "promoMessageBodyD"; | |
| 250 break; | |
| 251 default: | |
| 252 NOTREACHED() << "Unrecognized SyncPromoTrial::Group."; | |
| 253 resource_name = "promoMessageBodyA"; | |
| 254 break; | |
| 255 } | |
| 256 | |
| 257 SyncPromoTrial::RecordUserSawMessage(); | |
| 258 | |
| 259 // Call back to javascript with the resource name and let them set it. | |
| 260 StringValue result(resource_name); | |
| 261 web_ui_->CallJavascriptFunction("SyncSetupOverlay.populatePromoMessage", | |
| 262 result); | |
| 263 } | |
| 264 | |
| 205 void SyncPromoHandler::HandleShowAdvancedSettings( | 265 void SyncPromoHandler::HandleShowAdvancedSettings( |
| 206 const base::ListValue* args) { | 266 const base::ListValue* args) { |
| 207 CloseSyncSetup(); | 267 CloseSyncSetup(); |
| 208 std::string url(chrome::kChromeUISettingsURL); | 268 std::string url(chrome::kChromeUISettingsURL); |
| 209 url += chrome::kSyncSetupSubPage; | 269 url += chrome::kSyncSetupSubPage; |
| 210 web_ui_->tab_contents()->OpenURL(GURL(url), GURL(), CURRENT_TAB, | 270 web_ui_->tab_contents()->OpenURL(GURL(url), GURL(), CURRENT_TAB, |
| 211 content::PAGE_TRANSITION_LINK); | 271 content::PAGE_TRANSITION_LINK); |
| 212 RecordUserFlowAction(SYNC_PROMO_ADVANCED_CLICKED); | 272 RecordUserFlowAction(SYNC_PROMO_ADVANCED_CLICKED); |
| 213 } | 273 } |
| 214 | 274 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 int adjusted = GetViewCount() + amount; | 314 int adjusted = GetViewCount() + amount; |
| 255 prefs_->SetInteger(prefs::kSyncPromoViewCount, adjusted); | 315 prefs_->SetInteger(prefs::kSyncPromoViewCount, adjusted); |
| 256 return adjusted; | 316 return adjusted; |
| 257 } | 317 } |
| 258 | 318 |
| 259 void SyncPromoHandler::RecordUserFlowAction(int action) { | 319 void SyncPromoHandler::RecordUserFlowAction(int action) { |
| 260 // Send an enumeration to our single user flow histogram. | 320 // Send an enumeration to our single user flow histogram. |
| 261 UMA_HISTOGRAM_ENUMERATION("SyncPromo.UserFlow", action, | 321 UMA_HISTOGRAM_ENUMERATION("SyncPromo.UserFlow", action, |
| 262 SYNC_PROMO_BUCKET_BOUNDARY); | 322 SYNC_PROMO_BUCKET_BOUNDARY); |
| 263 } | 323 } |
| OLD | NEW |