| 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 // DataPack represents a read-only view onto an on-disk file that contains | 5 // DataPack represents a read-only view onto an on-disk file that contains |
| 6 // (key, value) pairs of data. It's used to store static resources like | 6 // (key, value) pairs of data. It's used to store static resources like |
| 7 // translation strings and images. | 7 // translation strings and images. |
| 8 | 8 |
| 9 #ifndef BASE_DATA_PACK_H_ | 9 #ifndef BASE_DATA_PACK_H_ |
| 10 #define BASE_DATA_PACK_H_ | 10 #define BASE_DATA_PACK_H_ |
| 11 | 11 |
| 12 #include <map> |
| 13 |
| 12 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 13 #include "base/ref_counted_memory.h" | 15 #include "base/ref_counted_memory.h" |
| 14 #include "base/scoped_ptr.h" | 16 #include "base/scoped_ptr.h" |
| 15 | 17 |
| 16 namespace file_util { | 18 namespace file_util { |
| 17 class MemoryMappedFile; | 19 class MemoryMappedFile; |
| 18 } | 20 } |
| 19 class FilePath; | 21 class FilePath; |
| 20 | 22 |
| 21 namespace base { | 23 namespace base { |
| 22 | 24 |
| 23 class StringPiece; | 25 class StringPiece; |
| 24 | 26 |
| 25 class DataPack { | 27 class DataPack { |
| 26 public: | 28 public: |
| 27 DataPack(); | 29 DataPack(); |
| 28 ~DataPack(); | 30 ~DataPack(); |
| 29 | 31 |
| 30 // Load a pack file from |path|, returning false on error. | 32 // Load a pack file from |path|, returning false on error. |
| 31 bool Load(const FilePath& path); | 33 bool Load(const FilePath& path); |
| 32 | 34 |
| 33 // Get resource by id |resource_id|, filling in |data|. | 35 // Get resource by id |resource_id|, filling in |data|. |
| 34 // The data is owned by the DataPack object and should not be modified. | 36 // The data is owned by the DataPack object and should not be modified. |
| 35 // Returns false if the resource id isn't found. | 37 // Returns false if the resource id isn't found. |
| 36 bool GetStringPiece(uint32_t resource_id, StringPiece* data); | 38 bool GetStringPiece(uint32 resource_id, StringPiece* data); |
| 37 | 39 |
| 38 // Like GetStringPiece(), but returns a reference to memory. This interface | 40 // Like GetStringPiece(), but returns a reference to memory. This interface |
| 39 // is used for image data, while the StringPiece interface is usually used | 41 // is used for image data, while the StringPiece interface is usually used |
| 40 // for localization strings. | 42 // for localization strings. |
| 41 RefCountedStaticMemory* GetStaticMemory(uint32_t resource_id); | 43 RefCountedStaticMemory* GetStaticMemory(uint32 resource_id); |
| 44 |
| 45 // Writes a pack file containing |resources| to |path|. |
| 46 static bool WritePack(const FilePath& path, |
| 47 const std::map<uint32, StringPiece>& resources); |
| 42 | 48 |
| 43 private: | 49 private: |
| 44 // The memory-mapped data. | 50 // The memory-mapped data. |
| 45 scoped_ptr<file_util::MemoryMappedFile> mmap_; | 51 scoped_ptr<file_util::MemoryMappedFile> mmap_; |
| 46 | 52 |
| 47 // Number of resources in the data. | 53 // Number of resources in the data. |
| 48 size_t resource_count_; | 54 size_t resource_count_; |
| 49 | 55 |
| 50 DISALLOW_COPY_AND_ASSIGN(DataPack); | 56 DISALLOW_COPY_AND_ASSIGN(DataPack); |
| 51 }; | 57 }; |
| 52 | 58 |
| 53 } // namespace base | 59 } // namespace base |
| 54 | 60 |
| 55 #endif // BASE_DATA_PACK_H_ | 61 #endif // BASE_DATA_PACK_H_ |
| OLD | NEW |