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

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

Issue 8992034: Merge 114608, 115692 to 963 (M17) branch. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/963/src/
Patch Set: rebasing, checking for diffs before merge Created 8 years, 12 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) 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
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 bool is_start_up = GetIsLaunchPageForSyncPromoURL(contents->GetURL());
128 sync_promo_trial::RecordUserShownPromoWithTrialBrand(is_start_up, profile);
129 }
124 } 130 }
125 131
126 // static 132 // static
133 bool SyncPromoUI::HasShownPromoAtStartup(Profile* profile) {
134 return profile->GetPrefs()->HasPrefPath(prefs::kSyncPromoStartupCount);
135 }
136
137 // static
127 bool SyncPromoUI::ShouldShowSyncPromo(Profile* profile) { 138 bool SyncPromoUI::ShouldShowSyncPromo(Profile* profile) {
128 #if defined(OS_CHROMEOS) 139 #if defined(OS_CHROMEOS)
129 // There's no need to show the sync promo on cros since cros users are logged 140 // There's no need to show the sync promo on cros since cros users are logged
130 // into sync already. 141 // into sync already.
131 return false; 142 return false;
132 #endif 143 #endif
133 144
134 // Honor the sync policies. 145 // Honor the sync policies.
135 if (!profile->GetOriginalProfile()->IsSyncAccessible()) 146 if (!profile->GetOriginalProfile()->IsSyncAccessible())
136 return false; 147 return false;
(...skipping 13 matching lines...) Expand all
150 prefs->RegisterIntegerPref( 161 prefs->RegisterIntegerPref(
151 prefs::kSyncPromoStartupCount, 0, PrefService::UNSYNCABLE_PREF); 162 prefs::kSyncPromoStartupCount, 0, PrefService::UNSYNCABLE_PREF);
152 prefs->RegisterBooleanPref( 163 prefs->RegisterBooleanPref(
153 prefs::kSyncPromoUserSkipped, false, PrefService::UNSYNCABLE_PREF); 164 prefs::kSyncPromoUserSkipped, false, PrefService::UNSYNCABLE_PREF);
154 prefs->RegisterBooleanPref(prefs::kSyncPromoShowOnFirstRunAllowed, true, 165 prefs->RegisterBooleanPref(prefs::kSyncPromoShowOnFirstRunAllowed, true,
155 PrefService::UNSYNCABLE_PREF); 166 PrefService::UNSYNCABLE_PREF);
156 167
157 SyncPromoHandler::RegisterUserPrefs(prefs); 168 SyncPromoHandler::RegisterUserPrefs(prefs);
158 } 169 }
159 170
171 // static
160 bool SyncPromoUI::ShouldShowSyncPromoAtStartup(Profile* profile, 172 bool SyncPromoUI::ShouldShowSyncPromoAtStartup(Profile* profile,
161 bool is_new_profile) { 173 bool is_new_profile) {
174 DCHECK(profile);
162 if (!ShouldShowSyncPromo(profile)) 175 if (!ShouldShowSyncPromo(profile))
163 return false; 176 return false;
164 177
165 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 178 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
166 if (command_line.HasSwitch(switches::kNoFirstRun)) 179 if (command_line.HasSwitch(switches::kNoFirstRun))
167 is_new_profile = false; 180 is_new_profile = false;
168 181
169 PrefService *prefs = profile->GetPrefs();
170 if (!is_new_profile) { 182 if (!is_new_profile) {
171 if (!prefs->HasPrefPath(prefs::kSyncPromoStartupCount)) 183 if (!HasShownPromoAtStartup(profile))
172 return false; 184 return false;
173 } 185 }
174 186
175 if (HasUserSkippedSyncPromo(profile)) 187 if (HasUserSkippedSyncPromo(profile))
176 return false; 188 return false;
177 189
178 // For Chinese users skip the sync promo. 190 // For Chinese users skip the sync promo.
179 if (g_browser_process->GetApplicationLocale() == "zh-CN") 191 if (g_browser_process->GetApplicationLocale() == "zh-CN")
180 return false; 192 return false;
181 193
194 PrefService* prefs = profile->GetPrefs();
182 int show_count = prefs->GetInteger(prefs::kSyncPromoStartupCount); 195 int show_count = prefs->GetInteger(prefs::kSyncPromoStartupCount);
183 if (show_count >= kSyncPromoShowAtStartupMaximum) 196 if (show_count >= kSyncPromoShowAtStartupMaximum)
184 return false; 197 return false;
185 198
199 // If the current install has a brand code that's part of an experiment, honor
200 // that before master prefs.
201 if (sync_promo_trial::IsPartOfBrandTrialToEnable())
202 return sync_promo_trial::ShouldShowAtStartupBasedOnBrand();
203
186 // This pref can be set in the master preferences file to allow or disallow 204 // This pref can be set in the master preferences file to allow or disallow
187 // showing the sync promo at startup. 205 // showing the sync promo at startup.
188 if (prefs->HasPrefPath(prefs::kSyncPromoShowOnFirstRunAllowed)) 206 if (prefs->HasPrefPath(prefs::kSyncPromoShowOnFirstRunAllowed))
189 return prefs->GetBoolean(prefs::kSyncPromoShowOnFirstRunAllowed); 207 return prefs->GetBoolean(prefs::kSyncPromoShowOnFirstRunAllowed);
190 208
191 // For now don't show the promo for some brands. 209 // For now don't show the promo for some brands.
192 if (!AllowPromoAtStartupForCurrentBrand()) 210 if (!AllowPromoAtStartupForCurrentBrand())
193 return false; 211 return false;
194 212
195 // Default to show the promo. 213 // Default to show the promo.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 UTF16ToUTF8(output.data(), output.length(), &url); 267 UTF16ToUTF8(output.data(), output.length(), &url);
250 return GURL(url); 268 return GURL(url);
251 } 269 }
252 return GURL(); 270 return GURL();
253 } 271 }
254 272
255 // static 273 // static
256 bool SyncPromoUI::UserHasSeenSyncPromoAtStartup(Profile* profile) { 274 bool SyncPromoUI::UserHasSeenSyncPromoAtStartup(Profile* profile) {
257 return profile->GetPrefs()->GetInteger(prefs::kSyncPromoStartupCount) > 0; 275 return profile->GetPrefs()->GetInteger(prefs::kSyncPromoStartupCount) > 0;
258 } 276 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/sync_promo/sync_promo_ui.h ('k') | chrome/browser/ui/webui/sync_promo_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698