diff options
author | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-10 02:04:38 +0000 |
---|---|---|
committer | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-10 02:04:38 +0000 |
commit | 4f2b1c4ccdc76ccf4d3f537cbd662f84c122751f (patch) | |
tree | 973461f71c7df75553eddc53b447d52fe0df4323 | |
parent | be623b0f2ec23b3032fc6c8b61d6062accf51bb7 (diff) | |
download | chromium_src-4f2b1c4ccdc76ccf4d3f537cbd662f84c122751f.zip chromium_src-4f2b1c4ccdc76ccf4d3f537cbd662f84c122751f.tar.gz chromium_src-4f2b1c4ccdc76ccf4d3f537cbd662f84c122751f.tar.bz2 |
Ensure that tips change when the Chrome language changes.
BUG= http://crbug.com/21394
TEST= Change chrome language. Close and reopen browser. Tips should appear in new language, or, if not available, they should not appear.
Review URL: http://codereview.chromium.org/199073
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25834 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/dom_ui/tips_handler.cc | 15 | ||||
-rw-r--r-- | chrome/browser/web_resource/web_resource_service.cc | 33 |
2 files changed, 35 insertions, 13 deletions
diff --git a/chrome/browser/dom_ui/tips_handler.cc b/chrome/browser/dom_ui/tips_handler.cc index 4690c27..be9ffba 100644 --- a/chrome/browser/dom_ui/tips_handler.cc +++ b/chrome/browser/dom_ui/tips_handler.cc @@ -4,6 +4,7 @@ #include "base/string_util.h" #include "base/values.h" +#include "chrome/browser/browser_process.h" #include "chrome/browser/dom_ui/tips_handler.h" #include "chrome/browser/profile.h" #include "chrome/browser/web_resource/web_resource_service.h" @@ -35,6 +36,20 @@ void TipsHandler::HandleGetTips(const Value* content) { int current_tip_index; std::string current_tip; + // If tips are not correct for our locale, do not send. Wait for update. + // We need to check here because the new tab page calls for tips before + // the tip service starts up. + PrefService* current_prefs = dom_ui_->GetProfile()->GetPrefs(); + if (current_prefs->HasPrefPath(prefs::kNTPTipsServer)) { + std::wstring server = current_prefs->GetString(prefs::kNTPTipsServer); + std::wstring locale = ASCIIToWide( + g_browser_process->GetApplicationLocale()); + if (!EndsWith(server, locale, false)) { + dom_ui_->CallJavascriptFunction(L"tips", list_value); + return; + } + } + if (tips_cache_ != NULL && tips_cache_->GetSize() >= 0) { if (tips_cache_->GetInteger( WebResourceService::kCurrentTipPrefName, ¤t_tip_index) && diff --git a/chrome/browser/web_resource/web_resource_service.cc b/chrome/browser/web_resource/web_resource_service.cc index f88b95d..dcfeade 100644 --- a/chrome/browser/web_resource/web_resource_service.cc +++ b/chrome/browser/web_resource/web_resource_service.cc @@ -196,15 +196,20 @@ void WebResourceService::Init() { resource_dispatcher_host_ = g_browser_process->resource_dispatcher_host(); web_resource_fetcher_ = new WebResourceFetcher(this); prefs_->RegisterStringPref(prefs::kNTPTipsCacheUpdate, L"0"); + std::wstring locale = ASCIIToWide(g_browser_process->GetApplicationLocale()); - // TODO(mirandac): allow for language change without wiping out prefs file. if (prefs_->HasPrefPath(prefs::kNTPTipsServer)) { - web_resource_server_ = prefs_->GetString(prefs::kNTPTipsServer); - } else { - web_resource_server_ = kDefaultResourceServer; - web_resource_server_.append( - ASCIIToWide(g_browser_process->GetApplicationLocale())); + web_resource_server_ = prefs_->GetString(prefs::kNTPTipsServer); + // If we are in the correct locale, initialization is done. + if (EndsWith(web_resource_server_, locale, false)) + return; } + + // If we have not yet set a server, or if the tips server is set to the wrong + // locale, reset the server and force an immediate update of tips. + web_resource_server_ = kDefaultResourceServer; + web_resource_server_.append(locale); + prefs_->SetString(prefs::kNTPTipsCacheUpdate, L""); } void WebResourceService::EndFetch() { @@ -258,13 +263,15 @@ void WebResourceService::StartAfterDelay() { if (prefs_->HasPrefPath(prefs::kNTPTipsCacheUpdate)) { std::wstring last_update_pref = prefs_->GetString(prefs::kNTPTipsCacheUpdate); - int ms_until_update = kCacheUpdateDelay - - static_cast<int>((base::Time::Now() - base::Time::FromDoubleT( - StringToDouble(WideToASCII(last_update_pref)))).InMilliseconds()); - - delay = ms_until_update > kCacheUpdateDelay ? - kCacheUpdateDelay : (ms_until_update < kStartResourceFetchDelay ? - kStartResourceFetchDelay : ms_until_update); + if (!last_update_pref.empty()) { + int ms_until_update = kCacheUpdateDelay - + static_cast<int>((base::Time::Now() - base::Time::FromDoubleT( + StringToDouble(WideToASCII(last_update_pref)))).InMilliseconds()); + + delay = ms_until_update > kCacheUpdateDelay ? + kCacheUpdateDelay : (ms_until_update < kStartResourceFetchDelay ? + kStartResourceFetchDelay : ms_until_update); + } } // Start fetch and wait for UpdateResourceCache. |