Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(940)

Side by Side Diff: chrome/browser/web_resource/web_resource_service.cc

Issue 258037: Fix tips in OS X to respect system language settings instead of locale.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/web_resource/web_resource_service.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #include "chrome/browser/web_resource/web_resource_service.h" 4 #include "chrome/browser/web_resource/web_resource_service.h"
5 5
6 #include "base/string_util.h" 6 #include "base/string_util.h"
7 #include "base/time.h" 7 #include "base/time.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/chrome_thread.h" 10 #include "chrome/browser/chrome_thread.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 in_fetch_(false) { 198 in_fetch_(false) {
199 Init(); 199 Init();
200 } 200 }
201 201
202 WebResourceService::~WebResourceService() { } 202 WebResourceService::~WebResourceService() { }
203 203
204 void WebResourceService::Init() { 204 void WebResourceService::Init() {
205 resource_dispatcher_host_ = g_browser_process->resource_dispatcher_host(); 205 resource_dispatcher_host_ = g_browser_process->resource_dispatcher_host();
206 web_resource_fetcher_ = new WebResourceFetcher(this); 206 web_resource_fetcher_ = new WebResourceFetcher(this);
207 prefs_->RegisterStringPref(prefs::kNTPTipsCacheUpdate, L"0"); 207 prefs_->RegisterStringPref(prefs::kNTPTipsCacheUpdate, L"0");
208 std::wstring locale = ASCIIToWide(g_browser_process->GetApplicationLocale()); 208 std::wstring language = WebResourceService::GetWebResourceLanguage(prefs_);
209 209
210 if (prefs_->HasPrefPath(prefs::kNTPTipsServer)) { 210 if (prefs_->HasPrefPath(prefs::kNTPTipsServer)) {
211 web_resource_server_ = prefs_->GetString(prefs::kNTPTipsServer); 211 web_resource_server_ = prefs_->GetString(prefs::kNTPTipsServer);
212 // If we are in the correct locale, initialization is done. 212 // If we are in the correct locale, initialization is done.
213 if (EndsWith(web_resource_server_, locale, false)) 213 if (EndsWith(web_resource_server_, language, false))
214 return; 214 return;
215 } 215 }
216 216
217 // If we have not yet set a server, or if the tips server is set to the wrong 217 // If we have not yet set a server, or if the tips server is set to the wrong
218 // locale, reset the server and force an immediate update of tips. 218 // locale, reset the server and force an immediate update of tips.
219 web_resource_server_ = kDefaultResourceServer; 219 web_resource_server_ = kDefaultResourceServer;
220 web_resource_server_.append(locale); 220 web_resource_server_.append(language);
221 prefs_->SetString(prefs::kNTPTipsCacheUpdate, L""); 221 prefs_->SetString(prefs::kNTPTipsCacheUpdate, L"");
222 } 222 }
223 223
224 void WebResourceService::EndFetch() { 224 void WebResourceService::EndFetch() {
225 in_fetch_ = false; 225 in_fetch_ = false;
226 } 226 }
227 227
228 void WebResourceService::OnWebResourceUnpacked( 228 void WebResourceService::OnWebResourceUnpacked(
229 const DictionaryValue& parsed_json) { 229 const DictionaryValue& parsed_json) {
230 // Get dictionary of cached preferences. 230 // Get dictionary of cached preferences.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 289
290 void WebResourceService::UpdateResourceCache(const std::string& json_data) { 290 void WebResourceService::UpdateResourceCache(const std::string& json_data) {
291 UnpackerClient* client = new UnpackerClient(this, json_data); 291 UnpackerClient* client = new UnpackerClient(this, json_data);
292 client->Start(); 292 client->Start();
293 293
294 // Update resource server and cache update time in preferences. 294 // Update resource server and cache update time in preferences.
295 prefs_->SetString(prefs::kNTPTipsCacheUpdate, 295 prefs_->SetString(prefs::kNTPTipsCacheUpdate,
296 DoubleToWString(base::Time::Now().ToDoubleT())); 296 DoubleToWString(base::Time::Now().ToDoubleT()));
297 prefs_->SetString(prefs::kNTPTipsServer, web_resource_server_); 297 prefs_->SetString(prefs::kNTPTipsServer, web_resource_server_);
298 } 298 }
299
300 // static
301 std::wstring WebResourceService::GetWebResourceLanguage(PrefService* prefs) {
302 #if defined OS_MACOSX
Nico 2009/10/07 14:56:21 On second thought, shouldn't the os x version of t
Miranda Callahan 2009/10/07 16:22:00 Well, the tips need to always be in the same langu
303 // OS X derives the language for the Chrome UI from the list of accepted
304 // languages, which can be different from the locale.
305 std::wstring languageList = prefs->GetString(prefs::kAcceptLanguages);
306 int pos = languageList.find(L",");
307 pos = pos >= 0 ? pos : languageList.length();
308 return languageList.substr(0, pos);
309 #else
310 return ASCIIToWide(g_browser_process->GetApplicationLocale());
311 #endif
TVL 2009/10/07 12:02:48 drive by: since we're forking what is done here, I
Miranda Callahan 2009/10/07 16:22:00 Good point. I think a source of confusion is that
312 }
313
OLDNEW
« no previous file with comments | « chrome/browser/web_resource/web_resource_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698