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 24 matching lines...) Expand all Loading... |
35 return -1; | 35 return -1; |
36 } else if (key > entry->resource_id) { | 36 } else if (key > entry->resource_id) { |
37 return 1; | 37 return 1; |
38 } else { | 38 } else { |
39 return 0; | 39 return 0; |
40 } | 40 } |
41 } | 41 } |
42 }; | 42 }; |
43 #pragma pack(pop) | 43 #pragma pack(pop) |
44 | 44 |
45 COMPILE_ASSERT(sizeof(DataPackEntry) == 6, size_of_entry_must_be_six); | 45 static_assert(sizeof(DataPackEntry) == 6, "size of entry must be six"); |
46 | 46 |
47 // We're crashing when trying to load a pak file on Windows. Add some error | 47 // We're crashing when trying to load a pak file on Windows. Add some error |
48 // codes for logging. | 48 // codes for logging. |
49 // http://crbug.com/58056 | 49 // http://crbug.com/58056 |
50 enum LoadErrors { | 50 enum LoadErrors { |
51 INIT_FAILED = 1, | 51 INIT_FAILED = 1, |
52 BAD_VERSION, | 52 BAD_VERSION, |
53 INDEX_TRUNCATED, | 53 INDEX_TRUNCATED, |
54 ENTRY_NOT_FOUND, | 54 ENTRY_NOT_FOUND, |
55 HEADER_TRUNCATED, | 55 HEADER_TRUNCATED, |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 return !!bsearch(&resource_id, mmap_->data() + kHeaderLength, resource_count_, | 174 return !!bsearch(&resource_id, mmap_->data() + kHeaderLength, resource_count_, |
175 sizeof(DataPackEntry), DataPackEntry::CompareById); | 175 sizeof(DataPackEntry), DataPackEntry::CompareById); |
176 } | 176 } |
177 | 177 |
178 bool DataPack::GetStringPiece(uint16 resource_id, | 178 bool DataPack::GetStringPiece(uint16 resource_id, |
179 base::StringPiece* data) const { | 179 base::StringPiece* data) const { |
180 // It won't be hard to make this endian-agnostic, but it's not worth | 180 // It won't be hard to make this endian-agnostic, but it's not worth |
181 // bothering to do right now. | 181 // bothering to do right now. |
182 #if defined(__BYTE_ORDER) | 182 #if defined(__BYTE_ORDER) |
183 // Linux check | 183 // Linux check |
184 COMPILE_ASSERT(__BYTE_ORDER == __LITTLE_ENDIAN, | 184 static_assert(__BYTE_ORDER == __LITTLE_ENDIAN, |
185 datapack_assumes_little_endian); | 185 "datapack assumes little endian"); |
186 #elif defined(__BIG_ENDIAN__) | 186 #elif defined(__BIG_ENDIAN__) |
187 // Mac check | 187 // Mac check |
188 #error DataPack assumes little endian | 188 #error DataPack assumes little endian |
189 #endif | 189 #endif |
190 | 190 |
191 const DataPackEntry* target = reinterpret_cast<const DataPackEntry*>( | 191 const DataPackEntry* target = reinterpret_cast<const DataPackEntry*>( |
192 bsearch(&resource_id, mmap_->data() + kHeaderLength, resource_count_, | 192 bsearch(&resource_id, mmap_->data() + kHeaderLength, resource_count_, |
193 sizeof(DataPackEntry), DataPackEntry::CompareById)); | 193 sizeof(DataPackEntry), DataPackEntry::CompareById)); |
194 if (!target) { | 194 if (!target) { |
195 return false; | 195 return false; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 return false; | 316 return false; |
317 } | 317 } |
318 } | 318 } |
319 | 319 |
320 base::CloseFile(file); | 320 base::CloseFile(file); |
321 | 321 |
322 return true; | 322 return true; |
323 } | 323 } |
324 | 324 |
325 } // namespace ui | 325 } // namespace ui |
OLD | NEW |