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