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

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: . 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
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 <algorithm>
10
9 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
10 #include "base/files/memory_mapped_file.h" 12 #include "base/files/memory_mapped_file.h"
11 #include "base/logging.h" 13 #include "base/logging.h"
12 #include "base/memory/ref_counted_memory.h" 14 #include "base/memory/ref_counted_memory.h"
13 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
14 #include "base/strings/string_piece.h" 16 #include "base/strings/string_piece.h"
15 17
16 // For details of the file layout, see 18 // For details of the file layout, see
17 // http://dev.chromium.org/developers/design-documents/linuxresourcesandlocalize dstrings 19 // http://dev.chromium.org/developers/design-documents/linuxresourcesandlocalize dstrings
18 20
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 } 226 }
225 227
226 ResourceHandle::TextEncodingType DataPack::GetTextEncodingType() const { 228 ResourceHandle::TextEncodingType DataPack::GetTextEncodingType() const {
227 return text_encoding_type_; 229 return text_encoding_type_;
228 } 230 }
229 231
230 ui::ScaleFactor DataPack::GetScaleFactor() const { 232 ui::ScaleFactor DataPack::GetScaleFactor() const {
231 return scale_factor_; 233 return scale_factor_;
232 } 234 }
233 235
236 #if DCHECK_IS_ON()
237 void DataPack::CheckForDuplicateResources(
238 const ScopedVector<ResourceHandle>& packs) {
239 for (size_t i = 0; i < resource_count_ + 1; ++i) {
Nico 2015/05/02 00:50:48 why + 1?
sadrul 2015/05/02 04:17:09 I am following the code from DataPack::LoadImpl()
240 const DataPackEntry* entry = reinterpret_cast<const DataPackEntry*>(
241 mmap_->data() + kHeaderLength + (i * sizeof(DataPackEntry)));
242 const uint16 resource_id = entry->resource_id;
243 const float resource_scale = GetScaleForScaleFactor(scale_factor_);
244 std::for_each(packs.begin(), packs.end(),
245 [resource_id, resource_scale](const ResourceHandle* handle) {
246 DCHECK(GetScaleForScaleFactor(handle->GetScaleFactor()) !=
247 resource_scale ||
248 !handle->HasResource(resource_id));
249 });
Nico 2015/05/02 00:50:48 nit: Writing this as for (const ResourceHandl
sadrul 2015/05/02 04:17:09 Heh, yeah. Totally. Done.
250 }
251 }
252 #endif // DCHECK_IS_ON()
253
234 // static 254 // static
235 bool DataPack::WritePack(const base::FilePath& path, 255 bool DataPack::WritePack(const base::FilePath& path,
236 const std::map<uint16, base::StringPiece>& resources, 256 const std::map<uint16, base::StringPiece>& resources,
237 TextEncodingType textEncodingType) { 257 TextEncodingType textEncodingType) {
238 FILE* file = base::OpenFile(path, "wb"); 258 FILE* file = base::OpenFile(path, "wb");
239 if (!file) 259 if (!file)
240 return false; 260 return false;
241 261
242 if (fwrite(&kFileFormatVersion, sizeof(kFileFormatVersion), 1, file) != 1) { 262 if (fwrite(&kFileFormatVersion, sizeof(kFileFormatVersion), 1, file) != 1) {
243 LOG(ERROR) << "Failed to write file version"; 263 LOG(ERROR) << "Failed to write file version";
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 return false; 336 return false;
317 } 337 }
318 } 338 }
319 339
320 base::CloseFile(file); 340 base::CloseFile(file);
321 341
322 return true; 342 return true;
323 } 343 }
324 344
325 } // namespace ui 345 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698