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

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

Issue 1115033003: resources: Prevent including the same resource in multiple pack files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tot-merge Created 5 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
« no previous file with comments | « ui/base/resource/data_pack.h ('k') | ui/base/resource/resource_bundle.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/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/files/memory_mapped_file.h" 10 #include "base/files/memory_mapped_file.h"
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 } 224 }
225 225
226 ResourceHandle::TextEncodingType DataPack::GetTextEncodingType() const { 226 ResourceHandle::TextEncodingType DataPack::GetTextEncodingType() const {
227 return text_encoding_type_; 227 return text_encoding_type_;
228 } 228 }
229 229
230 ui::ScaleFactor DataPack::GetScaleFactor() const { 230 ui::ScaleFactor DataPack::GetScaleFactor() const {
231 return scale_factor_; 231 return scale_factor_;
232 } 232 }
233 233
234 #if DCHECK_IS_ON()
235 void DataPack::CheckForDuplicateResources(
236 const ScopedVector<ResourceHandle>& packs) {
237 for (size_t i = 0; i < resource_count_ + 1; ++i) {
238 const DataPackEntry* entry = reinterpret_cast<const DataPackEntry*>(
239 mmap_->data() + kHeaderLength + (i * sizeof(DataPackEntry)));
240 const uint16 resource_id = entry->resource_id;
241 const float resource_scale = GetScaleForScaleFactor(scale_factor_);
242 for (const ResourceHandle* handle : packs) {
243 DCHECK_IMPLIES(
244 GetScaleForScaleFactor(handle->GetScaleFactor()) == resource_scale,
245 !handle->HasResource(resource_id));
246 }
247 }
248 }
249 #endif // DCHECK_IS_ON()
250
234 // static 251 // static
235 bool DataPack::WritePack(const base::FilePath& path, 252 bool DataPack::WritePack(const base::FilePath& path,
236 const std::map<uint16, base::StringPiece>& resources, 253 const std::map<uint16, base::StringPiece>& resources,
237 TextEncodingType textEncodingType) { 254 TextEncodingType textEncodingType) {
238 FILE* file = base::OpenFile(path, "wb"); 255 FILE* file = base::OpenFile(path, "wb");
239 if (!file) 256 if (!file)
240 return false; 257 return false;
241 258
242 if (fwrite(&kFileFormatVersion, sizeof(kFileFormatVersion), 1, file) != 1) { 259 if (fwrite(&kFileFormatVersion, sizeof(kFileFormatVersion), 1, file) != 1) {
243 LOG(ERROR) << "Failed to write file version"; 260 LOG(ERROR) << "Failed to write file version";
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 return false; 333 return false;
317 } 334 }
318 } 335 }
319 336
320 base::CloseFile(file); 337 base::CloseFile(file);
321 338
322 return true; 339 return true;
323 } 340 }
324 341
325 } // namespace ui 342 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/resource/data_pack.h ('k') | ui/base/resource/resource_bundle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698