| OLD | NEW |
| 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 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 "base/data_pack.h" | 5 #include "base/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/logging.h" | 10 #include "base/logging.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 LOG(ERROR) << "Entry #" << i << " in data pack points off end of file. " | 89 LOG(ERROR) << "Entry #" << i << " in data pack points off end of file. " |
| 90 << "Was the file corrupted?"; | 90 << "Was the file corrupted?"; |
| 91 mmap_.reset(); | 91 mmap_.reset(); |
| 92 return false; | 92 return false; |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 | 95 |
| 96 return true; | 96 return true; |
| 97 } | 97 } |
| 98 | 98 |
| 99 bool DataPack::GetStringPiece(uint32 resource_id, StringPiece* data) const { | 99 bool DataPack::GetStringPiece(uint32 resource_id, StringPiece* data) { |
| 100 // It won't be hard to make this endian-agnostic, but it's not worth | 100 // It won't be hard to make this endian-agnostic, but it's not worth |
| 101 // bothering to do right now. | 101 // bothering to do right now. |
| 102 #if defined(__BYTE_ORDER) | 102 #if defined(__BYTE_ORDER) |
| 103 // Linux check | 103 // Linux check |
| 104 COMPILE_ASSERT(__BYTE_ORDER == __LITTLE_ENDIAN, | 104 COMPILE_ASSERT(__BYTE_ORDER == __LITTLE_ENDIAN, |
| 105 datapack_assumes_little_endian); | 105 datapack_assumes_little_endian); |
| 106 #elif defined(__BIG_ENDIAN__) | 106 #elif defined(__BIG_ENDIAN__) |
| 107 // Mac check | 107 // Mac check |
| 108 #error DataPack assumes little endian | 108 #error DataPack assumes little endian |
| 109 #endif | 109 #endif |
| 110 | 110 |
| 111 DataPackEntry* target = reinterpret_cast<DataPackEntry*>( | 111 DataPackEntry* target = reinterpret_cast<DataPackEntry*>( |
| 112 bsearch(&resource_id, mmap_->data() + kHeaderLength, resource_count_, | 112 bsearch(&resource_id, mmap_->data() + kHeaderLength, resource_count_, |
| 113 sizeof(DataPackEntry), DataPackEntry::CompareById)); | 113 sizeof(DataPackEntry), DataPackEntry::CompareById)); |
| 114 if (!target) { | 114 if (!target) { |
| 115 return false; | 115 return false; |
| 116 } | 116 } |
| 117 | 117 |
| 118 data->set(mmap_->data() + target->file_offset, target->length); | 118 data->set(mmap_->data() + target->file_offset, target->length); |
| 119 return true; | 119 return true; |
| 120 } | 120 } |
| 121 | 121 |
| 122 RefCountedStaticMemory* DataPack::GetStaticMemory(uint32 resource_id) const { | 122 RefCountedStaticMemory* DataPack::GetStaticMemory(uint32 resource_id) { |
| 123 base::StringPiece piece; | 123 base::StringPiece piece; |
| 124 if (!GetStringPiece(resource_id, &piece)) | 124 if (!GetStringPiece(resource_id, &piece)) |
| 125 return NULL; | 125 return NULL; |
| 126 | 126 |
| 127 return new RefCountedStaticMemory( | 127 return new RefCountedStaticMemory( |
| 128 reinterpret_cast<const unsigned char*>(piece.data()), piece.length()); | 128 reinterpret_cast<const unsigned char*>(piece.data()), piece.length()); |
| 129 } | 129 } |
| 130 | 130 |
| 131 // static | 131 // static |
| 132 bool DataPack::WritePack(const FilePath& path, | 132 bool DataPack::WritePack(const FilePath& path, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 return false; | 185 return false; |
| 186 } | 186 } |
| 187 } | 187 } |
| 188 | 188 |
| 189 file_util::CloseFile(file); | 189 file_util::CloseFile(file); |
| 190 | 190 |
| 191 return true; | 191 return true; |
| 192 } | 192 } |
| 193 | 193 |
| 194 } // namespace base | 194 } // namespace base |
| OLD | NEW |