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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/data_pack.h" 5 #include "ui/base/resource/data_pack.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 // We're crashing when trying to load a pak file on Windows. Add some error 46 // We're crashing when trying to load a pak file on Windows. Add some error
47 // codes for logging. 47 // codes for logging.
48 // http://crbug.com/58056 48 // http://crbug.com/58056
49 enum LoadErrors { 49 enum LoadErrors {
50 INIT_FAILED = 1, 50 INIT_FAILED = 1,
51 BAD_VERSION, 51 BAD_VERSION,
52 INDEX_TRUNCATED, 52 INDEX_TRUNCATED,
53 ENTRY_NOT_FOUND, 53 ENTRY_NOT_FOUND,
54 HEADER_TRUNCATED, 54 HEADER_TRUNCATED,
55 WRONG_ENCODING, 55 WRONG_ENCODING,
56 INIT_FAILED_FROM_FILE,
56 57
57 LOAD_ERRORS_COUNT, 58 LOAD_ERRORS_COUNT,
58 }; 59 };
59 60
60 } // namespace 61 } // namespace
61 62
62 namespace ui { 63 namespace ui {
63 64
64 DataPack::DataPack(ui::ScaleFactor scale_factor) 65 DataPack::DataPack(ui::ScaleFactor scale_factor)
65 : resource_count_(0), 66 : resource_count_(0),
66 text_encoding_type_(BINARY), 67 text_encoding_type_(BINARY),
67 scale_factor_(scale_factor) { 68 scale_factor_(scale_factor) {
68 } 69 }
69 70
70 DataPack::~DataPack() { 71 DataPack::~DataPack() {
71 } 72 }
72 73
73 bool DataPack::Load(const FilePath& path) { 74 bool DataPack::LoadFromPath(const FilePath& path) {
74 mmap_.reset(new file_util::MemoryMappedFile); 75 mmap_.reset(new file_util::MemoryMappedFile);
75 if (!mmap_->Initialize(path)) { 76 if (!mmap_->Initialize(path)) {
76 DLOG(ERROR) << "Failed to mmap datapack"; 77 DLOG(ERROR) << "Failed to mmap datapack";
77 UMA_HISTOGRAM_ENUMERATION("DataPack.Load", INIT_FAILED, 78 UMA_HISTOGRAM_ENUMERATION("DataPack.Load", INIT_FAILED,
78 LOAD_ERRORS_COUNT); 79 LOAD_ERRORS_COUNT);
79 mmap_.reset(); 80 mmap_.reset();
80 return false; 81 return false;
81 } 82 }
83 return LoadImpl();
84 }
82 85
86 bool DataPack::LoadFromFile(base::PlatformFile file) {
87 mmap_.reset(new file_util::MemoryMappedFile);
88 if (!mmap_->Initialize(file)) {
89 DLOG(ERROR) << "Failed to mmap datapack";
90 UMA_HISTOGRAM_ENUMERATION("DataPack.Load", INIT_FAILED_FROM_FILE,
91 LOAD_ERRORS_COUNT);
92 mmap_.reset();
93 return false;
94 }
95 return LoadImpl();
96 }
97
98 bool DataPack::LoadImpl() {
83 // Sanity check the header of the file. 99 // Sanity check the header of the file.
84 if (kHeaderLength > mmap_->length()) { 100 if (kHeaderLength > mmap_->length()) {
85 DLOG(ERROR) << "Data pack file corruption: incomplete file header."; 101 DLOG(ERROR) << "Data pack file corruption: incomplete file header.";
86 UMA_HISTOGRAM_ENUMERATION("DataPack.Load", HEADER_TRUNCATED, 102 UMA_HISTOGRAM_ENUMERATION("DataPack.Load", HEADER_TRUNCATED,
87 LOAD_ERRORS_COUNT); 103 LOAD_ERRORS_COUNT);
88 mmap_.reset(); 104 mmap_.reset();
89 return false; 105 return false;
90 } 106 }
91 107
92 // Parse the header of the file. 108 // Parse the header of the file.
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 return false; 296 return false;
281 } 297 }
282 } 298 }
283 299
284 file_util::CloseFile(file); 300 file_util::CloseFile(file);
285 301
286 return true; 302 return true;
287 } 303 }
288 304
289 } // namespace ui 305 } // namespace ui
OLDNEW
« 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