| 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/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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 | 233 |
| 234 #if DCHECK_IS_ON() | 234 #if DCHECK_IS_ON() |
| 235 void DataPack::CheckForDuplicateResources( | 235 void DataPack::CheckForDuplicateResources( |
| 236 const ScopedVector<ResourceHandle>& packs) { | 236 const ScopedVector<ResourceHandle>& packs) { |
| 237 for (size_t i = 0; i < resource_count_ + 1; ++i) { | 237 for (size_t i = 0; i < resource_count_ + 1; ++i) { |
| 238 const DataPackEntry* entry = reinterpret_cast<const DataPackEntry*>( | 238 const DataPackEntry* entry = reinterpret_cast<const DataPackEntry*>( |
| 239 mmap_->data() + kHeaderLength + (i * sizeof(DataPackEntry))); | 239 mmap_->data() + kHeaderLength + (i * sizeof(DataPackEntry))); |
| 240 const uint16 resource_id = entry->resource_id; | 240 const uint16 resource_id = entry->resource_id; |
| 241 const float resource_scale = GetScaleForScaleFactor(scale_factor_); | 241 const float resource_scale = GetScaleForScaleFactor(scale_factor_); |
| 242 for (const ResourceHandle* handle : packs) { | 242 for (const ResourceHandle* handle : packs) { |
| 243 DCHECK_IMPLIES( | 243 DCHECK((GetScaleForScaleFactor(handle->GetScaleFactor()) != |
| 244 GetScaleForScaleFactor(handle->GetScaleFactor()) == resource_scale, | 244 resource_scale) || |
| 245 !handle->HasResource(resource_id)); | 245 !handle->HasResource(resource_id)); |
| 246 } | 246 } |
| 247 } | 247 } |
| 248 } | 248 } |
| 249 #endif // DCHECK_IS_ON() | 249 #endif // DCHECK_IS_ON() |
| 250 | 250 |
| 251 // static | 251 // static |
| 252 bool DataPack::WritePack(const base::FilePath& path, | 252 bool DataPack::WritePack(const base::FilePath& path, |
| 253 const std::map<uint16, base::StringPiece>& resources, | 253 const std::map<uint16, base::StringPiece>& resources, |
| 254 TextEncodingType textEncodingType) { | 254 TextEncodingType textEncodingType) { |
| 255 FILE* file = base::OpenFile(path, "wb"); | 255 FILE* file = base::OpenFile(path, "wb"); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 return false; | 333 return false; |
| 334 } | 334 } |
| 335 } | 335 } |
| 336 | 336 |
| 337 base::CloseFile(file); | 337 base::CloseFile(file); |
| 338 | 338 |
| 339 return true; | 339 return true; |
| 340 } | 340 } |
| 341 | 341 |
| 342 } // namespace ui | 342 } // namespace ui |
| OLD | NEW |