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(const GURL& next_page, |
| 210 Source source, |
| 211 bool auto_close) { |
209 DCHECK_NE(SOURCE_UNKNOWN, source); | 212 DCHECK_NE(SOURCE_UNKNOWN, source); |
210 | 213 |
211 std::stringstream stream; | 214 std::stringstream stream; |
212 stream << chrome::kChromeUISyncPromoURL << "?" | 215 stream << chrome::kChromeUISyncPromoURL << "?" |
213 << kSyncPromoQueryKeySource << "=" << static_cast<int>(source); | 216 << kSyncPromoQueryKeySource << "=" << static_cast<int>(source); |
214 | 217 |
| 218 if (auto_close) |
| 219 stream << "&" << kSyncPromoQueryKeyAutoClose << "=1"; |
| 220 |
215 if (!next_page.spec().empty()) { | 221 if (!next_page.spec().empty()) { |
216 url_canon::RawCanonOutputT<char> output; | 222 url_canon::RawCanonOutputT<char> output; |
217 url_util::EncodeURIComponent( | 223 url_util::EncodeURIComponent( |
218 next_page.spec().c_str(), next_page.spec().length(), &output); | 224 next_page.spec().c_str(), next_page.spec().length(), &output); |
219 std::string escaped_spec(output.data(), output.length()); | 225 std::string escaped_spec(output.data(), output.length()); |
220 stream << "&" << kSyncPromoQueryKeyNextPage << "=" << escaped_spec; | 226 stream << "&" << kSyncPromoQueryKeyNextPage << "=" << escaped_spec; |
221 } | 227 } |
222 | 228 |
223 return GURL(stream.str()); | 229 return GURL(stream.str()); |
224 } | 230 } |
(...skipping 14 matching lines...) Expand all Loading... |
239 if (chrome_common_net::GetValueForKeyInQuery( | 245 if (chrome_common_net::GetValueForKeyInQuery( |
240 url, kSyncPromoQueryKeySource, &value)) { | 246 url, kSyncPromoQueryKeySource, &value)) { |
241 int source = 0; | 247 int source = 0; |
242 if (base::StringToInt(value, &source) && source >= SOURCE_START_PAGE && | 248 if (base::StringToInt(value, &source) && source >= SOURCE_START_PAGE && |
243 source < SOURCE_UNKNOWN) { | 249 source < SOURCE_UNKNOWN) { |
244 return static_cast<Source>(source); | 250 return static_cast<Source>(source); |
245 } | 251 } |
246 } | 252 } |
247 return SOURCE_UNKNOWN; | 253 return SOURCE_UNKNOWN; |
248 } | 254 } |
| 255 |
| 256 // static |
| 257 bool SyncPromoUI::GetAutoCloseForSyncPromoURL(const GURL& url) { |
| 258 std::string value; |
| 259 if (chrome_common_net::GetValueForKeyInQuery( |
| 260 url, kSyncPromoQueryKeyAutoClose, &value)) { |
| 261 int source = 0; |
| 262 base::StringToInt(value, &source); |
| 263 return (source == 1); |
| 264 } |
| 265 return false; |
| 266 } |
OLD | NEW |