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