| OLD | NEW |
| 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 18 matching lines...) Expand all Loading... |
| 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 kSyncPromoQueryKeyShowTitle[] = "show_title"; |
| 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 kSyncPromoShowAtStartupMaxiumum = 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::IsOrganic(brand)) | 49 if (google_util::IsOrganic(brand)) |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 profile->GetChromeURLDataManager()->AddDataSource(theme); | 113 profile->GetChromeURLDataManager()->AddDataSource(theme); |
| 114 | 114 |
| 115 // Set up the sync promo source. | 115 // Set up the sync promo source. |
| 116 SyncPromoUIHTMLSource* html_source = new SyncPromoUIHTMLSource(); | 116 SyncPromoUIHTMLSource* html_source = new SyncPromoUIHTMLSource(); |
| 117 html_source->set_json_path(kStringsJsFile); | 117 html_source->set_json_path(kStringsJsFile); |
| 118 html_source->add_resource_path(kSyncPromoJsFile, IDR_SYNC_PROMO_JS); | 118 html_source->add_resource_path(kSyncPromoJsFile, IDR_SYNC_PROMO_JS); |
| 119 html_source->set_default_resource(IDR_SYNC_PROMO_HTML); | 119 html_source->set_default_resource(IDR_SYNC_PROMO_HTML); |
| 120 profile->GetChromeURLDataManager()->AddDataSource(html_source); | 120 profile->GetChromeURLDataManager()->AddDataSource(html_source); |
| 121 } | 121 } |
| 122 | 122 |
| 123 // static |
| 123 bool SyncPromoUI::ShouldShowSyncPromo(Profile* profile) { | 124 bool SyncPromoUI::ShouldShowSyncPromo(Profile* profile) { |
| 124 #if defined(OS_CHROMEOS) | 125 #if defined(OS_CHROMEOS) |
| 125 // There's no need to show the sync promo on cros since cros users are logged | 126 // There's no need to show the sync promo on cros since cros users are logged |
| 126 // into sync already. | 127 // into sync already. |
| 127 return false; | 128 return false; |
| 128 #endif | 129 #endif |
| 129 | 130 |
| 130 // Honor the sync policies. | 131 // Honor the sync policies. |
| 131 if (!profile->GetOriginalProfile()->IsSyncAccessible()) | 132 if (!profile->GetOriginalProfile()->IsSyncAccessible()) |
| 132 return false; | 133 return false; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 } | 170 } |
| 170 | 171 |
| 171 if (HasUserSkippedSyncPromo(profile)) | 172 if (HasUserSkippedSyncPromo(profile)) |
| 172 return false; | 173 return false; |
| 173 | 174 |
| 174 // For Chinese users skip the sync promo. | 175 // For Chinese users skip the sync promo. |
| 175 if (g_browser_process->GetApplicationLocale() == "zh-CN") | 176 if (g_browser_process->GetApplicationLocale() == "zh-CN") |
| 176 return false; | 177 return false; |
| 177 | 178 |
| 178 int show_count = prefs->GetInteger(prefs::kSyncPromoStartupCount); | 179 int show_count = prefs->GetInteger(prefs::kSyncPromoStartupCount); |
| 179 if (show_count >= kSyncPromoShowAtStartupMaxiumum) | 180 if (show_count >= kSyncPromoShowAtStartupMaximum) |
| 180 return false; | 181 return false; |
| 181 | 182 |
| 182 // This pref can be set in the master preferences file to allow or disallow | 183 // This pref can be set in the master preferences file to allow or disallow |
| 183 // showing the sync promo at startup. | 184 // showing the sync promo at startup. |
| 184 if (prefs->HasPrefPath(prefs::kSyncPromoShowOnFirstRunAllowed)) | 185 if (prefs->HasPrefPath(prefs::kSyncPromoShowOnFirstRunAllowed)) |
| 185 return prefs->GetBoolean(prefs::kSyncPromoShowOnFirstRunAllowed); | 186 return prefs->GetBoolean(prefs::kSyncPromoShowOnFirstRunAllowed); |
| 186 | 187 |
| 187 // For now don't show the promo for some brands. | 188 // For now don't show the promo for some brands. |
| 188 if (!AllowPromoAtStartupForCurrentBrand()) | 189 if (!AllowPromoAtStartupForCurrentBrand()) |
| 189 return false; | 190 return false; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 UTF16ToUTF8(output.data(), output.length(), &url); | 243 UTF16ToUTF8(output.data(), output.length(), &url); |
| 243 return GURL(url); | 244 return GURL(url); |
| 244 } | 245 } |
| 245 return GURL(); | 246 return GURL(); |
| 246 } | 247 } |
| 247 | 248 |
| 248 // static | 249 // static |
| 249 bool SyncPromoUI::UserHasSeenSyncPromoAtStartup(Profile* profile) { | 250 bool SyncPromoUI::UserHasSeenSyncPromoAtStartup(Profile* profile) { |
| 250 return profile->GetPrefs()->GetInteger(prefs::kSyncPromoStartupCount) > 0; | 251 return profile->GetPrefs()->GetInteger(prefs::kSyncPromoStartupCount) > 0; |
| 251 } | 252 } |
| OLD | NEW |