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

Side by Side Diff: net/disk_cache/simple/simple_synchronous_entry.h

Issue 23983005: SimpleCache: merge the first and second stream in one file (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Stream 0 size in footer Created 7 years, 3 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_ 5 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_
6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_ 6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
15 #include "base/platform_file.h" 16 #include "base/platform_file.h"
16 #include "base/time/time.h" 17 #include "base/time/time.h"
17 #include "net/base/cache_type.h" 18 #include "net/base/cache_type.h"
18 #include "net/disk_cache/simple/simple_entry_format.h" 19 #include "net/disk_cache/simple/simple_entry_format.h"
19 20
20 namespace net { 21 namespace net {
22 class GrowableIOBuffer;
21 class IOBuffer; 23 class IOBuffer;
22 } 24 }
23 25
24 namespace disk_cache { 26 namespace disk_cache {
25 27
26 class SimpleSynchronousEntry; 28 class SimpleSynchronousEntry;
27 29
28 struct SimpleEntryStat { 30 struct SimpleEntryStat {
29 SimpleEntryStat(); 31 SimpleEntryStat();
30 SimpleEntryStat(base::Time last_used_p, 32 SimpleEntryStat(base::Time last_used_p,
31 base::Time last_modified_p, 33 base::Time last_modified_p,
32 const int32 data_size_p[]); 34 const int32 data_size_p[]);
33 35
36 int GetOffsetInFile(const std::string& key,
37 int offset,
38 int stream_index) const;
39 int GetEOFOffsetInFile(const std::string& key, int stream_index) const;
40 int GetLastEOFOffsetInFile(const std::string& key, int stream_index) const;
41
34 base::Time last_used; 42 base::Time last_used;
35 base::Time last_modified; 43 base::Time last_modified;
36 int32 data_size[kSimpleEntryFileCount]; 44 int32 data_size[kSimpleEntryStreamCount];
37 }; 45 };
38 46
39 struct SimpleEntryCreationResults { 47 struct SimpleEntryCreationResults {
40 explicit SimpleEntryCreationResults(SimpleEntryStat entry_stat); 48 explicit SimpleEntryCreationResults(SimpleEntryStat entry_stat);
41 ~SimpleEntryCreationResults(); 49 ~SimpleEntryCreationResults();
42 50
43 SimpleSynchronousEntry* sync_entry; 51 SimpleSynchronousEntry* sync_entry;
52 scoped_refptr<net::GrowableIOBuffer> stream_0_data;
44 SimpleEntryStat entry_stat; 53 SimpleEntryStat entry_stat;
45 int result; 54 int result;
46 }; 55 };
47 56
48 // Worker thread interface to the very simple cache. This interface is not 57 // Worker thread interface to the very simple cache. This interface is not
49 // thread safe, and callers must ensure that it is only ever accessed from 58 // thread safe, and callers must ensure that it is only ever accessed from
50 // a single thread between synchronization points. 59 // a single thread between synchronization points.
51 class SimpleSynchronousEntry { 60 class SimpleSynchronousEntry {
52 public: 61 public:
53 struct CRCRecord { 62 struct CRCRecord {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 // Like |DoomEntry()| above. Deletes all entries corresponding to the 104 // Like |DoomEntry()| above. Deletes all entries corresponding to the
96 // |key_hashes|. Succeeds only when all entries are deleted. Returns a net 105 // |key_hashes|. Succeeds only when all entries are deleted. Returns a net
97 // error code. 106 // error code.
98 static int DoomEntrySet(scoped_ptr<std::vector<uint64> > key_hashes, 107 static int DoomEntrySet(scoped_ptr<std::vector<uint64> > key_hashes,
99 const base::FilePath& path); 108 const base::FilePath& path);
100 109
101 // N.B. ReadData(), WriteData(), CheckEOFRecord() and Close() may block on IO. 110 // N.B. ReadData(), WriteData(), CheckEOFRecord() and Close() may block on IO.
102 void ReadData(const EntryOperationData& in_entry_op, 111 void ReadData(const EntryOperationData& in_entry_op,
103 net::IOBuffer* out_buf, 112 net::IOBuffer* out_buf,
104 uint32* out_crc32, 113 uint32* out_crc32,
105 base::Time* out_last_used, 114 SimpleEntryStat* out_entry_stat,
106 int* out_result) const; 115 int* out_result) const;
107 void WriteData(const EntryOperationData& in_entry_op, 116 void WriteData(const EntryOperationData& in_entry_op,
108 net::IOBuffer* in_buf, 117 net::IOBuffer* in_buf,
109 SimpleEntryStat* out_entry_stat, 118 SimpleEntryStat* out_entry_stat,
110 int* out_result) const; 119 int* out_result) const;
111 void CheckEOFRecord(int index, 120 void CheckEOFRecord(int index,
112 int data_size, 121 const SimpleEntryStat& entry_stat,
113 uint32 expected_crc32, 122 uint32 expected_crc32,
114 int* out_result) const; 123 int* out_result) const;
115 124
116 // Close all streams, and add write EOF records to streams indicated by the 125 // Close all streams, and add write EOF records to streams indicated by the
117 // CRCRecord entries in |crc32s_to_write|. 126 // CRCRecord entries in |crc32s_to_write|.
118 void Close(const SimpleEntryStat& entry_stat, 127 void Close(const SimpleEntryStat& entry_stat,
119 scoped_ptr<std::vector<CRCRecord> > crc32s_to_write); 128 scoped_ptr<std::vector<CRCRecord> > crc32s_to_write,
129 net::GrowableIOBuffer* stream_0_data);
120 130
121 const base::FilePath& path() const { return path_; } 131 const base::FilePath& path() const { return path_; }
122 std::string key() const { return key_; } 132 std::string key() const { return key_; }
123 133
124 private: 134 private:
125 SimpleSynchronousEntry( 135 SimpleSynchronousEntry(
126 net::CacheType cache_type, 136 net::CacheType cache_type,
127 const base::FilePath& path, 137 const base::FilePath& path,
128 const std::string& key, 138 const std::string& key,
129 uint64 entry_hash); 139 uint64 entry_hash);
130 140
131 // Like Entry, the SimpleSynchronousEntry self releases when Close() is 141 // Like Entry, the SimpleSynchronousEntry self releases when Close() is
132 // called. 142 // called.
133 ~SimpleSynchronousEntry(); 143 ~SimpleSynchronousEntry();
134 144
135 bool OpenOrCreateFiles(bool create, 145 bool OpenOrCreateFiles(bool create,
136 bool had_index, 146 bool had_index,
137 SimpleEntryStat* out_entry_stat); 147 SimpleEntryStat* out_entry_stat);
138 void CloseFiles(); 148 void CloseFiles();
139 149
140 // Returns a net error, i.e. net::OK on success. |had_index| is passed 150 // Returns a net error, i.e. net::OK on success. |had_index| is passed
141 // from the main entry for metrics purposes, and is true if the index was 151 // from the main entry for metrics purposes, and is true if the index was
142 // initialized when the open operation began. 152 // initialized when the open operation began.
143 int InitializeForOpen(bool had_index, SimpleEntryStat* out_entry_stat); 153 int InitializeForOpen(bool had_index,
154 SimpleEntryStat* out_entry_stat,
155 scoped_refptr<net::GrowableIOBuffer>* stream_0_data);
144 156
145 // Returns a net error, including net::OK on success and net::FILE_EXISTS 157 // Returns a net error, including net::OK on success and net::FILE_EXISTS
146 // when the entry already exists. |had_index| is passed from the main entry 158 // when the entry already exists. |had_index| is passed from the main entry
147 // for metrics purposes, and is true if the index was initialized when the 159 // for metrics purposes, and is true if the index was initialized when the
148 // create operation began. 160 // create operation began.
149 int InitializeForCreate(bool had_index, SimpleEntryStat* out_entry_stat); 161 int InitializeForCreate(bool had_index, SimpleEntryStat* out_entry_stat);
150 162
163 // Allocates and fills a buffer with stream 0 data in |stream_0_data|, then
164 // checks its crc32.
165 int ReadAndValidateStream0(
166 int total_data_size,
167 SimpleEntryStat* out_entry_stat,
168 scoped_refptr<net::GrowableIOBuffer>* stream_0_data) const;
169
170 int GetEOFRecordData(int index,
171 const SimpleEntryStat& entry_stat,
172 bool* out_has_crc32,
173 uint32* out_crc32,
174 int* out_data_size) const;
151 void Doom() const; 175 void Doom() const;
152 176
153 static bool DeleteFilesForEntryHash(const base::FilePath& path, 177 static bool DeleteFilesForEntryHash(const base::FilePath& path,
154 uint64 entry_hash); 178 uint64 entry_hash);
155 179
156 const net::CacheType cache_type_; 180 const net::CacheType cache_type_;
157 const base::FilePath path_; 181 const base::FilePath path_;
158 const uint64 entry_hash_; 182 const uint64 entry_hash_;
159 std::string key_; 183 std::string key_;
160 184
161 bool have_open_files_; 185 bool have_open_files_;
162 bool initialized_; 186 bool initialized_;
163 187
164 base::PlatformFile files_[kSimpleEntryFileCount]; 188 base::PlatformFile files_[kSimpleEntryFileCount];
165 }; 189 };
166 190
167 } // namespace disk_cache 191 } // namespace disk_cache
168 192
169 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_ 193 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698