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