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

Unified 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, 8 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 side-by-side diff with in-line comments
Download patch
Index: ui/base/resource/data_pack.cc
diff --git a/ui/base/resource/data_pack.cc b/ui/base/resource/data_pack.cc
index f9fe9b8469eeb35d3369a4c32cb09ace5ba48b0f..ad3bcfec030c5a0882c597378de4eb09f1441ad0 100644
--- a/ui/base/resource/data_pack.cc
+++ b/ui/base/resource/data_pack.cc
@@ -6,6 +6,8 @@
#include <errno.h>
+#include <algorithm>
+
#include "base/files/file_util.h"
#include "base/files/memory_mapped_file.h"
#include "base/logging.h"
@@ -231,6 +233,24 @@ ui::ScaleFactor DataPack::GetScaleFactor() const {
return scale_factor_;
}
+#if DCHECK_IS_ON()
+void DataPack::CheckForDuplicateResources(
+ const ScopedVector<ResourceHandle>& packs) {
+ 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()
+ const DataPackEntry* entry = reinterpret_cast<const DataPackEntry*>(
+ mmap_->data() + kHeaderLength + (i * sizeof(DataPackEntry)));
+ const uint16 resource_id = entry->resource_id;
+ const float resource_scale = GetScaleForScaleFactor(scale_factor_);
+ std::for_each(packs.begin(), packs.end(),
+ [resource_id, resource_scale](const ResourceHandle* handle) {
+ DCHECK(GetScaleForScaleFactor(handle->GetScaleFactor()) !=
+ resource_scale ||
+ !handle->HasResource(resource_id));
+ });
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.
+ }
+}
+#endif // DCHECK_IS_ON()
+
// static
bool DataPack::WritePack(const base::FilePath& path,
const std::map<uint16, base::StringPiece>& resources,

Powered by Google App Engine
This is Rietveld 408576698