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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 // Load a pack file from |path|, returning false on error. | 43 // Load a pack file from |path|, returning false on error. |
44 bool LoadFromPath(const base::FilePath& path); | 44 bool LoadFromPath(const base::FilePath& path); |
45 | 45 |
46 // Loads a pack file from |file|, returning false on error. | 46 // Loads a pack file from |file|, returning false on error. |
47 bool LoadFromFile(base::File file); | 47 bool LoadFromFile(base::File file); |
48 | 48 |
49 // Loads a pack file from |region| of |file|, returning false on error. | 49 // Loads a pack file from |region| of |file|, returning false on error. |
50 bool LoadFromFileRegion(base::File file, | 50 bool LoadFromFileRegion(base::File file, |
51 const base::MemoryMappedFile::Region& region); | 51 const base::MemoryMappedFile::Region& region); |
52 | 52 |
53 // Loads a pack file from |buffer|, returning false on error. | |
54 bool LoadFromBuffer(base::StringPiece buffer); | |
alex clarke (OOO till 29th)
2016/05/12 17:31:04
bikeshed: Should this be InitializeFromBuffer? Sa
altimin
2016/05/12 18:07:53
I don't think so — we already have LoadFromPath, L
| |
55 | |
53 // Writes a pack file containing |resources| to |path|. If there are any | 56 // 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 | 57 // text resources to be written, their encoding must already agree to the |
55 // |textEncodingType| specified. If no text resources are present, please | 58 // |textEncodingType| specified. If no text resources are present, please |
56 // indicate BINARY. | 59 // indicate BINARY. |
57 static bool WritePack(const base::FilePath& path, | 60 static bool WritePack(const base::FilePath& path, |
58 const std::map<uint16_t, base::StringPiece>& resources, | 61 const std::map<uint16_t, base::StringPiece>& resources, |
59 TextEncodingType textEncodingType); | 62 TextEncodingType textEncodingType); |
60 | 63 |
61 // ResourceHandle implementation: | 64 // ResourceHandle implementation: |
62 bool HasResource(uint16_t resource_id) const override; | 65 bool HasResource(uint16_t resource_id) const override; |
63 bool GetStringPiece(uint16_t resource_id, | 66 bool GetStringPiece(uint16_t resource_id, |
64 base::StringPiece* data) const override; | 67 base::StringPiece* data) const override; |
65 base::RefCountedStaticMemory* GetStaticMemory( | 68 base::RefCountedStaticMemory* GetStaticMemory( |
66 uint16_t resource_id) const override; | 69 uint16_t resource_id) const override; |
67 TextEncodingType GetTextEncodingType() const override; | 70 TextEncodingType GetTextEncodingType() const override; |
68 ui::ScaleFactor GetScaleFactor() const override; | 71 ui::ScaleFactor GetScaleFactor() const override; |
69 bool HasOnlyMaterialDesignAssets() const override; | 72 bool HasOnlyMaterialDesignAssets() const override; |
70 | 73 |
71 #if DCHECK_IS_ON() | 74 #if DCHECK_IS_ON() |
72 // Checks to see if any resource in this DataPack already exists in the list | 75 // Checks to see if any resource in this DataPack already exists in the list |
73 // of resources. | 76 // of resources. |
74 void CheckForDuplicateResources(const ScopedVector<ResourceHandle>& packs); | 77 void CheckForDuplicateResources(const ScopedVector<ResourceHandle>& packs); |
75 #endif | 78 #endif |
76 | 79 |
77 private: | 80 private: |
78 // Does the actual loading of a pack file. Called by Load and LoadFromFile. | 81 // Does the actual loading of a pack file. |
82 // Called by Load and LoadFromFile and LoadFromBuffer. | |
79 bool LoadImpl(); | 83 bool LoadImpl(); |
80 | 84 |
85 void Clear(); | |
86 | |
81 // The memory-mapped data. | 87 // The memory-mapped data. |
alex clarke (OOO till 29th)
2016/05/12 17:31:04
// The memory-mapped data. Might be null if initi
altimin
2016/05/12 18:07:53
Acknowledged.
| |
82 std::unique_ptr<base::MemoryMappedFile> mmap_; | 88 std::unique_ptr<base::MemoryMappedFile> mmap_; |
alex clarke (OOO till 29th)
2016/05/12 17:31:04
Not sure if this is overkill, but I would be tempt
altimin
2016/05/12 18:07:53
I thought about this and decided that's an overkil
| |
89 size_t length_; | |
90 const uint8_t* data_; | |
83 | 91 |
84 // Number of resources in the data. | 92 // Number of resources in the data. |
85 size_t resource_count_; | 93 size_t resource_count_; |
86 | 94 |
87 // Type of encoding for text resources. | 95 // Type of encoding for text resources. |
88 TextEncodingType text_encoding_type_; | 96 TextEncodingType text_encoding_type_; |
89 | 97 |
90 // The scale of the image in this resource pack relative to images in the 1x | 98 // The scale of the image in this resource pack relative to images in the 1x |
91 // resource pak. | 99 // resource pak. |
92 ui::ScaleFactor scale_factor_; | 100 ui::ScaleFactor scale_factor_; |
93 | 101 |
94 // Set to true if the only resources contained within this DataPack are | 102 // Set to true if the only resources contained within this DataPack are |
95 // material design image assets. | 103 // material design image assets. |
96 bool has_only_material_design_assets_; | 104 bool has_only_material_design_assets_; |
97 | 105 |
98 DISALLOW_COPY_AND_ASSIGN(DataPack); | 106 DISALLOW_COPY_AND_ASSIGN(DataPack); |
99 }; | 107 }; |
100 | 108 |
101 } // namespace ui | 109 } // namespace ui |
102 | 110 |
103 #endif // UI_BASE_RESOURCE_DATA_PACK_H_ | 111 #endif // UI_BASE_RESOURCE_DATA_PACK_H_ |
OLD | NEW |