| 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_ |
| 11 | 11 |
| 12 #include <map> | 12 #include <map> |
| 13 | 13 |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/platform_file.h" | 16 #include "base/platform_file.h" |
| 17 #include "base/string_piece.h" | 17 #include "base/string_piece.h" |
| 18 #include "ui/base/layout.h" | 18 #include "ui/base/layout.h" |
| 19 #include "ui/base/resource/resource_handle.h" | 19 #include "ui/base/resource/resource_handle.h" |
| 20 #include "ui/base/ui_export.h" | 20 #include "ui/base/ui_export.h" |
| 21 | 21 |
| 22 namespace base { | 22 namespace base { |
| 23 class FilePath; | 23 class FilePath; |
| 24 class MemoryMappedFile; |
| 24 class RefCountedStaticMemory; | 25 class RefCountedStaticMemory; |
| 25 } | 26 } |
| 26 | 27 |
| 27 namespace file_util { | |
| 28 class MemoryMappedFile; | |
| 29 } | |
| 30 | |
| 31 namespace ui { | 28 namespace ui { |
| 32 | 29 |
| 33 class UI_EXPORT DataPack : public ResourceHandle { | 30 class UI_EXPORT DataPack : public ResourceHandle { |
| 34 public: | 31 public: |
| 35 DataPack(ui::ScaleFactor scale_factor); | 32 DataPack(ui::ScaleFactor scale_factor); |
| 36 virtual ~DataPack(); | 33 virtual ~DataPack(); |
| 37 | 34 |
| 38 // Load a pack file from |path|, returning false on error. | 35 // Load a pack file from |path|, returning false on error. |
| 39 bool LoadFromPath(const base::FilePath& path); | 36 bool LoadFromPath(const base::FilePath& path); |
| 40 | 37 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 56 virtual base::RefCountedStaticMemory* GetStaticMemory( | 53 virtual base::RefCountedStaticMemory* GetStaticMemory( |
| 57 uint16 resource_id) const OVERRIDE; | 54 uint16 resource_id) const OVERRIDE; |
| 58 virtual TextEncodingType GetTextEncodingType() const OVERRIDE; | 55 virtual TextEncodingType GetTextEncodingType() const OVERRIDE; |
| 59 virtual ui::ScaleFactor GetScaleFactor() const OVERRIDE; | 56 virtual ui::ScaleFactor GetScaleFactor() const OVERRIDE; |
| 60 | 57 |
| 61 private: | 58 private: |
| 62 // Does the actual loading of a pack file. Called by Load and LoadFromFile. | 59 // Does the actual loading of a pack file. Called by Load and LoadFromFile. |
| 63 bool LoadImpl(); | 60 bool LoadImpl(); |
| 64 | 61 |
| 65 // The memory-mapped data. | 62 // The memory-mapped data. |
| 66 scoped_ptr<file_util::MemoryMappedFile> mmap_; | 63 scoped_ptr<base::MemoryMappedFile> mmap_; |
| 67 | 64 |
| 68 // Number of resources in the data. | 65 // Number of resources in the data. |
| 69 size_t resource_count_; | 66 size_t resource_count_; |
| 70 | 67 |
| 71 // Type of encoding for text resources. | 68 // Type of encoding for text resources. |
| 72 TextEncodingType text_encoding_type_; | 69 TextEncodingType text_encoding_type_; |
| 73 | 70 |
| 74 // The scale of the image in this resource pack relative to images in the 1x | 71 // The scale of the image in this resource pack relative to images in the 1x |
| 75 // resource pak. | 72 // resource pak. |
| 76 ui::ScaleFactor scale_factor_; | 73 ui::ScaleFactor scale_factor_; |
| 77 | 74 |
| 78 DISALLOW_COPY_AND_ASSIGN(DataPack); | 75 DISALLOW_COPY_AND_ASSIGN(DataPack); |
| 79 }; | 76 }; |
| 80 | 77 |
| 81 } // namespace ui | 78 } // namespace ui |
| 82 | 79 |
| 83 #endif // UI_BASE_RESOURCE_DATA_PACK_H_ | 80 #endif // UI_BASE_RESOURCE_DATA_PACK_H_ |
| OLD | NEW |