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

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

Issue 8689006: Create a field test for sync sign in promo strings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: small typo spotted by tmccoy Created 9 years 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
« no previous file with comments | « chrome/browser/ui/webui/sync_promo_ui.h ('k') | chrome/browser/ui/webui/sync_setup_handler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_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"
(...skipping 14 matching lines...) Expand all
25 #include "grit/browser_resources.h" 25 #include "grit/browser_resources.h"
26 #include "grit/generated_resources.h" 26 #include "grit/generated_resources.h"
27 #include "grit/theme_resources.h" 27 #include "grit/theme_resources.h"
28 #include "ui/base/l10n/l10n_util.h" 28 #include "ui/base/l10n/l10n_util.h"
29 29
30 namespace { 30 namespace {
31 31
32 const char kStringsJsFile[] = "strings.js"; 32 const char kStringsJsFile[] = "strings.js";
33 const char kSyncPromoJsFile[] = "sync_promo.js"; 33 const char kSyncPromoJsFile[] = "sync_promo.js";
34 34
35 const char kSyncPromoQueryKeyShowTitle[] = "show_title"; 35 const char kSyncPromoQueryKeyIsLaunchPage[] = "is_launch_page";
36 const char kSyncPromoQueryKeyNextPage[] = "next_page"; 36 const char kSyncPromoQueryKeyNextPage[] = "next_page";
37 37
38 // The maximum number of times we want to show the sync promo at startup. 38 // The maximum number of times we want to show the sync promo at startup.
39 const int kSyncPromoShowAtStartupMaximum = 10; 39 const int kSyncPromoShowAtStartupMaximum = 10;
40 40
41 // Checks we want to show the sync promo for the given brand. 41 // Checks we want to show the sync promo for the given brand.
42 bool AllowPromoAtStartupForCurrentBrand() { 42 bool AllowPromoAtStartupForCurrentBrand() {
43 std::string brand; 43 std::string brand;
44 google_util::GetBrand(&brand); 44 google_util::GetBrand(&brand);
45 45
46 if (brand.empty()) 46 if (brand.empty())
47 return true; 47 return true;
48 48
49 if (google_util::IsInternetCafeBrandCode(brand)) 49 if (google_util::IsInternetCafeBrandCode(brand))
50 return false; 50 return false;
51 51
52 if (google_util::IsOrganic(brand)) 52 if (google_util::IsOrganic(brand))
53 return true; 53 return true;
54 54
55 if (StartsWithASCII(brand, "CH", true)) 55 if (StartsWithASCII(brand, "CH", true))
56 return true; 56 return true;
57 57
58 // Default to disallow for all other brand codes. 58 // Default to disallow for all other brand codes.
59 return false; 59 return false;
60 } 60 }
61 61
62 // The Web UI data source for the sync promo page. 62 // The Web UI data source for the sync promo page.
63 class SyncPromoUIHTMLSource : public ChromeWebUIDataSource { 63 class SyncPromoUIHTMLSource : public ChromeWebUIDataSource {
64 public: 64 public:
65 SyncPromoUIHTMLSource(); 65 explicit SyncPromoUIHTMLSource(WebUI* web_ui);
66 66
67 private: 67 private:
68 ~SyncPromoUIHTMLSource() {} 68 ~SyncPromoUIHTMLSource() {}
69 DISALLOW_COPY_AND_ASSIGN(SyncPromoUIHTMLSource); 69 DISALLOW_COPY_AND_ASSIGN(SyncPromoUIHTMLSource);
70 }; 70 };
71 71
72 SyncPromoUIHTMLSource::SyncPromoUIHTMLSource() 72 SyncPromoUIHTMLSource::SyncPromoUIHTMLSource(WebUI* web_ui)
73 : ChromeWebUIDataSource(chrome::kChromeUISyncPromoHost) { 73 : ChromeWebUIDataSource(chrome::kChromeUISyncPromoHost) {
74 DictionaryValue localized_strings; 74 DictionaryValue localized_strings;
75 CoreOptionsHandler::GetStaticLocalizedValues(&localized_strings); 75 CoreOptionsHandler::GetStaticLocalizedValues(&localized_strings);
76 SyncSetupHandler::GetStaticLocalizedValues(&localized_strings); 76 SyncSetupHandler::GetStaticLocalizedValues(&localized_strings, web_ui);
77 AddLocalizedStrings(localized_strings); 77 AddLocalizedStrings(localized_strings);
78 } 78 }
79 79
80 // Looks for |search_key| in the query portion of |url|. Returns true if the 80 // Looks for |search_key| in the query portion of |url|. Returns true if the
81 // key is found and sets |out_value| to the value for the key. Returns false if 81 // key is found and sets |out_value| to the value for the key. Returns false if
82 // the key is not found. 82 // the key is not found.
83 bool GetValueForKeyInQuery(const GURL& url, const std::string& search_key, 83 bool GetValueForKeyInQuery(const GURL& url, const std::string& search_key,
84 std::string* out_value) { 84 std::string* out_value) {
85 url_parse::Component query = url.parsed_for_possibly_invalid_spec().query; 85 url_parse::Component query = url.parsed_for_possibly_invalid_spec().query;
86 url_parse::Component key, value; 86 url_parse::Component key, value;
(...skipping 22 matching lines...) Expand all
109 g_browser_process->profile_manager()); 109 g_browser_process->profile_manager());
110 AddMessageHandler(handler); 110 AddMessageHandler(handler);
111 handler->Attach(this); 111 handler->Attach(this);
112 112
113 // Set up the chrome://theme/ source. 113 // Set up the chrome://theme/ source.
114 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); 114 Profile* profile = Profile::FromBrowserContext(contents->browser_context());
115 ThemeSource* theme = new ThemeSource(profile); 115 ThemeSource* theme = new ThemeSource(profile);
116 profile->GetChromeURLDataManager()->AddDataSource(theme); 116 profile->GetChromeURLDataManager()->AddDataSource(theme);
117 117
118 // Set up the sync promo source. 118 // Set up the sync promo source.
119 SyncPromoUIHTMLSource* html_source = new SyncPromoUIHTMLSource(); 119 SyncPromoUIHTMLSource* html_source = new SyncPromoUIHTMLSource(this);
120 html_source->set_json_path(kStringsJsFile); 120 html_source->set_json_path(kStringsJsFile);
121 html_source->add_resource_path(kSyncPromoJsFile, IDR_SYNC_PROMO_JS); 121 html_source->add_resource_path(kSyncPromoJsFile, IDR_SYNC_PROMO_JS);
122 html_source->set_default_resource(IDR_SYNC_PROMO_HTML); 122 html_source->set_default_resource(IDR_SYNC_PROMO_HTML);
123 profile->GetChromeURLDataManager()->AddDataSource(html_source); 123 profile->GetChromeURLDataManager()->AddDataSource(html_source);
124 } 124 }
125 125
126 // static 126 // static
127 bool SyncPromoUI::ShouldShowSyncPromo(Profile* profile) { 127 bool SyncPromoUI::ShouldShowSyncPromo(Profile* profile) {
128 #if defined(OS_CHROMEOS) 128 #if defined(OS_CHROMEOS)
129 // There's no need to show the sync promo on cros since cros users are logged 129 // There's no need to show the sync promo on cros since cros users are logged
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 return profile->GetPrefs()->GetBoolean(prefs::kSyncPromoUserSkipped); 207 return profile->GetPrefs()->GetBoolean(prefs::kSyncPromoUserSkipped);
208 } 208 }
209 209
210 void SyncPromoUI::SetUserSkippedSyncPromo(Profile* profile) { 210 void SyncPromoUI::SetUserSkippedSyncPromo(Profile* profile) {
211 profile->GetPrefs()->SetBoolean(prefs::kSyncPromoUserSkipped, true); 211 profile->GetPrefs()->SetBoolean(prefs::kSyncPromoUserSkipped, true);
212 } 212 }
213 213
214 // static 214 // static
215 GURL SyncPromoUI::GetSyncPromoURL(const GURL& next_page, bool show_title) { 215 GURL SyncPromoUI::GetSyncPromoURL(const GURL& next_page, bool show_title) {
216 std::stringstream stream; 216 std::stringstream stream;
217 stream << chrome::kChromeUISyncPromoURL << "?" << kSyncPromoQueryKeyShowTitle 217 stream << chrome::kChromeUISyncPromoURL << "?"
218 << "=" << (show_title ? "true" : "false"); 218 << kSyncPromoQueryKeyIsLaunchPage << "="
219 << (show_title ? "true" : "false");
219 220
220 if (!next_page.spec().empty()) { 221 if (!next_page.spec().empty()) {
221 url_canon::RawCanonOutputT<char> output; 222 url_canon::RawCanonOutputT<char> output;
222 url_util::EncodeURIComponent( 223 url_util::EncodeURIComponent(
223 next_page.spec().c_str(), next_page.spec().length(), &output); 224 next_page.spec().c_str(), next_page.spec().length(), &output);
224 std::string escaped_spec(output.data(), output.length()); 225 std::string escaped_spec(output.data(), output.length());
225 stream << "&" << kSyncPromoQueryKeyNextPage << "=" << escaped_spec; 226 stream << "&" << kSyncPromoQueryKeyNextPage << "=" << escaped_spec;
226 } 227 }
227 228
228 return GURL(stream.str()); 229 return GURL(stream.str());
229 } 230 }
230 231
231 // static 232 // static
232 bool SyncPromoUI::GetShowTitleForSyncPromoURL(const GURL& url) { 233 bool SyncPromoUI::GetIsLaunchPageForSyncPromoURL(const GURL& url) {
233 std::string value; 234 std::string value;
234 if (GetValueForKeyInQuery(url, kSyncPromoQueryKeyShowTitle, &value)) 235 // Show the title if the promo is currently the Chrome launch page (and not
236 // the page accessed through the NTP).
237 if (GetValueForKeyInQuery(url, kSyncPromoQueryKeyIsLaunchPage, &value))
235 return value == "true"; 238 return value == "true";
236 return false; 239 return false;
237 } 240 }
238 241
239 // static 242 // static
240 GURL SyncPromoUI::GetNextPageURLForSyncPromoURL(const GURL& url) { 243 GURL SyncPromoUI::GetNextPageURLForSyncPromoURL(const GURL& url) {
241 std::string value; 244 std::string value;
242 if (GetValueForKeyInQuery(url, kSyncPromoQueryKeyNextPage, &value)) { 245 if (GetValueForKeyInQuery(url, kSyncPromoQueryKeyNextPage, &value)) {
243 url_canon::RawCanonOutputT<char16> output; 246 url_canon::RawCanonOutputT<char16> output;
244 url_util::DecodeURLEscapeSequences(value.c_str(), value.length(), &output); 247 url_util::DecodeURLEscapeSequences(value.c_str(), value.length(), &output);
245 std::string url; 248 std::string url;
246 UTF16ToUTF8(output.data(), output.length(), &url); 249 UTF16ToUTF8(output.data(), output.length(), &url);
247 return GURL(url); 250 return GURL(url);
248 } 251 }
249 return GURL(); 252 return GURL();
250 } 253 }
251 254
252 // static 255 // static
253 bool SyncPromoUI::UserHasSeenSyncPromoAtStartup(Profile* profile) { 256 bool SyncPromoUI::UserHasSeenSyncPromoAtStartup(Profile* profile) {
254 return profile->GetPrefs()->GetInteger(prefs::kSyncPromoStartupCount) > 0; 257 return profile->GetPrefs()->GetInteger(prefs::kSyncPromoStartupCount) > 0;
255 } 258 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/sync_promo_ui.h ('k') | chrome/browser/ui/webui/sync_setup_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698