OLD | NEW |
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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 // confirming that they're signed in. | 201 // confirming that they're signed in. |
202 std::string username = prefs_->GetString(prefs::kGoogleServicesUsername); | 202 std::string username = prefs_->GetString(prefs::kGoogleServicesUsername); |
203 if (!username.empty()) | 203 if (!username.empty()) |
204 prefs_->SetBoolean(prefs::kSyncPromoShowNTPBubble, true); | 204 prefs_->SetBoolean(prefs::kSyncPromoShowNTPBubble, true); |
205 | 205 |
206 // If the browser window is being closed then don't try to navigate to | 206 // If the browser window is being closed then don't try to navigate to |
207 // another URL. This prevents the browser window from flashing during | 207 // another URL. This prevents the browser window from flashing during |
208 // close. | 208 // close. |
209 Browser* browser = | 209 Browser* browser = |
210 BrowserList::FindBrowserWithWebContents(web_ui()->GetWebContents()); | 210 BrowserList::FindBrowserWithWebContents(web_ui()->GetWebContents()); |
211 if (browser && !browser->IsAttemptingToCloseBrowser()) { | 211 if (!browser || !browser->IsAttemptingToCloseBrowser()) { |
212 GURL url = SyncPromoUI::GetNextPageURLForSyncPromoURL( | 212 GURL url = SyncPromoUI::GetNextPageURLForSyncPromoURL( |
213 web_ui()->GetWebContents()->GetURL()); | 213 web_ui()->GetWebContents()->GetURL()); |
214 OpenURLParams params( | 214 OpenURLParams params( |
215 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, false); | 215 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, false); |
216 web_ui()->GetWebContents()->OpenURL(params); | 216 web_ui()->GetWebContents()->OpenURL(params); |
217 } | 217 } |
218 } | 218 } |
219 | 219 |
| 220 int SyncPromoHandler::GetPromoVersion() { |
| 221 switch (SyncPromoUI::GetSyncPromoVersion()) { |
| 222 case SyncPromoUI::VERSION_DEFAULT: |
| 223 return 0; |
| 224 case SyncPromoUI::VERSION_DEVICES: |
| 225 return 1; |
| 226 case SyncPromoUI::VERSION_VERBOSE: |
| 227 return 2; |
| 228 case SyncPromoUI::VERSION_SIMPLE: |
| 229 return 3; |
| 230 case SyncPromoUI::VERSION_DIALOG: |
| 231 // Use the simple sync promo layout for the dialog version. |
| 232 return 3; |
| 233 default: |
| 234 NOTREACHED(); |
| 235 return 0; |
| 236 } |
| 237 } |
| 238 |
220 void SyncPromoHandler::HandleInitializeSyncPromo(const base::ListValue* args) { | 239 void SyncPromoHandler::HandleInitializeSyncPromo(const base::ListValue* args) { |
221 base::FundamentalValue version(SyncPromoUI::GetSyncPromoVersion()); | 240 base::FundamentalValue version(GetPromoVersion()); |
222 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showPromoVersion", | 241 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showPromoVersion", |
223 version); | 242 version); |
224 | 243 |
225 OpenSyncSetup(); | 244 OpenSyncSetup(); |
226 // We don't need to compute anything for this, just do this every time. | 245 // We don't need to compute anything for this, just do this every time. |
227 RecordUserFlowAction(SYNC_PROMO_VIEWED); | 246 RecordUserFlowAction(SYNC_PROMO_VIEWED); |
228 // Increment view count first and show natural numbers in stats rather than 0 | 247 // Increment view count first and show natural numbers in stats rather than 0 |
229 // based starting point (if it happened to be our first time showing this). | 248 // based starting point (if it happened to be our first time showing this). |
230 IncrementViewCountBy(1); | 249 IncrementViewCountBy(1); |
231 // Record +1 for every view. This is the only thing we record that's not part | 250 // Record +1 for every view. This is the only thing we record that's not part |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 // The following call does not use the standard UMA macro because the | 315 // The following call does not use the standard UMA macro because the |
297 // histogram name is only known at runtime. The standard macros declare | 316 // histogram name is only known at runtime. The standard macros declare |
298 // static variables that won't work if the name changes on differnt calls. | 317 // static variables that won't work if the name changes on differnt calls. |
299 if (!histogram_name_.empty()) { | 318 if (!histogram_name_.empty()) { |
300 base::Histogram* histogram = base::LinearHistogram::FactoryGet( | 319 base::Histogram* histogram = base::LinearHistogram::FactoryGet( |
301 histogram_name_, 1, SYNC_PROMO_BUCKET_BOUNDARY, | 320 histogram_name_, 1, SYNC_PROMO_BUCKET_BOUNDARY, |
302 SYNC_PROMO_BUCKET_BOUNDARY + 1, base::Histogram::kNoFlags); | 321 SYNC_PROMO_BUCKET_BOUNDARY + 1, base::Histogram::kNoFlags); |
303 histogram->Add(action); | 322 histogram->Add(action); |
304 } | 323 } |
305 } | 324 } |
OLD | NEW |