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 "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/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
| 17 #include "chrome/common/extensions/extension_constants.h" | 18 #include "chrome/common/extensions/extension_constants.h" |
| 18 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 19 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 20 #include "content/browser/tab_contents/tab_contents.h" | 21 #include "content/browser/tab_contents/tab_contents.h" |
| 21 #include "content/common/notification_details.h" | 22 #include "content/common/notification_details.h" |
| 22 #include "content/common/notification_service.h" | 23 #include "content/common/notification_service.h" |
| 23 | 24 |
| 24 SyncPromoHandler::SyncPromoHandler(ProfileManager* profile_manager) | 25 SyncPromoHandler::SyncPromoHandler(ProfileManager* profile_manager) |
| 25 : SyncSetupHandler(profile_manager), window_already_closed_(false) { | 26 : SyncSetupHandler(profile_manager), |
| 27 window_already_closed_(false) { | |
| 26 } | 28 } |
| 27 | 29 |
| 28 SyncPromoHandler::~SyncPromoHandler() { | 30 SyncPromoHandler::~SyncPromoHandler() { |
| 29 } | 31 } |
| 30 | 32 |
| 31 // static | 33 // static |
| 32 void SyncPromoHandler::RegisterUserPrefs(PrefService* prefs) { | 34 void SyncPromoHandler::RegisterUserPrefs(PrefService* prefs) { |
| 33 prefs->RegisterIntegerPref(prefs::kSyncPromoViewCount, 0, | 35 prefs->RegisterIntegerPref(prefs::kSyncPromoViewCount, 0, |
| 34 PrefService::UNSYNCABLE_PREF); | 36 PrefService::UNSYNCABLE_PREF); |
| 35 } | 37 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 } | 117 } |
| 116 | 118 |
| 117 void SyncPromoHandler::ShowSetupUI() { | 119 void SyncPromoHandler::ShowSetupUI() { |
| 118 ProfileSyncService* service = | 120 ProfileSyncService* service = |
| 119 Profile::FromWebUI(web_ui_)->GetProfileSyncService(); | 121 Profile::FromWebUI(web_ui_)->GetProfileSyncService(); |
| 120 service->get_wizard().Step(SyncSetupWizard::GetLoginState()); | 122 service->get_wizard().Step(SyncSetupWizard::GetLoginState()); |
| 121 } | 123 } |
| 122 | 124 |
| 123 void SyncPromoHandler::HandleCloseSyncPromo(const base::ListValue* args) { | 125 void SyncPromoHandler::HandleCloseSyncPromo(const base::ListValue* args) { |
| 124 CloseSyncSetup(); | 126 CloseSyncSetup(); |
| 125 web_ui_->tab_contents()->OpenURL(GURL(chrome::kChromeUINewTabURL), | 127 |
| 126 GURL(), CURRENT_TAB, | 128 // If there's no previous page on this tab then it means that the promo was |
|
James Hawkins
2011/10/12 17:34:18
Is this the best signal we have that the promo was
sail
2011/10/12 17:54:12
An alternative would be to add some kind of parame
| |
| 127 PageTransition::LINK); | 129 // displayed at startup. In this case we want to close the browser tab that |
| 130 // the promo is in. | |
| 131 if (!web_ui_->tab_contents()->controller().CanGoBack()) { | |
| 132 Browser* browser = | |
| 133 BrowserList::FindBrowserWithTabContents(web_ui_->tab_contents()); | |
| 134 browser->CloseTabContents(web_ui_->tab_contents()); | |
| 135 } else { | |
| 136 web_ui_->tab_contents()->OpenURL(GURL(chrome::kChromeUINewTabURL), | |
| 137 GURL(), CURRENT_TAB, | |
| 138 PageTransition::LINK); | |
| 139 } | |
| 128 } | 140 } |
| 129 | 141 |
| 130 void SyncPromoHandler::HandleInitializeSyncPromo(const base::ListValue* args) { | 142 void SyncPromoHandler::HandleInitializeSyncPromo(const base::ListValue* args) { |
| 131 OpenSyncSetup(); | 143 OpenSyncSetup(); |
| 132 // We don't need to compute anything for this, just do this every time. | 144 // We don't need to compute anything for this, just do this every time. |
| 133 RecordUserFlowAction(extension_misc::SYNC_PROMO_VIEWED); | 145 RecordUserFlowAction(extension_misc::SYNC_PROMO_VIEWED); |
| 134 // Increment view count first and show natural numbers in stats rather than 0 | 146 // Increment view count first and show natural numbers in stats rather than 0 |
| 135 // based starting point (if it happened to be our first time showing this). | 147 // based starting point (if it happened to be our first time showing this). |
| 136 IncrementViewCountBy(1); | 148 IncrementViewCountBy(1); |
| 137 // Record +1 for every view. This is the only thing we record that's not part | 149 // Record +1 for every view. This is the only thing we record that's not part |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 int adjusted = GetViewCount() + amount; | 183 int adjusted = GetViewCount() + amount; |
| 172 prefs_->SetInteger(prefs::kSyncPromoViewCount, adjusted); | 184 prefs_->SetInteger(prefs::kSyncPromoViewCount, adjusted); |
| 173 return adjusted; | 185 return adjusted; |
| 174 } | 186 } |
| 175 | 187 |
| 176 void SyncPromoHandler::RecordUserFlowAction(int action) { | 188 void SyncPromoHandler::RecordUserFlowAction(int action) { |
| 177 // Send an enumeration to our single user flow histogram. | 189 // Send an enumeration to our single user flow histogram. |
| 178 UMA_HISTOGRAM_ENUMERATION("SyncPromo.UserFlow", action, | 190 UMA_HISTOGRAM_ENUMERATION("SyncPromo.UserFlow", action, |
| 179 extension_misc::SYNC_PROMO_BUCKET_BOUNDARY); | 191 extension_misc::SYNC_PROMO_BUCKET_BOUNDARY); |
| 180 } | 192 } |
| OLD | NEW |