| 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 // 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 14 matching lines...) Expand all Loading... |
| 25 } | 25 } |
| 26 | 26 |
| 27 namespace file_util { | 27 namespace file_util { |
| 28 class MemoryMappedFile; | 28 class MemoryMappedFile; |
| 29 } | 29 } |
| 30 | 30 |
| 31 namespace ui { | 31 namespace ui { |
| 32 | 32 |
| 33 class UI_EXPORT DataPack : public ResourceHandle { | 33 class UI_EXPORT DataPack : public ResourceHandle { |
| 34 public: | 34 public: |
| 35 DataPack(); | 35 DataPack(float scale_factor); |
| 36 virtual ~DataPack(); | 36 virtual ~DataPack(); |
| 37 | 37 |
| 38 // Load a pack file from |path|, returning false on error. | 38 // Load a pack file from |path|, returning false on error. |
| 39 bool Load(const FilePath& path); | 39 bool Load(const FilePath& path); |
| 40 | 40 |
| 41 // Writes a pack file containing |resources| to |path|. If there are any | 41 // Writes a pack file containing |resources| to |path|. If there are any |
| 42 // text resources to be written, their encoding must already agree to the | 42 // text resources to be written, their encoding must already agree to the |
| 43 // |textEncodingType| specified. If no text resources are present, please | 43 // |textEncodingType| specified. If no text resources are present, please |
| 44 // indicate BINARY. | 44 // indicate BINARY. |
| 45 static bool WritePack(const FilePath& path, | 45 static bool WritePack(const FilePath& path, |
| 46 const std::map<uint16, base::StringPiece>& resources, | 46 const std::map<uint16, base::StringPiece>& resources, |
| 47 TextEncodingType textEncodingType); | 47 TextEncodingType textEncodingType); |
| 48 | 48 |
| 49 // ResourceHandle implementation: | 49 // ResourceHandle implementation: |
| 50 virtual bool GetStringPiece(uint16 resource_id, | 50 virtual bool GetStringPiece(uint16 resource_id, |
| 51 base::StringPiece* data) const OVERRIDE; | 51 base::StringPiece* data) const OVERRIDE; |
| 52 virtual base::RefCountedStaticMemory* GetStaticMemory( | 52 virtual base::RefCountedStaticMemory* GetStaticMemory( |
| 53 uint16 resource_id) const OVERRIDE; | 53 uint16 resource_id) const OVERRIDE; |
| 54 virtual TextEncodingType GetTextEncodingType() const OVERRIDE; | 54 virtual TextEncodingType GetTextEncodingType() const OVERRIDE; |
| 55 virtual float GetScaleFactor() const OVERRIDE; |
| 55 | 56 |
| 56 private: | 57 private: |
| 57 // The memory-mapped data. | 58 // The memory-mapped data. |
| 58 scoped_ptr<file_util::MemoryMappedFile> mmap_; | 59 scoped_ptr<file_util::MemoryMappedFile> mmap_; |
| 59 | 60 |
| 60 // Number of resources in the data. | 61 // Number of resources in the data. |
| 61 size_t resource_count_; | 62 size_t resource_count_; |
| 62 | 63 |
| 63 // Type of encoding for text resources. | 64 // Type of encoding for text resources. |
| 64 TextEncodingType text_encoding_type_; | 65 TextEncodingType text_encoding_type_; |
| 65 | 66 |
| 67 // The scale of the image in this resource pack relative to images in the 1x |
| 68 // resource pak. |
| 69 float scale_factor_; |
| 70 |
| 66 DISALLOW_COPY_AND_ASSIGN(DataPack); | 71 DISALLOW_COPY_AND_ASSIGN(DataPack); |
| 67 }; | 72 }; |
| 68 | 73 |
| 69 } // namespace ui | 74 } // namespace ui |
| 70 | 75 |
| 71 #endif // UI_BASE_RESOURCE_DATA_PACK_H_ | 76 #endif // UI_BASE_RESOURCE_DATA_PACK_H_ |
| OLD | NEW |