Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(429)

Side by Side Diff: base/data_pack.h

Issue 338027: Modify DataPacks so they can return RefCountedStaticMemory objects. (Closed)
Patch Set: Rewrite GetStaticMemory Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2008 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 BASE_DATA_PACK_H_ 9 #ifndef BASE_DATA_PACK_H_
10 #define BASE_DATA_PACK_H_ 10 #define BASE_DATA_PACK_H_
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/ref_counted_memory.h"
13 #include "base/scoped_ptr.h" 14 #include "base/scoped_ptr.h"
14 15
15 namespace file_util { 16 namespace file_util {
16 class MemoryMappedFile; 17 class MemoryMappedFile;
17 } 18 }
18 class FilePath; 19 class FilePath;
19 20
20 namespace base { 21 namespace base {
21 22
22 class StringPiece; 23 class StringPiece;
23 24
24 class DataPack { 25 class DataPack {
25 public: 26 public:
26 DataPack(); 27 DataPack();
27 ~DataPack(); 28 ~DataPack();
28 29
29 // Load a pack file from |path|, returning false on error. 30 // Load a pack file from |path|, returning false on error.
30 bool Load(const FilePath& path); 31 bool Load(const FilePath& path);
31 32
32 // Get resource by id |resource_id|, filling in |data|. 33 // Get resource by id |resource_id|, filling in |data|.
33 // The data is owned by the DataPack object and should not be modified. 34 // The data is owned by the DataPack object and should not be modified.
34 // Returns false if the resource id isn't found. 35 // Returns false if the resource id isn't found.
35 bool Get(uint32_t resource_id, StringPiece* data); 36 bool GetStringPiece(uint32_t resource_id, StringPiece* data);
37
38 // Like GetStringPiece(), but returns a reference to memory. This interface
39 // is used for image data, while the StringPiece interface is usually used
40 // for localization strings.
41 RefCountedStaticMemory* GetStaticMemory(uint32_t resource_id);
36 42
37 private: 43 private:
38 // The memory-mapped data. 44 // The memory-mapped data.
39 scoped_ptr<file_util::MemoryMappedFile> mmap_; 45 scoped_ptr<file_util::MemoryMappedFile> mmap_;
40 46
41 // Number of resources in the data. 47 // Number of resources in the data.
42 size_t resource_count_; 48 size_t resource_count_;
43 49
44 DISALLOW_COPY_AND_ASSIGN(DataPack); 50 DISALLOW_COPY_AND_ASSIGN(DataPack);
45 }; 51 };
46 52
47 } // namespace base 53 } // namespace base
48 54
49 #endif // BASE_DATA_PACK_H_ 55 #endif // BASE_DATA_PACK_H_
OLDNEW
« no previous file with comments | « app/resource_bundle_mac.mm ('k') | base/data_pack.cc » ('j') | base/data_pack.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698