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_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/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
(...skipping 25 matching lines...) Expand all Loading... | |
36 | 36 |
37 using content::WebContents; | 37 using content::WebContents; |
38 | 38 |
39 namespace { | 39 namespace { |
40 | 40 |
41 const char kStringsJsFile[] = "strings.js"; | 41 const char kStringsJsFile[] = "strings.js"; |
42 const char kSyncPromoJsFile[] = "sync_promo.js"; | 42 const char kSyncPromoJsFile[] = "sync_promo.js"; |
43 | 43 |
44 const char kSyncPromoQueryKeyNextPage[] = "next_page"; | 44 const char kSyncPromoQueryKeyNextPage[] = "next_page"; |
45 const char kSyncPromoQueryKeySource[] = "source"; | 45 const char kSyncPromoQueryKeySource[] = "source"; |
46 const char kSyncPromoQueryKeyAutoClose[] = "auto_close"; | |
46 | 47 |
47 // The maximum number of times we want to show the sync promo at startup. | 48 // The maximum number of times we want to show the sync promo at startup. |
48 const int kSyncPromoShowAtStartupMaximum = 10; | 49 const int kSyncPromoShowAtStartupMaximum = 10; |
49 | 50 |
50 // Checks we want to show the sync promo for the given brand. | 51 // Checks we want to show the sync promo for the given brand. |
51 bool AllowPromoAtStartupForCurrentBrand() { | 52 bool AllowPromoAtStartupForCurrentBrand() { |
52 std::string brand; | 53 std::string brand; |
53 google_util::GetBrand(&brand); | 54 google_util::GetBrand(&brand); |
54 | 55 |
55 if (brand.empty()) | 56 if (brand.empty()) |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 | 199 |
199 bool SyncPromoUI::HasUserSkippedSyncPromo(Profile* profile) { | 200 bool SyncPromoUI::HasUserSkippedSyncPromo(Profile* profile) { |
200 return profile->GetPrefs()->GetBoolean(prefs::kSyncPromoUserSkipped); | 201 return profile->GetPrefs()->GetBoolean(prefs::kSyncPromoUserSkipped); |
201 } | 202 } |
202 | 203 |
203 void SyncPromoUI::SetUserSkippedSyncPromo(Profile* profile) { | 204 void SyncPromoUI::SetUserSkippedSyncPromo(Profile* profile) { |
204 profile->GetPrefs()->SetBoolean(prefs::kSyncPromoUserSkipped, true); | 205 profile->GetPrefs()->SetBoolean(prefs::kSyncPromoUserSkipped, true); |
205 } | 206 } |
206 | 207 |
207 // static | 208 // static |
208 GURL SyncPromoUI::GetSyncPromoURL(const GURL& next_page, Source source) { | 209 GURL SyncPromoUI::GetSyncPromoURL( |
210 const GURL& next_page, Source source, bool auto_close) { | |
sky
2012/07/23 18:31:20
nit: when you wrap, each param on its own line.
Munjal (Google)
2012/07/23 18:35:18
Done.
| |
209 DCHECK_NE(SOURCE_UNKNOWN, source); | 211 DCHECK_NE(SOURCE_UNKNOWN, source); |
210 | 212 |
211 std::stringstream stream; | 213 std::stringstream stream; |
212 stream << chrome::kChromeUISyncPromoURL << "?" | 214 stream << chrome::kChromeUISyncPromoURL << "?" |
213 << kSyncPromoQueryKeySource << "=" << static_cast<int>(source); | 215 << kSyncPromoQueryKeySource << "=" << static_cast<int>(source); |
214 | 216 |
217 if (auto_close) | |
218 stream << "&" << kSyncPromoQueryKeyAutoClose << "=1"; | |
219 | |
215 if (!next_page.spec().empty()) { | 220 if (!next_page.spec().empty()) { |
216 url_canon::RawCanonOutputT<char> output; | 221 url_canon::RawCanonOutputT<char> output; |
217 url_util::EncodeURIComponent( | 222 url_util::EncodeURIComponent( |
218 next_page.spec().c_str(), next_page.spec().length(), &output); | 223 next_page.spec().c_str(), next_page.spec().length(), &output); |
219 std::string escaped_spec(output.data(), output.length()); | 224 std::string escaped_spec(output.data(), output.length()); |
220 stream << "&" << kSyncPromoQueryKeyNextPage << "=" << escaped_spec; | 225 stream << "&" << kSyncPromoQueryKeyNextPage << "=" << escaped_spec; |
221 } | 226 } |
222 | 227 |
223 return GURL(stream.str()); | 228 return GURL(stream.str()); |
224 } | 229 } |
(...skipping 14 matching lines...) Expand all Loading... | |
239 if (chrome_common_net::GetValueForKeyInQuery( | 244 if (chrome_common_net::GetValueForKeyInQuery( |
240 url, kSyncPromoQueryKeySource, &value)) { | 245 url, kSyncPromoQueryKeySource, &value)) { |
241 int source = 0; | 246 int source = 0; |
242 if (base::StringToInt(value, &source) && source >= SOURCE_START_PAGE && | 247 if (base::StringToInt(value, &source) && source >= SOURCE_START_PAGE && |
243 source < SOURCE_UNKNOWN) { | 248 source < SOURCE_UNKNOWN) { |
244 return static_cast<Source>(source); | 249 return static_cast<Source>(source); |
245 } | 250 } |
246 } | 251 } |
247 return SOURCE_UNKNOWN; | 252 return SOURCE_UNKNOWN; |
248 } | 253 } |
254 | |
255 // static | |
256 bool SyncPromoUI::GetAutoCloseForSyncPromoURL(const GURL& url) { | |
257 std::string value; | |
258 if (chrome_common_net::GetValueForKeyInQuery( | |
259 url, kSyncPromoQueryKeyAutoClose, &value)) { | |
260 int source = 0; | |
261 base::StringToInt(value, &source); | |
262 return (source == 1); | |
263 } | |
264 return false; | |
265 } | |
OLD | NEW |