| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 UI_BASE_RESOURCE_DATA_PACK_H_ | 9 #ifndef UI_BASE_RESOURCE_DATA_PACK_H_ |
| 10 #define UI_BASE_RESOURCE_DATA_PACK_H_ | 10 #define UI_BASE_RESOURCE_DATA_PACK_H_ |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 } | 24 } |
| 25 | 25 |
| 26 namespace file_util { | 26 namespace file_util { |
| 27 class MemoryMappedFile; | 27 class MemoryMappedFile; |
| 28 } | 28 } |
| 29 | 29 |
| 30 namespace ui { | 30 namespace ui { |
| 31 | 31 |
| 32 class UI_EXPORT DataPack { | 32 class UI_EXPORT DataPack { |
| 33 public: | 33 public: |
| 34 // What type of encoding the text resources use. | |
| 35 enum TextEncodingType { | |
| 36 BINARY, | |
| 37 UTF8, | |
| 38 UTF16 | |
| 39 }; | |
| 40 | |
| 41 DataPack(); | 34 DataPack(); |
| 42 ~DataPack(); | 35 ~DataPack(); |
| 43 | 36 |
| 44 // Load a pack file from |path|, returning false on error. | 37 // Load a pack file from |path|, returning false on error. |
| 45 bool Load(const FilePath& path); | 38 bool Load(const FilePath& path); |
| 46 | 39 |
| 47 // Get resource by id |resource_id|, filling in |data|. | 40 // Get resource by id |resource_id|, filling in |data|. |
| 48 // The data is owned by the DataPack object and should not be modified. | 41 // The data is owned by the DataPack object and should not be modified. |
| 49 // Returns false if the resource id isn't found. | 42 // Returns false if the resource id isn't found. |
| 50 bool GetStringPiece(uint16 resource_id, base::StringPiece* data) const; | 43 bool GetStringPiece(uint16 resource_id, base::StringPiece* data) const; |
| 51 | 44 |
| 52 // Like GetStringPiece(), but returns a reference to memory. This interface | 45 // Like GetStringPiece(), but returns a reference to memory. This interface |
| 53 // is used for image data, while the StringPiece interface is usually used | 46 // is used for image data, while the StringPiece interface is usually used |
| 54 // for localization strings. | 47 // for localization strings. |
| 55 RefCountedStaticMemory* GetStaticMemory(uint16 resource_id) const; | 48 RefCountedStaticMemory* GetStaticMemory(uint16 resource_id) const; |
| 56 | 49 |
| 57 // Writes a pack file containing |resources| to |path|. If there are any | 50 // Writes a pack file containing |resources| to |path|. |
| 58 // text resources to be written, their encoding must already agree to the | |
| 59 // |textEncodingType| specified. If no text resources are present, please | |
| 60 // indicate BINARY. | |
| 61 static bool WritePack(const FilePath& path, | 51 static bool WritePack(const FilePath& path, |
| 62 const std::map<uint16, base::StringPiece>& resources, | 52 const std::map<uint16, base::StringPiece>& resources); |
| 63 TextEncodingType textEncodingType); | |
| 64 | |
| 65 // Get the encoding type of text resources. | |
| 66 TextEncodingType GetTextEncodingType() const { return text_encoding_type_; } | |
| 67 | 53 |
| 68 private: | 54 private: |
| 69 // The memory-mapped data. | 55 // The memory-mapped data. |
| 70 scoped_ptr<file_util::MemoryMappedFile> mmap_; | 56 scoped_ptr<file_util::MemoryMappedFile> mmap_; |
| 71 | 57 |
| 72 // Number of resources in the data. | 58 // Number of resources in the data. |
| 73 size_t resource_count_; | 59 size_t resource_count_; |
| 74 | 60 |
| 75 // Type of encoding for text resources. | |
| 76 TextEncodingType text_encoding_type_; | |
| 77 | |
| 78 DISALLOW_COPY_AND_ASSIGN(DataPack); | 61 DISALLOW_COPY_AND_ASSIGN(DataPack); |
| 79 }; | 62 }; |
| 80 | 63 |
| 81 } // namespace ui | 64 } // namespace ui |
| 82 | 65 |
| 83 #endif // UI_BASE_RESOURCE_DATA_PACK_H_ | 66 #endif // UI_BASE_RESOURCE_DATA_PACK_H_ |
| OLD | NEW |