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

Side by Side Diff: net/disk_cache/flash/log_store.h

Issue 14265009: FlashCache refactorings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More refactorings. Created 7 years, 8 months 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
« no previous file with comments | « net/disk_cache/flash/flash_entry_unittest.cc ('k') | net/disk_cache/flash/log_store.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef NET_DISK_CACHE_FLASH_LOG_STORE_H_ 5 #ifndef NET_DISK_CACHE_FLASH_LOG_STORE_H_
6 #define NET_DISK_CACHE_FLASH_LOG_STORE_H_ 6 #define NET_DISK_CACHE_FLASH_LOG_STORE_H_
7 7
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "net/base/net_export.h" 13 #include "net/base/net_export.h"
14 #include "net/disk_cache/flash/storage.h"
14 15
15 namespace disk_cache { 16 namespace disk_cache {
16 17
17 class Segment; 18 class Segment;
18 class Storage;
19 19
20 // This class implements a general purpose store for storing and retrieving 20 // This class implements a general purpose store for storing and retrieving
21 // entries consisting of arbitrary binary data. The store has log semantics, 21 // entries consisting of arbitrary binary data. The store has log semantics,
22 // i.e. it's not possible to overwrite data in place. In order to update an 22 // i.e. it's not possible to overwrite data in place. In order to update an
23 // entry, a new version must be written. Only one entry can be written to at 23 // entry, a new version must be written. Only one entry can be written to at
24 // any given time, while concurrent reading of multiple entries is supported. 24 // any given time, while concurrent reading of multiple entries is supported.
25 class NET_EXPORT_PRIVATE LogStore { 25 class NET_EXPORT_PRIVATE LogStore {
26 public: 26 public:
27 explicit LogStore(Storage* storage); 27 LogStore(const base::FilePath& path, int32 size);
28 ~LogStore(); 28 ~LogStore();
29 29
30 // Performs initialization. Must be the first function called and further 30 // Performs initialization. Must be the first function called and further
31 // calls should be made only if it is successful. 31 // calls should be made only if it is successful.
32 bool Init(); 32 bool Init();
33 33
34 // Closes the store. Should be the last function called before destruction. 34 // Closes the store. Should be the last function called before destruction.
35 bool Close(); 35 bool Close();
36 36
37 // Creates an entry of |size| bytes. The id of the created entry is stored in 37 // Creates an entry of |size| bytes. The id of the created entry is stored in
(...skipping 13 matching lines...) Expand all
51 51
52 // Reads |size| bytes starting from |offset| into |buffer|, where |offset| is 52 // Reads |size| bytes starting from |offset| into |buffer|, where |offset| is
53 // relative to the entry's content, from an entry identified by |entry_id|. 53 // relative to the entry's content, from an entry identified by |entry_id|.
54 bool ReadData(int32 entry_id, void* buffer, int32 size, int32 offset) const; 54 bool ReadData(int32 entry_id, void* buffer, int32 size, int32 offset) const;
55 55
56 // Closes an entry that was either opened with OpenEntry or created with 56 // Closes an entry that was either opened with OpenEntry or created with
57 // CreateEntry. 57 // CreateEntry.
58 void CloseEntry(int32 id); 58 void CloseEntry(int32 id);
59 59
60 private: 60 private:
61 FRIEND_TEST_ALL_PREFIXES(FlashCacheTest, 61 FRIEND_TEST_ALL_PREFIXES(FlashCacheTest, LogStoreReadFromClosedSegment);
62 LogStoreReadFromClosedSegment); 62 FRIEND_TEST_ALL_PREFIXES(FlashCacheTest, LogStoreSegmentSelectionIsFifo);
63 FRIEND_TEST_ALL_PREFIXES(FlashCacheTest, 63 FRIEND_TEST_ALL_PREFIXES(FlashCacheTest, LogStoreInUseSegmentIsSkipped);
64 LogStoreSegmentSelectionIsFifo); 64 FRIEND_TEST_ALL_PREFIXES(FlashCacheTest, LogStoreReadFromCurrentAfterClose);
65 FRIEND_TEST_ALL_PREFIXES(FlashCacheTest,
66 LogStoreInUseSegmentIsSkipped);
67 FRIEND_TEST_ALL_PREFIXES(FlashCacheTest,
68 LogStoreReadFromCurrentAfterClose);
69 65
70 int32 GetNextSegmentIndex(); 66 int32 GetNextSegmentIndex();
71 bool InUse(int32 segment_index) const; 67 bool InUse(int32 segment_index) const;
72 68
73 Storage* storage_; 69 Storage storage_;
74 70
75 int32 num_segments_; 71 int32 num_segments_;
76 72
77 // Currently open segments, either for reading or writing. There can only be 73 // Currently open segments, either for reading or writing. There can only be
78 // one segment open for writing, and multiple open for reading. 74 // one segment open for writing, and multiple open for reading.
79 std::vector<Segment*> open_segments_; 75 std::vector<Segment*> open_segments_;
80 76
81 // The index of the segment currently being written to. It's an index to 77 // The index of the segment currently being written to. It's an index to
82 // |open_segments_| vector. 78 // |open_segments_| vector.
83 int32 write_index_; 79 int32 write_index_;
(...skipping 12 matching lines...) Expand all
96 92
97 bool init_; // Init was called. 93 bool init_; // Init was called.
98 bool closed_; // Close was called. 94 bool closed_; // Close was called.
99 95
100 DISALLOW_COPY_AND_ASSIGN(LogStore); 96 DISALLOW_COPY_AND_ASSIGN(LogStore);
101 }; 97 };
102 98
103 } // namespace disk_cache 99 } // namespace disk_cache
104 100
105 #endif // NET_DISK_CACHE_FLASH_LOG_STORE_H_ 101 #endif // NET_DISK_CACHE_FLASH_LOG_STORE_H_
OLDNEW
« no previous file with comments | « net/disk_cache/flash/flash_entry_unittest.cc ('k') | net/disk_cache/flash/log_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698