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

Side by Side Diff: ui/base/resource/resource_bundle.cc

Issue 1187433006: Load language .pak files directly from the apk when using splits (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@locale-res-or-file
Patch Set: Fix ui_base_unittest failure (allow locale paks to be loaded multiple times) Created 5 years, 5 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
OLDNEW
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 "ui/base/resource/resource_bundle.h" 5 #include "ui/base/resource/resource_bundle.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/big_endian.h" 10 #include "base/big_endian.h"
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 if (locale_file_path.empty() || !locale_file_path.IsAbsolute()) 258 if (locale_file_path.empty() || !locale_file_path.IsAbsolute())
259 return base::FilePath(); 259 return base::FilePath();
260 260
261 if (test_file_exists && !base::PathExists(locale_file_path)) 261 if (test_file_exists && !base::PathExists(locale_file_path))
262 return base::FilePath(); 262 return base::FilePath();
263 263
264 return locale_file_path; 264 return locale_file_path;
265 } 265 }
266 #endif 266 #endif
267 267
268 #if !defined(OS_ANDROID)
268 std::string ResourceBundle::LoadLocaleResources( 269 std::string ResourceBundle::LoadLocaleResources(
269 const std::string& pref_locale) { 270 const std::string& pref_locale) {
270 DCHECK(!locale_resources_data_.get()) << "locale.pak already loaded"; 271 DCHECK(!locale_resources_data_.get()) << "locale.pak already loaded";
271 std::string app_locale = l10n_util::GetApplicationLocale(pref_locale); 272 std::string app_locale = l10n_util::GetApplicationLocale(pref_locale);
272 base::FilePath locale_file_path = GetOverriddenPakPath(); 273 base::FilePath locale_file_path = GetOverriddenPakPath();
273 if (locale_file_path.empty()) 274 if (locale_file_path.empty())
274 locale_file_path = GetLocaleFilePath(app_locale, true); 275 locale_file_path = GetLocaleFilePath(app_locale, true);
275 276
276 if (locale_file_path.empty()) { 277 if (locale_file_path.empty()) {
277 // It's possible that there is no locale.pak. 278 // It's possible that there is no locale.pak.
278 LOG(WARNING) << "locale_file_path.empty()"; 279 LOG(WARNING) << "locale_file_path.empty() for locale " << app_locale;
279 return std::string(); 280 return std::string();
280 } 281 }
281 282
282 scoped_ptr<DataPack> data_pack( 283 scoped_ptr<DataPack> data_pack(
283 new DataPack(SCALE_FACTOR_100P)); 284 new DataPack(SCALE_FACTOR_100P));
284 if (!data_pack->LoadFromPath(locale_file_path)) { 285 if (!data_pack->LoadFromPath(locale_file_path)) {
285 UMA_HISTOGRAM_ENUMERATION("ResourceBundle.LoadLocaleResourcesError", 286 UMA_HISTOGRAM_ENUMERATION("ResourceBundle.LoadLocaleResourcesError",
286 logging::GetLastSystemErrorCode(), 16000); 287 logging::GetLastSystemErrorCode(), 16000);
287 LOG(ERROR) << "failed to load locale.pak"; 288 LOG(ERROR) << "failed to load locale.pak";
288 NOTREACHED(); 289 NOTREACHED();
289 return std::string(); 290 return std::string();
290 } 291 }
291 292
292 locale_resources_data_.reset(data_pack.release()); 293 locale_resources_data_.reset(data_pack.release());
293 return app_locale; 294 return app_locale;
294 } 295 }
296 #endif // defined(OS_ANDROID)
295 297
296 void ResourceBundle::LoadTestResources(const base::FilePath& path, 298 void ResourceBundle::LoadTestResources(const base::FilePath& path,
297 const base::FilePath& locale_path) { 299 const base::FilePath& locale_path) {
298 DCHECK(!ui::GetSupportedScaleFactors().empty()); 300 DCHECK(!ui::GetSupportedScaleFactors().empty());
299 const ScaleFactor scale_factor(ui::GetSupportedScaleFactors()[0]); 301 const ScaleFactor scale_factor(ui::GetSupportedScaleFactors()[0]);
300 // Use the given resource pak for both common and localized resources. 302 // Use the given resource pak for both common and localized resources.
301 scoped_ptr<DataPack> data_pack(new DataPack(scale_factor)); 303 scoped_ptr<DataPack> data_pack(new DataPack(scale_factor));
302 if (!path.empty() && data_pack->LoadFromPath(path)) 304 if (!path.empty() && data_pack->LoadFromPath(path))
303 AddDataPack(data_pack.release()); 305 AddDataPack(data_pack.release());
304 306
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 // static 852 // static
851 bool ResourceBundle::DecodePNG(const unsigned char* buf, 853 bool ResourceBundle::DecodePNG(const unsigned char* buf,
852 size_t size, 854 size_t size,
853 SkBitmap* bitmap, 855 SkBitmap* bitmap,
854 bool* fell_back_to_1x) { 856 bool* fell_back_to_1x) {
855 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); 857 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size);
856 return gfx::PNGCodec::Decode(buf, size, bitmap); 858 return gfx::PNGCodec::Decode(buf, size, bitmap);
857 } 859 }
858 860
859 } // namespace ui 861 } // namespace ui
OLDNEW
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | ui/base/resource/resource_bundle_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698