| OLD | NEW |
| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 // static | 208 // static |
| 209 void ResourceBundle::InitSharedInstanceWithPakFileRegion( | 209 void ResourceBundle::InitSharedInstanceWithPakFileRegion( |
| 210 base::File pak_file, | 210 base::File pak_file, |
| 211 const base::MemoryMappedFile::Region& region) { | 211 const base::MemoryMappedFile::Region& region) { |
| 212 InitSharedInstance(NULL); | 212 InitSharedInstance(NULL); |
| 213 std::unique_ptr<DataPack> data_pack(new DataPack(SCALE_FACTOR_100P)); | 213 std::unique_ptr<DataPack> data_pack(new DataPack(SCALE_FACTOR_100P)); |
| 214 if (!data_pack->LoadFromFileRegion(std::move(pak_file), region)) { | 214 if (!data_pack->LoadFromFileRegion(std::move(pak_file), region)) { |
| 215 NOTREACHED() << "failed to load pak file"; | 215 NOTREACHED() << "failed to load pak file"; |
| 216 return; | 216 return; |
| 217 } | 217 } |
| 218 g_shared_instance_->locale_resources_data_.reset(data_pack.release()); | 218 g_shared_instance_->locale_resources_data_ = std::move(data_pack); |
| 219 g_shared_instance_->InitDefaultFontList(); | 219 g_shared_instance_->InitDefaultFontList(); |
| 220 } | 220 } |
| 221 | 221 |
| 222 // static | 222 // static |
| 223 void ResourceBundle::InitSharedInstanceWithPakPath(const base::FilePath& path) { | 223 void ResourceBundle::InitSharedInstanceWithPakPath(const base::FilePath& path) { |
| 224 InitSharedInstance(NULL); | 224 InitSharedInstance(NULL); |
| 225 g_shared_instance_->LoadTestResources(path, path); | 225 g_shared_instance_->LoadTestResources(path, path); |
| 226 | 226 |
| 227 g_shared_instance_->InitDefaultFontList(); | 227 g_shared_instance_->InitDefaultFontList(); |
| 228 } | 228 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 return std::string(); | 329 return std::string(); |
| 330 } | 330 } |
| 331 | 331 |
| 332 std::unique_ptr<DataPack> data_pack(new DataPack(SCALE_FACTOR_100P)); | 332 std::unique_ptr<DataPack> data_pack(new DataPack(SCALE_FACTOR_100P)); |
| 333 if (!data_pack->LoadFromPath(locale_file_path)) { | 333 if (!data_pack->LoadFromPath(locale_file_path)) { |
| 334 LOG(ERROR) << "failed to load locale.pak"; | 334 LOG(ERROR) << "failed to load locale.pak"; |
| 335 NOTREACHED(); | 335 NOTREACHED(); |
| 336 return std::string(); | 336 return std::string(); |
| 337 } | 337 } |
| 338 | 338 |
| 339 locale_resources_data_.reset(data_pack.release()); | 339 locale_resources_data_ = std::move(data_pack); |
| 340 return app_locale; | 340 return app_locale; |
| 341 } | 341 } |
| 342 #endif // defined(OS_ANDROID) | 342 #endif // defined(OS_ANDROID) |
| 343 | 343 |
| 344 void ResourceBundle::LoadTestResources(const base::FilePath& path, | 344 void ResourceBundle::LoadTestResources(const base::FilePath& path, |
| 345 const base::FilePath& locale_path) { | 345 const base::FilePath& locale_path) { |
| 346 is_test_resources_ = true; | 346 is_test_resources_ = true; |
| 347 DCHECK(!ui::GetSupportedScaleFactors().empty()); | 347 DCHECK(!ui::GetSupportedScaleFactors().empty()); |
| 348 const ScaleFactor scale_factor(ui::GetSupportedScaleFactors()[0]); | 348 const ScaleFactor scale_factor(ui::GetSupportedScaleFactors()[0]); |
| 349 // Use the given resource pak for both common and localized resources. | 349 // Use the given resource pak for both common and localized resources. |
| 350 std::unique_ptr<DataPack> data_pack(new DataPack(scale_factor)); | 350 std::unique_ptr<DataPack> data_pack(new DataPack(scale_factor)); |
| 351 if (!path.empty() && data_pack->LoadFromPath(path)) | 351 if (!path.empty() && data_pack->LoadFromPath(path)) |
| 352 AddDataPack(data_pack.release()); | 352 AddDataPack(data_pack.release()); |
| 353 | 353 |
| 354 data_pack.reset(new DataPack(ui::SCALE_FACTOR_NONE)); | 354 data_pack.reset(new DataPack(ui::SCALE_FACTOR_NONE)); |
| 355 if (!locale_path.empty() && data_pack->LoadFromPath(locale_path)) { | 355 if (!locale_path.empty() && data_pack->LoadFromPath(locale_path)) { |
| 356 locale_resources_data_.reset(data_pack.release()); | 356 locale_resources_data_ = std::move(data_pack); |
| 357 } else { | 357 } else { |
| 358 locale_resources_data_.reset(new DataPack(ui::SCALE_FACTOR_NONE)); | 358 locale_resources_data_.reset(new DataPack(ui::SCALE_FACTOR_NONE)); |
| 359 } | 359 } |
| 360 // This is necessary to initialize ICU since we won't be calling | 360 // This is necessary to initialize ICU since we won't be calling |
| 361 // LoadLocaleResources in this case. | 361 // LoadLocaleResources in this case. |
| 362 l10n_util::GetApplicationLocale(std::string()); | 362 l10n_util::GetApplicationLocale(std::string()); |
| 363 } | 363 } |
| 364 | 364 |
| 365 void ResourceBundle::UnloadLocaleResources() { | 365 void ResourceBundle::UnloadLocaleResources() { |
| 366 locale_resources_data_.reset(); | 366 locale_resources_data_.reset(); |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 // static | 900 // static |
| 901 bool ResourceBundle::DecodePNG(const unsigned char* buf, | 901 bool ResourceBundle::DecodePNG(const unsigned char* buf, |
| 902 size_t size, | 902 size_t size, |
| 903 SkBitmap* bitmap, | 903 SkBitmap* bitmap, |
| 904 bool* fell_back_to_1x) { | 904 bool* fell_back_to_1x) { |
| 905 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); | 905 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); |
| 906 return gfx::PNGCodec::Decode(buf, size, bitmap); | 906 return gfx::PNGCodec::Decode(buf, size, bitmap); |
| 907 } | 907 } |
| 908 | 908 |
| 909 } // namespace ui | 909 } // namespace ui |
| OLD | NEW |