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/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/memory_mapped_file.h" | 10 #include "base/files/memory_mapped_file.h" |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 const DataPackEntry* target = reinterpret_cast<const DataPackEntry*>( | 183 const DataPackEntry* target = reinterpret_cast<const DataPackEntry*>( |
184 bsearch(&resource_id, mmap_->data() + kHeaderLength, resource_count_, | 184 bsearch(&resource_id, mmap_->data() + kHeaderLength, resource_count_, |
185 sizeof(DataPackEntry), DataPackEntry::CompareById)); | 185 sizeof(DataPackEntry), DataPackEntry::CompareById)); |
186 if (!target) { | 186 if (!target) { |
187 return false; | 187 return false; |
188 } | 188 } |
189 | 189 |
190 const DataPackEntry* next_entry = target + 1; | 190 const DataPackEntry* next_entry = target + 1; |
191 size_t length = next_entry->file_offset - target->file_offset; | 191 size_t length = next_entry->file_offset - target->file_offset; |
192 | 192 |
193 data->set(reinterpret_cast<const char*>(mmap_->data() + target->file_offset), | 193 data->set(mmap_->data() + target->file_offset, length); |
194 length); | |
195 return true; | 194 return true; |
196 } | 195 } |
197 | 196 |
198 base::RefCountedStaticMemory* DataPack::GetStaticMemory( | 197 base::RefCountedStaticMemory* DataPack::GetStaticMemory( |
199 uint16 resource_id) const { | 198 uint16 resource_id) const { |
200 base::StringPiece piece; | 199 base::StringPiece piece; |
201 if (!GetStringPiece(resource_id, &piece)) | 200 if (!GetStringPiece(resource_id, &piece)) |
202 return NULL; | 201 return NULL; |
203 | 202 |
204 return new base::RefCountedStaticMemory(piece.data(), piece.length()); | 203 return new base::RefCountedStaticMemory(piece.data(), piece.length()); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 return false; | 296 return false; |
298 } | 297 } |
299 } | 298 } |
300 | 299 |
301 base::CloseFile(file); | 300 base::CloseFile(file); |
302 | 301 |
303 return true; | 302 return true; |
304 } | 303 } |
305 | 304 |
306 } // namespace ui | 305 } // namespace ui |
OLD | NEW |