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_ui.h" | 5 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/first_run/first_run.h" | 10 #include "chrome/browser/first_run/first_run.h" |
11 #include "chrome/browser/google/google_util.h" | 11 #include "chrome/browser/google/google_util.h" |
12 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/sync/profile_sync_service.h" | 14 #include "chrome/browser/sync/profile_sync_service.h" |
15 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 15 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
16 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 16 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
17 #include "chrome/browser/ui/webui/options/core_options_handler.h" | 17 #include "chrome/browser/ui/webui/options/core_options_handler.h" |
18 #include "chrome/browser/ui/webui/sync_promo_handler.h" | 18 #include "chrome/browser/ui/webui/sync_promo/sync_promo_handler.h" |
| 19 #include "chrome/browser/ui/webui/sync_promo/sync_promo_trial.h" |
19 #include "chrome/browser/ui/webui/theme_source.h" | 20 #include "chrome/browser/ui/webui/theme_source.h" |
20 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.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 "googleurl/src/url_util.h" | 25 #include "googleurl/src/url_util.h" |
25 #include "grit/browser_resources.h" | 26 #include "grit/browser_resources.h" |
26 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
27 #include "grit/theme_resources.h" | 28 #include "grit/theme_resources.h" |
28 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); | 115 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); |
115 ThemeSource* theme = new ThemeSource(profile); | 116 ThemeSource* theme = new ThemeSource(profile); |
116 profile->GetChromeURLDataManager()->AddDataSource(theme); | 117 profile->GetChromeURLDataManager()->AddDataSource(theme); |
117 | 118 |
118 // Set up the sync promo source. | 119 // Set up the sync promo source. |
119 SyncPromoUIHTMLSource* html_source = new SyncPromoUIHTMLSource(this); | 120 SyncPromoUIHTMLSource* html_source = new SyncPromoUIHTMLSource(this); |
120 html_source->set_json_path(kStringsJsFile); | 121 html_source->set_json_path(kStringsJsFile); |
121 html_source->add_resource_path(kSyncPromoJsFile, IDR_SYNC_PROMO_JS); | 122 html_source->add_resource_path(kSyncPromoJsFile, IDR_SYNC_PROMO_JS); |
122 html_source->set_default_resource(IDR_SYNC_PROMO_HTML); | 123 html_source->set_default_resource(IDR_SYNC_PROMO_HTML); |
123 profile->GetChromeURLDataManager()->AddDataSource(html_source); | 124 profile->GetChromeURLDataManager()->AddDataSource(html_source); |
| 125 |
| 126 if (sync_promo_trial::IsPartOfBrandTrialToEnable()) |
| 127 sync_promo_trial::RecordUserShownPromoWithTrialBrand(); |
124 } | 128 } |
125 | 129 |
126 // static | 130 // static |
127 bool SyncPromoUI::ShouldShowSyncPromo(Profile* profile) { | 131 bool SyncPromoUI::ShouldShowSyncPromo(Profile* profile) { |
128 #if defined(OS_CHROMEOS) | 132 #if defined(OS_CHROMEOS) |
129 // There's no need to show the sync promo on cros since cros users are logged | 133 // There's no need to show the sync promo on cros since cros users are logged |
130 // into sync already. | 134 // into sync already. |
131 return false; | 135 return false; |
132 #endif | 136 #endif |
133 | 137 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 return false; | 180 return false; |
177 | 181 |
178 // For Chinese users skip the sync promo. | 182 // For Chinese users skip the sync promo. |
179 if (g_browser_process->GetApplicationLocale() == "zh-CN") | 183 if (g_browser_process->GetApplicationLocale() == "zh-CN") |
180 return false; | 184 return false; |
181 | 185 |
182 int show_count = prefs->GetInteger(prefs::kSyncPromoStartupCount); | 186 int show_count = prefs->GetInteger(prefs::kSyncPromoStartupCount); |
183 if (show_count >= kSyncPromoShowAtStartupMaximum) | 187 if (show_count >= kSyncPromoShowAtStartupMaximum) |
184 return false; | 188 return false; |
185 | 189 |
| 190 // If the current install has a brand code that's part of an experiment, honor |
| 191 // that before master prefs. |
| 192 if (sync_promo_trial::IsPartOfBrandTrialToEnable()) |
| 193 return sync_promo_trial::ShouldShowAtStartupBasedOnBrand(); |
| 194 |
186 // This pref can be set in the master preferences file to allow or disallow | 195 // This pref can be set in the master preferences file to allow or disallow |
187 // showing the sync promo at startup. | 196 // showing the sync promo at startup. |
188 if (prefs->HasPrefPath(prefs::kSyncPromoShowOnFirstRunAllowed)) | 197 if (prefs->HasPrefPath(prefs::kSyncPromoShowOnFirstRunAllowed)) |
189 return prefs->GetBoolean(prefs::kSyncPromoShowOnFirstRunAllowed); | 198 return prefs->GetBoolean(prefs::kSyncPromoShowOnFirstRunAllowed); |
190 | 199 |
191 // For now don't show the promo for some brands. | 200 // For now don't show the promo for some brands. |
192 if (!AllowPromoAtStartupForCurrentBrand()) | 201 if (!AllowPromoAtStartupForCurrentBrand()) |
193 return false; | 202 return false; |
194 | 203 |
195 // Default to show the promo. | 204 // Default to show the promo. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 UTF16ToUTF8(output.data(), output.length(), &url); | 258 UTF16ToUTF8(output.data(), output.length(), &url); |
250 return GURL(url); | 259 return GURL(url); |
251 } | 260 } |
252 return GURL(); | 261 return GURL(); |
253 } | 262 } |
254 | 263 |
255 // static | 264 // static |
256 bool SyncPromoUI::UserHasSeenSyncPromoAtStartup(Profile* profile) { | 265 bool SyncPromoUI::UserHasSeenSyncPromoAtStartup(Profile* profile) { |
257 return profile->GetPrefs()->GetInteger(prefs::kSyncPromoStartupCount) > 0; | 266 return profile->GetPrefs()->GetInteger(prefs::kSyncPromoStartupCount) > 0; |
258 } | 267 } |
OLD | NEW |