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 // See net/disk_cache/disk_cache.h for the public interface. | 5 // See net/disk_cache/disk_cache.h for the public interface. |
6 | 6 |
7 #ifndef NET_DISK_CACHE_BLOCKFILE_STORAGE_BLOCK_H_ | 7 #ifndef NET_DISK_CACHE_BLOCKFILE_STORAGE_BLOCK_H_ |
8 #define NET_DISK_CACHE_BLOCKFILE_STORAGE_BLOCK_H_ | 8 #define NET_DISK_CACHE_BLOCKFILE_STORAGE_BLOCK_H_ |
9 | 9 |
10 #include "net/disk_cache/blockfile/addr.h" | 10 #include "net/disk_cache/blockfile/addr.h" |
11 #include "net/disk_cache/blockfile/mapped_file.h" | 11 #include "net/disk_cache/blockfile/mapped_file.h" |
12 | 12 |
13 namespace disk_cache { | 13 namespace disk_cache { |
14 | 14 |
15 // This class encapsulates common behavior of a single "block" of data that is | 15 // This class encapsulates common behavior of a single "block" of data that is |
16 // stored on a block-file. It implements the FileBlock interface, so it can be | 16 // stored on a block-file. It implements the FileBlock interface, so it can be |
17 // serialized directly to the backing file. | 17 // serialized directly to the backing file. |
18 // This object provides a memory buffer for the related data, and it can be used | 18 // This object provides a memory buffer for the related data, and it can be used |
19 // to actually share that memory with another instance of the class. | 19 // to actually share that memory with another instance of the class. |
20 // | 20 // |
21 // The following example shows how to share storage with another object: | 21 // The following example shows how to share storage with another object: |
22 // StorageBlock<TypeA> a(file, address); | 22 // StorageBlock<TypeA> a(file, address); |
23 // StorageBlock<TypeB> b(file, address); | 23 // StorageBlock<TypeB> b(file, address); |
24 // a.Load(); | 24 // a.Load(); |
25 // DoSomething(a.Data()); | 25 // DoSomething(a.Data()); |
26 // b.SetData(a.Data()); | 26 // b.SetData(a.Data()); |
27 // ModifySomething(b.Data()); | 27 // ModifySomething(b.Data()); |
28 // // Data modified on the previous call will be saved by b's destructor. | 28 // // Data modified on the previous call will be saved by b's destructor. |
29 // b.set_modified(); | 29 // b.set_modified(); |
30 template<typename T> | 30 template <typename T> |
31 class StorageBlock : public FileBlock { | 31 class StorageBlock : public FileBlock { |
32 public: | 32 public: |
33 StorageBlock(MappedFile* file, Addr address); | 33 StorageBlock(MappedFile* file, Addr address); |
34 virtual ~StorageBlock(); | 34 virtual ~StorageBlock(); |
35 | 35 |
36 // FileBlock interface. | 36 // FileBlock interface. |
37 virtual void* buffer() const; | 37 virtual void* buffer() const; |
38 virtual size_t size() const; | 38 virtual size_t size() const; |
39 virtual int offset() const; | 39 virtual int offset() const; |
40 | 40 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 bool modified_; | 88 bool modified_; |
89 bool own_data_; // Is data_ owned by this object or shared with someone else. | 89 bool own_data_; // Is data_ owned by this object or shared with someone else. |
90 bool extended_; // Used to store an entry of more than one block. | 90 bool extended_; // Used to store an entry of more than one block. |
91 | 91 |
92 DISALLOW_COPY_AND_ASSIGN(StorageBlock); | 92 DISALLOW_COPY_AND_ASSIGN(StorageBlock); |
93 }; | 93 }; |
94 | 94 |
95 } // namespace disk_cache | 95 } // namespace disk_cache |
96 | 96 |
97 #endif // NET_DISK_CACHE_BLOCKFILE_STORAGE_BLOCK_H_ | 97 #endif // NET_DISK_CACHE_BLOCKFILE_STORAGE_BLOCK_H_ |
OLD | NEW |