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

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

Issue 399086: Mac language/locale cleanup... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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/command_line.h" 6 #include "base/command_line.h"
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/time.h" 8 #include "base/time.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 in_fetch_(false) { 204 in_fetch_(false) {
205 Init(); 205 Init();
206 } 206 }
207 207
208 WebResourceService::~WebResourceService() { } 208 WebResourceService::~WebResourceService() { }
209 209
210 void WebResourceService::Init() { 210 void WebResourceService::Init() {
211 resource_dispatcher_host_ = g_browser_process->resource_dispatcher_host(); 211 resource_dispatcher_host_ = g_browser_process->resource_dispatcher_host();
212 web_resource_fetcher_ = new WebResourceFetcher(this); 212 web_resource_fetcher_ = new WebResourceFetcher(this);
213 prefs_->RegisterStringPref(prefs::kNTPTipsCacheUpdate, L"0"); 213 prefs_->RegisterStringPref(prefs::kNTPTipsCacheUpdate, L"0");
214 std::wstring language = WebResourceService::GetWebResourceLanguage(prefs_); 214 std::wstring locale = ASCIIToWide(g_browser_process->GetApplicationLocale());
215 215
216 if (prefs_->HasPrefPath(prefs::kNTPTipsServer)) { 216 if (prefs_->HasPrefPath(prefs::kNTPTipsServer)) {
217 web_resource_server_ = prefs_->GetString(prefs::kNTPTipsServer); 217 web_resource_server_ = prefs_->GetString(prefs::kNTPTipsServer);
218 // If we are in the correct locale, initialization is done. 218 // If we are in the correct locale, initialization is done.
219 if (EndsWith(web_resource_server_, language, false)) 219 if (EndsWith(web_resource_server_, locale, false))
220 return; 220 return;
221 } 221 }
222 222
223 // If we have not yet set a server, or if the tips server is set to the wrong 223 // If we have not yet set a server, or if the tips server is set to the wrong
224 // locale, reset the server and force an immediate update of tips. 224 // locale, reset the server and force an immediate update of tips.
225 web_resource_server_ = kDefaultResourceServer; 225 web_resource_server_ = kDefaultResourceServer;
226 web_resource_server_.append(language); 226 web_resource_server_.append(locale);
227 prefs_->SetString(prefs::kNTPTipsCacheUpdate, L""); 227 prefs_->SetString(prefs::kNTPTipsCacheUpdate, L"");
228 } 228 }
229 229
230 void WebResourceService::EndFetch() { 230 void WebResourceService::EndFetch() {
231 in_fetch_ = false; 231 in_fetch_ = false;
232 } 232 }
233 233
234 void WebResourceService::OnWebResourceUnpacked( 234 void WebResourceService::OnWebResourceUnpacked(
235 const DictionaryValue& parsed_json) { 235 const DictionaryValue& parsed_json) {
236 // Get dictionary of cached preferences. 236 // Get dictionary of cached preferences.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 295
296 void WebResourceService::UpdateResourceCache(const std::string& json_data) { 296 void WebResourceService::UpdateResourceCache(const std::string& json_data) {
297 UnpackerClient* client = new UnpackerClient(this, json_data); 297 UnpackerClient* client = new UnpackerClient(this, json_data);
298 client->Start(); 298 client->Start();
299 299
300 // Update resource server and cache update time in preferences. 300 // Update resource server and cache update time in preferences.
301 prefs_->SetString(prefs::kNTPTipsCacheUpdate, 301 prefs_->SetString(prefs::kNTPTipsCacheUpdate,
302 DoubleToWString(base::Time::Now().ToDoubleT())); 302 DoubleToWString(base::Time::Now().ToDoubleT()));
303 prefs_->SetString(prefs::kNTPTipsServer, web_resource_server_); 303 prefs_->SetString(prefs::kNTPTipsServer, web_resource_server_);
304 } 304 }
305
306 // static
307 std::wstring WebResourceService::GetWebResourceLanguage(PrefService* prefs) {
308 #if defined OS_MACOSX
309 // OS X derives the language for the Chrome UI from the list of accepted
310 // languages, which can be different from the locale.
311 std::wstring languageList = prefs->GetString(prefs::kAcceptLanguages);
312 int pos = languageList.find(L",");
313 pos = pos >= 0 ? pos : languageList.length();
314 return languageList.substr(0, pos);
315 #else
316 return ASCIIToWide(g_browser_process->GetApplicationLocale());
317 #endif
318 }
319
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