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 18 matching lines...) Expand all Loading... |
29 } | 29 } |
30 | 30 |
31 namespace ui { | 31 namespace ui { |
32 enum ScaleFactor : int; | 32 enum ScaleFactor : int; |
33 | 33 |
34 class UI_DATA_PACK_EXPORT DataPack : public ResourceHandle { | 34 class UI_DATA_PACK_EXPORT DataPack : public ResourceHandle { |
35 public: | 35 public: |
36 explicit DataPack(ui::ScaleFactor scale_factor); | 36 explicit DataPack(ui::ScaleFactor scale_factor); |
37 ~DataPack() override; | 37 ~DataPack() override; |
38 | 38 |
39 void set_has_only_material_design_assets(bool has_only_material_assets) { | |
40 has_only_material_design_assets_ = has_only_material_assets; | |
41 } | |
42 | |
43 // Load a pack file from |path|, returning false on error. | 39 // Load a pack file from |path|, returning false on error. |
44 bool LoadFromPath(const base::FilePath& path); | 40 bool LoadFromPath(const base::FilePath& path); |
45 | 41 |
46 // Loads a pack file from |file|, returning false on error. | 42 // Loads a pack file from |file|, returning false on error. |
47 bool LoadFromFile(base::File file); | 43 bool LoadFromFile(base::File file); |
48 | 44 |
49 // Loads a pack file from |region| of |file|, returning false on error. | 45 // Loads a pack file from |region| of |file|, returning false on error. |
50 bool LoadFromFileRegion(base::File file, | 46 bool LoadFromFileRegion(base::File file, |
51 const base::MemoryMappedFile::Region& region); | 47 const base::MemoryMappedFile::Region& region); |
52 | 48 |
53 // Writes a pack file containing |resources| to |path|. If there are any | 49 // Writes a pack file containing |resources| to |path|. If there are any |
54 // text resources to be written, their encoding must already agree to the | 50 // text resources to be written, their encoding must already agree to the |
55 // |textEncodingType| specified. If no text resources are present, please | 51 // |textEncodingType| specified. If no text resources are present, please |
56 // indicate BINARY. | 52 // indicate BINARY. |
57 static bool WritePack(const base::FilePath& path, | 53 static bool WritePack(const base::FilePath& path, |
58 const std::map<uint16_t, base::StringPiece>& resources, | 54 const std::map<uint16_t, base::StringPiece>& resources, |
59 TextEncodingType textEncodingType); | 55 TextEncodingType textEncodingType); |
60 | 56 |
61 // ResourceHandle implementation: | 57 // ResourceHandle implementation: |
62 bool HasResource(uint16_t resource_id) const override; | 58 bool HasResource(uint16_t resource_id) const override; |
63 bool GetStringPiece(uint16_t resource_id, | 59 bool GetStringPiece(uint16_t resource_id, |
64 base::StringPiece* data) const override; | 60 base::StringPiece* data) const override; |
65 base::RefCountedStaticMemory* GetStaticMemory( | 61 base::RefCountedStaticMemory* GetStaticMemory( |
66 uint16_t resource_id) const override; | 62 uint16_t resource_id) const override; |
67 TextEncodingType GetTextEncodingType() const override; | 63 TextEncodingType GetTextEncodingType() const override; |
68 ui::ScaleFactor GetScaleFactor() const override; | 64 ui::ScaleFactor GetScaleFactor() const override; |
69 bool HasOnlyMaterialDesignAssets() const override; | |
70 | 65 |
71 #if DCHECK_IS_ON() | 66 #if DCHECK_IS_ON() |
72 // Checks to see if any resource in this DataPack already exists in the list | 67 // Checks to see if any resource in this DataPack already exists in the list |
73 // of resources. | 68 // of resources. |
74 void CheckForDuplicateResources(const ScopedVector<ResourceHandle>& packs); | 69 void CheckForDuplicateResources(const ScopedVector<ResourceHandle>& packs); |
75 #endif | 70 #endif |
76 | 71 |
77 private: | 72 private: |
78 // Does the actual loading of a pack file. Called by Load and LoadFromFile. | 73 // Does the actual loading of a pack file. Called by Load and LoadFromFile. |
79 bool LoadImpl(); | 74 bool LoadImpl(); |
80 | 75 |
81 // The memory-mapped data. | 76 // The memory-mapped data. |
82 std::unique_ptr<base::MemoryMappedFile> mmap_; | 77 std::unique_ptr<base::MemoryMappedFile> mmap_; |
83 | 78 |
84 // Number of resources in the data. | 79 // Number of resources in the data. |
85 size_t resource_count_; | 80 size_t resource_count_; |
86 | 81 |
87 // Type of encoding for text resources. | 82 // Type of encoding for text resources. |
88 TextEncodingType text_encoding_type_; | 83 TextEncodingType text_encoding_type_; |
89 | 84 |
90 // The scale of the image in this resource pack relative to images in the 1x | 85 // The scale of the image in this resource pack relative to images in the 1x |
91 // resource pak. | 86 // resource pak. |
92 ui::ScaleFactor scale_factor_; | 87 ui::ScaleFactor scale_factor_; |
93 | 88 |
94 // Set to true if the only resources contained within this DataPack are | |
95 // material design image assets. | |
96 bool has_only_material_design_assets_; | |
97 | |
98 DISALLOW_COPY_AND_ASSIGN(DataPack); | 89 DISALLOW_COPY_AND_ASSIGN(DataPack); |
99 }; | 90 }; |
100 | 91 |
101 } // namespace ui | 92 } // namespace ui |
102 | 93 |
103 #endif // UI_BASE_RESOURCE_DATA_PACK_H_ | 94 #endif // UI_BASE_RESOURCE_DATA_PACK_H_ |
OLD | NEW |