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/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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 | 64 |
65 DataPack::DataPack(ui::ScaleFactor scale_factor) | 65 DataPack::DataPack(ui::ScaleFactor scale_factor) |
66 : resource_count_(0), | 66 : resource_count_(0), |
67 text_encoding_type_(BINARY), | 67 text_encoding_type_(BINARY), |
68 scale_factor_(scale_factor) { | 68 scale_factor_(scale_factor) { |
69 } | 69 } |
70 | 70 |
71 DataPack::~DataPack() { | 71 DataPack::~DataPack() { |
72 } | 72 } |
73 | 73 |
74 bool DataPack::LoadFromPath(const FilePath& path) { | 74 bool DataPack::LoadFromPath(const base::FilePath& path) { |
75 mmap_.reset(new file_util::MemoryMappedFile); | 75 mmap_.reset(new file_util::MemoryMappedFile); |
76 if (!mmap_->Initialize(path)) { | 76 if (!mmap_->Initialize(path)) { |
77 DLOG(ERROR) << "Failed to mmap datapack"; | 77 DLOG(ERROR) << "Failed to mmap datapack"; |
78 UMA_HISTOGRAM_ENUMERATION("DataPack.Load", INIT_FAILED, | 78 UMA_HISTOGRAM_ENUMERATION("DataPack.Load", INIT_FAILED, |
79 LOAD_ERRORS_COUNT); | 79 LOAD_ERRORS_COUNT); |
80 mmap_.reset(); | 80 mmap_.reset(); |
81 return false; | 81 return false; |
82 } | 82 } |
83 return LoadImpl(); | 83 return LoadImpl(); |
84 } | 84 } |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 | 205 |
206 ResourceHandle::TextEncodingType DataPack::GetTextEncodingType() const { | 206 ResourceHandle::TextEncodingType DataPack::GetTextEncodingType() const { |
207 return text_encoding_type_; | 207 return text_encoding_type_; |
208 } | 208 } |
209 | 209 |
210 ui::ScaleFactor DataPack::GetScaleFactor() const { | 210 ui::ScaleFactor DataPack::GetScaleFactor() const { |
211 return scale_factor_; | 211 return scale_factor_; |
212 } | 212 } |
213 | 213 |
214 // static | 214 // static |
215 bool DataPack::WritePack(const FilePath& path, | 215 bool DataPack::WritePack(const base::FilePath& path, |
216 const std::map<uint16, base::StringPiece>& resources, | 216 const std::map<uint16, base::StringPiece>& resources, |
217 TextEncodingType textEncodingType) { | 217 TextEncodingType textEncodingType) { |
218 FILE* file = file_util::OpenFile(path, "wb"); | 218 FILE* file = file_util::OpenFile(path, "wb"); |
219 if (!file) | 219 if (!file) |
220 return false; | 220 return false; |
221 | 221 |
222 if (fwrite(&kFileFormatVersion, sizeof(kFileFormatVersion), 1, file) != 1) { | 222 if (fwrite(&kFileFormatVersion, sizeof(kFileFormatVersion), 1, file) != 1) { |
223 LOG(ERROR) << "Failed to write file version"; | 223 LOG(ERROR) << "Failed to write file version"; |
224 file_util::CloseFile(file); | 224 file_util::CloseFile(file); |
225 return false; | 225 return false; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 return false; | 296 return false; |
297 } | 297 } |
298 } | 298 } |
299 | 299 |
300 file_util::CloseFile(file); | 300 file_util::CloseFile(file); |
301 | 301 |
302 return true; | 302 return true; |
303 } | 303 } |
304 | 304 |
305 } // namespace ui | 305 } // namespace ui |
OLD | NEW |