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

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

Issue 537063002: Eliminate silently letting errors pass on pak loading. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ios finally works Created 6 years, 3 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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 void ResourceBundle::AddDataPackFromFile(base::File file, 243 void ResourceBundle::AddDataPackFromFile(base::File file,
244 ScaleFactor scale_factor) { 244 ScaleFactor scale_factor) {
245 AddDataPackFromFileRegion( 245 AddDataPackFromFileRegion(
246 file.Pass(), base::MemoryMappedFile::Region::kWholeFile, scale_factor); 246 file.Pass(), base::MemoryMappedFile::Region::kWholeFile, scale_factor);
247 } 247 }
248 248
249 void ResourceBundle::AddDataPackFromFileRegion( 249 void ResourceBundle::AddDataPackFromFileRegion(
250 base::File file, 250 base::File file,
251 const base::MemoryMappedFile::Region& region, 251 const base::MemoryMappedFile::Region& region,
252 ScaleFactor scale_factor) { 252 ScaleFactor scale_factor) {
253 scoped_ptr<DataPack> data_pack( 253 scoped_ptr<DataPack> data_pack(new DataPack(scale_factor));
254 new DataPack(scale_factor));
255 if (data_pack->LoadFromFileRegion(file.Pass(), region)) { 254 if (data_pack->LoadFromFileRegion(file.Pass(), region)) {
256 AddDataPack(data_pack.release()); 255 AddDataPack(data_pack.release());
257 } else { 256 } else {
258 LOG(ERROR) << "Failed to load data pack from file." 257 LOG(ERROR) << "Failed to load data pack from file."
259 << "\nSome features may not be available."; 258 << "\nSome features may not be available.";
260 } 259 }
261 } 260 }
262 261
263 #if !defined(OS_MACOSX) 262 #if !defined(OS_MACOSX)
264 base::FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale, 263 base::FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 base::FilePath locale_file_path = GetOverriddenPakPath(); 297 base::FilePath locale_file_path = GetOverriddenPakPath();
299 if (locale_file_path.empty()) 298 if (locale_file_path.empty())
300 locale_file_path = GetLocaleFilePath(app_locale, true); 299 locale_file_path = GetLocaleFilePath(app_locale, true);
301 300
302 if (locale_file_path.empty()) { 301 if (locale_file_path.empty()) {
303 // It's possible that there is no locale.pak. 302 // It's possible that there is no locale.pak.
304 LOG(WARNING) << "locale_file_path.empty()"; 303 LOG(WARNING) << "locale_file_path.empty()";
305 return std::string(); 304 return std::string();
306 } 305 }
307 306
308 scoped_ptr<DataPack> data_pack( 307 scoped_ptr<DataPack> data_pack(new DataPack(SCALE_FACTOR_100P));
309 new DataPack(SCALE_FACTOR_100P));
310 if (!data_pack->LoadFromPath(locale_file_path)) { 308 if (!data_pack->LoadFromPath(locale_file_path)) {
311 UMA_HISTOGRAM_ENUMERATION("ResourceBundle.LoadLocaleResourcesError", 309 UMA_HISTOGRAM_ENUMERATION("ResourceBundle.LoadLocaleResourcesError",
312 logging::GetLastSystemErrorCode(), 16000); 310 logging::GetLastSystemErrorCode(), 16000);
313 LOG(ERROR) << "failed to load locale.pak"; 311 LOG(ERROR) << "failed to load locale.pak";
314 NOTREACHED(); 312 NOTREACHED();
315 return std::string(); 313 return std::string();
316 } 314 }
317 315
318 locale_resources_data_.reset(data_pack.release()); 316 locale_resources_data_.reset(data_pack.release());
319 return app_locale; 317 return app_locale;
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 ScaleFactor scale_factor, 651 ScaleFactor scale_factor,
654 bool optional) { 652 bool optional) {
655 // Do not pass an empty |path| value to this method. If the absolute path is 653 // Do not pass an empty |path| value to this method. If the absolute path is
656 // unknown pass just the pack file name. 654 // unknown pass just the pack file name.
657 DCHECK(!path.empty()); 655 DCHECK(!path.empty());
658 656
659 base::FilePath pack_path = path; 657 base::FilePath pack_path = path;
660 if (delegate_) 658 if (delegate_)
661 pack_path = delegate_->GetPathForResourcePack(pack_path, scale_factor); 659 pack_path = delegate_->GetPathForResourcePack(pack_path, scale_factor);
662 660
663 // Don't try to load empty values or values that are not absolute paths. 661 // An empty path is a request from the delegate to cancel loading.
664 if (pack_path.empty() || !pack_path.IsAbsolute()) 662 if (pack_path.empty())
665 return; 663 return;
666 664
667 scoped_ptr<DataPack> data_pack( 665 scoped_ptr<DataPack> data_pack(new DataPack(scale_factor));
668 new DataPack(scale_factor));
669 if (data_pack->LoadFromPath(pack_path)) { 666 if (data_pack->LoadFromPath(pack_path)) {
670 AddDataPack(data_pack.release()); 667 AddDataPack(data_pack.release());
671 } else if (!optional) { 668 } else if (!optional) {
672 LOG(ERROR) << "Failed to load " << pack_path.value() 669 DLOG(FATAL) << "Failed to load " << pack_path.value();
673 << "\nSome features may not be available.";
674 } 670 }
675 } 671 }
676 672
677 void ResourceBundle::AddDataPack(DataPack* data_pack) { 673 void ResourceBundle::AddDataPack(DataPack* data_pack) {
678 data_packs_.push_back(data_pack); 674 data_packs_.push_back(data_pack);
679 675
680 if (GetScaleForScaleFactor(data_pack->GetScaleFactor()) > 676 if (GetScaleForScaleFactor(data_pack->GetScaleFactor()) >
681 GetScaleForScaleFactor(max_scale_factor_)) 677 GetScaleForScaleFactor(max_scale_factor_))
682 max_scale_factor_ = data_pack->GetScaleFactor(); 678 max_scale_factor_ = data_pack->GetScaleFactor();
683 } 679 }
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 // static 847 // static
852 bool ResourceBundle::DecodePNG(const unsigned char* buf, 848 bool ResourceBundle::DecodePNG(const unsigned char* buf,
853 size_t size, 849 size_t size,
854 SkBitmap* bitmap, 850 SkBitmap* bitmap,
855 bool* fell_back_to_1x) { 851 bool* fell_back_to_1x) {
856 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); 852 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size);
857 return gfx::PNGCodec::Decode(buf, size, bitmap); 853 return gfx::PNGCodec::Decode(buf, size, bitmap);
858 } 854 }
859 855
860 } // namespace ui 856 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698