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

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

Issue 10151025: Add scale factor tag to data packs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 7 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 | Annotate | Revision Log
« 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 HEADER_TRUNCATED, 54 HEADER_TRUNCATED,
55 WRONG_ENCODING, 55 WRONG_ENCODING,
56 56
57 LOAD_ERRORS_COUNT, 57 LOAD_ERRORS_COUNT,
58 }; 58 };
59 59
60 } // namespace 60 } // namespace
61 61
62 namespace ui { 62 namespace ui {
63 63
64 // In .cc for MemoryMappedFile dtor. 64 DataPack::DataPack(float scale_factor)
65 DataPack::DataPack() : resource_count_(0), text_encoding_type_(BINARY) { 65 : resource_count_(0),
66 text_encoding_type_(BINARY),
67 scale_factor_(scale_factor) {
66 } 68 }
69
67 DataPack::~DataPack() { 70 DataPack::~DataPack() {
68 } 71 }
69 72
70 bool DataPack::Load(const FilePath& path) { 73 bool DataPack::Load(const FilePath& path) {
71 mmap_.reset(new file_util::MemoryMappedFile); 74 mmap_.reset(new file_util::MemoryMappedFile);
72 if (!mmap_->Initialize(path)) { 75 if (!mmap_->Initialize(path)) {
73 DLOG(ERROR) << "Failed to mmap datapack"; 76 DLOG(ERROR) << "Failed to mmap datapack";
74 UMA_HISTOGRAM_ENUMERATION("DataPack.Load", INIT_FAILED, 77 UMA_HISTOGRAM_ENUMERATION("DataPack.Load", INIT_FAILED,
75 LOAD_ERRORS_COUNT); 78 LOAD_ERRORS_COUNT);
76 mmap_.reset(); 79 mmap_.reset();
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 return NULL; 179 return NULL;
177 180
178 return new base::RefCountedStaticMemory( 181 return new base::RefCountedStaticMemory(
179 reinterpret_cast<const unsigned char*>(piece.data()), piece.length()); 182 reinterpret_cast<const unsigned char*>(piece.data()), piece.length());
180 } 183 }
181 184
182 ResourceHandle::TextEncodingType DataPack::GetTextEncodingType() const { 185 ResourceHandle::TextEncodingType DataPack::GetTextEncodingType() const {
183 return text_encoding_type_; 186 return text_encoding_type_;
184 } 187 }
185 188
189 float DataPack::GetScaleFactor() const {
190 return scale_factor_;
191 }
192
186 // static 193 // static
187 bool DataPack::WritePack(const FilePath& path, 194 bool DataPack::WritePack(const FilePath& path,
188 const std::map<uint16, base::StringPiece>& resources, 195 const std::map<uint16, base::StringPiece>& resources,
189 TextEncodingType textEncodingType) { 196 TextEncodingType textEncodingType) {
190 FILE* file = file_util::OpenFile(path, "wb"); 197 FILE* file = file_util::OpenFile(path, "wb");
191 if (!file) 198 if (!file)
192 return false; 199 return false;
193 200
194 if (fwrite(&kFileFormatVersion, sizeof(kFileFormatVersion), 1, file) != 1) { 201 if (fwrite(&kFileFormatVersion, sizeof(kFileFormatVersion), 1, file) != 1) {
195 LOG(ERROR) << "Failed to write file version"; 202 LOG(ERROR) << "Failed to write file version";
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 return false; 275 return false;
269 } 276 }
270 } 277 }
271 278
272 file_util::CloseFile(file); 279 file_util::CloseFile(file);
273 280
274 return true; 281 return true;
275 } 282 }
276 283
277 } // namespace ui 284 } // 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