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/files/file.h" | 15 #include "base/files/file.h" |
16 #include "base/files/memory_mapped_file.h" | 16 #include "base/files/memory_mapped_file.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/memory/scoped_vector.h" |
18 #include "base/strings/string_piece.h" | 19 #include "base/strings/string_piece.h" |
19 #include "ui/base/resource/resource_handle.h" | 20 #include "ui/base/resource/resource_handle.h" |
20 #include "ui/base/ui_base_export.h" | 21 #include "ui/base/ui_base_export.h" |
21 | 22 |
22 namespace base { | 23 namespace base { |
23 class FilePath; | 24 class FilePath; |
24 class RefCountedStaticMemory; | 25 class RefCountedStaticMemory; |
25 } | 26 } |
26 | 27 |
27 namespace ui { | 28 namespace ui { |
(...skipping 24 matching lines...) Expand all Loading... |
52 | 53 |
53 // ResourceHandle implementation: | 54 // ResourceHandle implementation: |
54 bool HasResource(uint16 resource_id) const override; | 55 bool HasResource(uint16 resource_id) const override; |
55 bool GetStringPiece(uint16 resource_id, | 56 bool GetStringPiece(uint16 resource_id, |
56 base::StringPiece* data) const override; | 57 base::StringPiece* data) const override; |
57 base::RefCountedStaticMemory* GetStaticMemory( | 58 base::RefCountedStaticMemory* GetStaticMemory( |
58 uint16 resource_id) const override; | 59 uint16 resource_id) const override; |
59 TextEncodingType GetTextEncodingType() const override; | 60 TextEncodingType GetTextEncodingType() const override; |
60 ui::ScaleFactor GetScaleFactor() const override; | 61 ui::ScaleFactor GetScaleFactor() const override; |
61 | 62 |
| 63 #if DCHECK_IS_ON() |
| 64 // Checks to see if any resource in this DataPack already exists in the list |
| 65 // of resources. |
| 66 void CheckForDuplicateResources(const ScopedVector<ResourceHandle>& packs); |
| 67 #endif |
| 68 |
62 private: | 69 private: |
63 // Does the actual loading of a pack file. Called by Load and LoadFromFile. | 70 // Does the actual loading of a pack file. Called by Load and LoadFromFile. |
64 bool LoadImpl(); | 71 bool LoadImpl(); |
65 | 72 |
66 // The memory-mapped data. | 73 // The memory-mapped data. |
67 scoped_ptr<base::MemoryMappedFile> mmap_; | 74 scoped_ptr<base::MemoryMappedFile> mmap_; |
68 | 75 |
69 // Number of resources in the data. | 76 // Number of resources in the data. |
70 size_t resource_count_; | 77 size_t resource_count_; |
71 | 78 |
72 // Type of encoding for text resources. | 79 // Type of encoding for text resources. |
73 TextEncodingType text_encoding_type_; | 80 TextEncodingType text_encoding_type_; |
74 | 81 |
75 // The scale of the image in this resource pack relative to images in the 1x | 82 // The scale of the image in this resource pack relative to images in the 1x |
76 // resource pak. | 83 // resource pak. |
77 ui::ScaleFactor scale_factor_; | 84 ui::ScaleFactor scale_factor_; |
78 | 85 |
79 DISALLOW_COPY_AND_ASSIGN(DataPack); | 86 DISALLOW_COPY_AND_ASSIGN(DataPack); |
80 }; | 87 }; |
81 | 88 |
82 } // namespace ui | 89 } // namespace ui |
83 | 90 |
84 #endif // UI_BASE_RESOURCE_DATA_PACK_H_ | 91 #endif // UI_BASE_RESOURCE_DATA_PACK_H_ |
OLD | NEW |