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

Unified Diff: ui/base/resource/data_pack.cc

Issue 10686005: Add methods to add DataPack from open files (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/base/resource/data_pack.h ('k') | ui/base/resource/data_pack_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/resource/data_pack.cc
diff --git a/ui/base/resource/data_pack.cc b/ui/base/resource/data_pack.cc
index e1d8c144ac54ec21c7f3448c3f9b34a6b713d659..87c8735d319d4339a7dfd78ad8c081ca6d95ba44 100644
--- a/ui/base/resource/data_pack.cc
+++ b/ui/base/resource/data_pack.cc
@@ -53,6 +53,7 @@ enum LoadErrors {
ENTRY_NOT_FOUND,
HEADER_TRUNCATED,
WRONG_ENCODING,
+ INIT_FAILED_FROM_FILE,
LOAD_ERRORS_COUNT,
};
@@ -70,7 +71,7 @@ DataPack::DataPack(ui::ScaleFactor scale_factor)
DataPack::~DataPack() {
}
-bool DataPack::Load(const FilePath& path) {
+bool DataPack::LoadFromPath(const FilePath& path) {
mmap_.reset(new file_util::MemoryMappedFile);
if (!mmap_->Initialize(path)) {
DLOG(ERROR) << "Failed to mmap datapack";
@@ -79,7 +80,22 @@ bool DataPack::Load(const FilePath& path) {
mmap_.reset();
return false;
}
+ return LoadImpl();
+}
+
+bool DataPack::LoadFromFile(base::PlatformFile file) {
+ mmap_.reset(new file_util::MemoryMappedFile);
+ if (!mmap_->Initialize(file)) {
+ DLOG(ERROR) << "Failed to mmap datapack";
+ UMA_HISTOGRAM_ENUMERATION("DataPack.Load", INIT_FAILED_FROM_FILE,
+ LOAD_ERRORS_COUNT);
+ mmap_.reset();
+ return false;
+ }
+ return LoadImpl();
+}
+bool DataPack::LoadImpl() {
// Sanity check the header of the file.
if (kHeaderLength > mmap_->length()) {
DLOG(ERROR) << "Data pack file corruption: incomplete file header.";
« no previous file with comments | « ui/base/resource/data_pack.h ('k') | ui/base/resource/data_pack_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698