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

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

Issue 2874833005: SimpleCache: read small files all at once. (Closed)
Patch Set: Tweak histogram description based on feedback Created 3 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 <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <map> 11 #include <map>
12 #include <memory> 12 #include <memory>
13 #include <string> 13 #include <string>
14 #include <utility> 14 #include <utility>
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/feature_list.h"
17 #include "base/files/file.h" 18 #include "base/files/file.h"
18 #include "base/files/file_path.h" 19 #include "base/files/file_path.h"
19 #include "base/gtest_prod_util.h" 20 #include "base/gtest_prod_util.h"
20 #include "base/memory/ref_counted.h" 21 #include "base/memory/ref_counted.h"
22 #include "base/strings/string_piece_forward.h"
21 #include "base/time/time.h" 23 #include "base/time/time.h"
22 #include "net/base/cache_type.h" 24 #include "net/base/cache_type.h"
23 #include "net/base/net_export.h" 25 #include "net/base/net_export.h"
24 #include "net/disk_cache/simple/simple_entry_format.h" 26 #include "net/disk_cache/simple/simple_entry_format.h"
25 27
26 namespace net { 28 namespace net {
27 class GrowableIOBuffer; 29 class GrowableIOBuffer;
28 class IOBuffer; 30 class IOBuffer;
29 } 31 }
30 32
31 FORWARD_DECLARE_TEST(DiskCacheBackendTest, SimpleCacheEnumerationLongKeys); 33 FORWARD_DECLARE_TEST(DiskCacheBackendTest, SimpleCacheEnumerationLongKeys);
32 34
33 namespace disk_cache { 35 namespace disk_cache {
34 36
37 NET_EXPORT_PRIVATE extern const base::Feature kSimpleCachePrefetchExperiment;
38 NET_EXPORT_PRIVATE extern const char kSimplePrefetchBytesParam[];
39
40 // Returns how large a file would get prefetched on reading the entry.
41 // If the experiment is disabled, returns 0.
42 NET_EXPORT_PRIVATE int GetSimpleCachePrefetchSize();
43
35 class SimpleSynchronousEntry; 44 class SimpleSynchronousEntry;
36 45
37 // This class handles the passing of data about the entry between 46 // This class handles the passing of data about the entry between
38 // SimpleEntryImplementation and SimpleSynchronousEntry and the computation of 47 // SimpleEntryImplementation and SimpleSynchronousEntry and the computation of
39 // file offsets based on the data size for all streams. 48 // file offsets based on the data size for all streams.
40 class NET_EXPORT_PRIVATE SimpleEntryStat { 49 class NET_EXPORT_PRIVATE SimpleEntryStat {
41 public: 50 public:
42 SimpleEntryStat(base::Time last_used, 51 SimpleEntryStat(base::Time last_used,
43 base::Time last_modified, 52 base::Time last_modified,
44 const int32_t data_size[], 53 const int32_t data_size[],
(...skipping 21 matching lines...) Expand all
66 sparse_data_size_ = sparse_data_size; 75 sparse_data_size_ = sparse_data_size;
67 } 76 }
68 77
69 private: 78 private:
70 base::Time last_used_; 79 base::Time last_used_;
71 base::Time last_modified_; 80 base::Time last_modified_;
72 int32_t data_size_[kSimpleEntryStreamCount]; 81 int32_t data_size_[kSimpleEntryStreamCount];
73 int32_t sparse_data_size_; 82 int32_t sparse_data_size_;
74 }; 83 };
75 84
85 struct SimpleStreamPrefetchData {
86 SimpleStreamPrefetchData();
87 ~SimpleStreamPrefetchData();
88
89 scoped_refptr<net::GrowableIOBuffer> data;
90 uint32_t stream_crc32;
91 };
92
76 struct SimpleEntryCreationResults { 93 struct SimpleEntryCreationResults {
77 explicit SimpleEntryCreationResults(SimpleEntryStat entry_stat); 94 explicit SimpleEntryCreationResults(SimpleEntryStat entry_stat);
78 ~SimpleEntryCreationResults(); 95 ~SimpleEntryCreationResults();
79 96
80 SimpleSynchronousEntry* sync_entry; 97 SimpleSynchronousEntry* sync_entry;
81 scoped_refptr<net::GrowableIOBuffer> stream_0_data; 98
99 // Expectation is that [0] will always be filled in, but [1] might not be.
100 SimpleStreamPrefetchData stream_prefetch_data[2];
101
82 SimpleEntryStat entry_stat; 102 SimpleEntryStat entry_stat;
83 uint32_t stream_0_crc32;
84 int result; 103 int result;
85 }; 104 };
86 105
87 // Worker thread interface to the very simple cache. This interface is not 106 // Worker thread interface to the very simple cache. This interface is not
88 // thread safe, and callers must ensure that it is only ever accessed from 107 // thread safe, and callers must ensure that it is only ever accessed from
89 // a single thread between synchronization points. 108 // a single thread between synchronization points.
90 class SimpleSynchronousEntry { 109 class SimpleSynchronousEntry {
91 public: 110 public:
92 struct CRCRecord { 111 struct CRCRecord {
93 CRCRecord(); 112 CRCRecord();
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 // requested. 200 // requested.
182 void ReadData(const EntryOperationData& in_entry_op, 201 void ReadData(const EntryOperationData& in_entry_op,
183 CRCRequest* crc_request, 202 CRCRequest* crc_request,
184 SimpleEntryStat* entry_stat, 203 SimpleEntryStat* entry_stat,
185 net::IOBuffer* out_buf, 204 net::IOBuffer* out_buf,
186 int* out_result); 205 int* out_result);
187 void WriteData(const EntryOperationData& in_entry_op, 206 void WriteData(const EntryOperationData& in_entry_op,
188 net::IOBuffer* in_buf, 207 net::IOBuffer* in_buf,
189 SimpleEntryStat* out_entry_stat, 208 SimpleEntryStat* out_entry_stat,
190 int* out_result); 209 int* out_result);
191 int CheckEOFRecord(int index, 210 int CheckEOFRecord(int stream_index,
192 const SimpleEntryStat& entry_stat, 211 const SimpleEntryStat& entry_stat,
193 uint32_t expected_crc32) const; 212 uint32_t expected_crc32);
194 213
195 void ReadSparseData(const EntryOperationData& in_entry_op, 214 void ReadSparseData(const EntryOperationData& in_entry_op,
196 net::IOBuffer* out_buf, 215 net::IOBuffer* out_buf,
197 base::Time* out_last_used, 216 base::Time* out_last_used,
198 int* out_result); 217 int* out_result);
199 void WriteSparseData(const EntryOperationData& in_entry_op, 218 void WriteSparseData(const EntryOperationData& in_entry_op,
200 net::IOBuffer* in_buf, 219 net::IOBuffer* in_buf,
201 uint64_t max_sparse_data_size, 220 uint64_t max_sparse_data_size,
202 SimpleEntryStat* out_entry_stat, 221 SimpleEntryStat* out_entry_stat,
203 int* out_result); 222 int* out_result);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 void CloseFiles(); 293 void CloseFiles();
275 294
276 // Read the header and key at the beginning of the file, and validate that 295 // Read the header and key at the beginning of the file, and validate that
277 // they are correct. If this entry was opened with a key, the key is checked 296 // they are correct. If this entry was opened with a key, the key is checked
278 // for a match. If not, then the |key_| member is set based on the value in 297 // for a match. If not, then the |key_| member is set based on the value in
279 // this header. Records histograms if any check is failed. 298 // this header. Records histograms if any check is failed.
280 bool CheckHeaderAndKey(int file_index); 299 bool CheckHeaderAndKey(int file_index);
281 300
282 // Returns a net error, i.e. net::OK on success. 301 // Returns a net error, i.e. net::OK on success.
283 int InitializeForOpen(SimpleEntryStat* out_entry_stat, 302 int InitializeForOpen(SimpleEntryStat* out_entry_stat,
284 scoped_refptr<net::GrowableIOBuffer>* stream_0_data, 303 SimpleStreamPrefetchData stream_prefetch_data[2]);
285 uint32_t* out_stream_0_crc32);
286 304
287 // Writes the header and key to a newly-created stream file. |index| is the 305 // Writes the header and key to a newly-created stream file. |index| is the
288 // index of the stream. Returns true on success; returns false and sets 306 // index of the stream. Returns true on success; returns false and sets
289 // |*out_result| on failure. 307 // |*out_result| on failure.
290 bool InitializeCreatedFile(int index, CreateEntryResult* out_result); 308 bool InitializeCreatedFile(int index, CreateEntryResult* out_result);
291 309
292 // Returns a net error, including net::OK on success and net::FILE_EXISTS 310 // Returns a net error, including net::OK on success and net::FILE_EXISTS
293 // when the entry already exists. 311 // when the entry already exists.
294 int InitializeForCreate(SimpleEntryStat* out_entry_stat); 312 int InitializeForCreate(SimpleEntryStat* out_entry_stat);
295 313
296 // Allocates and fills a buffer with stream 0 data in |stream_0_data|, then 314 // Allocates and fills a buffer with stream 0 data in |stream_0_data|, then
297 // checks its crc32. 315 // checks its crc32. May also optionally read in |stream_1_data| and its
298 int ReadAndValidateStream0( 316 // crc, but might decide not to.
317 int ReadAndValidateStream0AndMaybe1(
299 int file_size, 318 int file_size,
300 SimpleEntryStat* out_entry_stat, 319 SimpleEntryStat* out_entry_stat,
301 scoped_refptr<net::GrowableIOBuffer>* stream_0_data, 320 SimpleStreamPrefetchData stream_prefetch_data[2]);
302 uint32_t* out_stream_0_crc32);
303 321
304 int GetEOFRecordData(int index, 322 // Reads the EOF record located at |file_offset| in file |file_index|,
305 const SimpleEntryStat& entry_stat, 323 // with |file_0_prefetch| ptentially having prefetched file 0 content.
306 bool* out_has_crc32, 324 // Puts the result into |*eof_record| and sanity-checks it.
307 bool* out_has_key_sha256, 325 // Returns net status, and records any failures to UMA.
308 uint32_t* out_crc32, 326 int GetEOFRecordData(base::StringPiece file_0_prefetch,
309 int32_t* out_data_size) const; 327 int file_index,
328 int file_offset,
329 SimpleFileEOF* eof_record);
330
331 // Reads either from |file_0_prefetch| or files_[file_index].
332 // Range-checks all the in-memory reads.
333 bool ReadFromFileOrPrefetched(base::StringPiece file_0_prefetch,
334 int file_index,
335 int offset,
336 int size,
337 char* dest);
338
339 // Extracts out the payload of stream |stream_index|, reading either from
340 // |file_0_prefetch|, if available, or the file. |entry_stat| will be used to
341 // determine file layout, though |extra_size| additional bytes will be read
342 // past the stream payload end.
343 //
344 // |*stream_data| will be pointed to a fresh buffer with the results,
345 // and |*out_crc32| will get the checksum, which will be verified against
346 // |eof_record|.
347 int PreReadStreamPayload(base::StringPiece file_0_prefetch,
348 int stream_index,
349 int extra_size,
350 const SimpleEntryStat& entry_stat,
351 const SimpleFileEOF& eof_record,
352 SimpleStreamPrefetchData* out);
353
310 void Doom() const; 354 void Doom() const;
311 355
312 // Opens the sparse data file and scans it if it exists. 356 // Opens the sparse data file and scans it if it exists.
313 bool OpenSparseFileIfExists(int32_t* out_sparse_data_size); 357 bool OpenSparseFileIfExists(int32_t* out_sparse_data_size);
314 358
315 // Creates and initializes the sparse data file. 359 // Creates and initializes the sparse data file.
316 bool CreateSparseFile(); 360 bool CreateSparseFile();
317 361
318 // Closes the sparse data file. 362 // Closes the sparse data file.
319 void CloseSparseFile(); 363 void CloseSparseFile();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 int64_t sparse_tail_offset_; 433 int64_t sparse_tail_offset_;
390 434
391 // True if the entry was created, or false if it was opened. Used to log 435 // True if the entry was created, or false if it was opened. Used to log
392 // SimpleCache.*.EntryCreatedWithStream2Omitted only for created entries. 436 // SimpleCache.*.EntryCreatedWithStream2Omitted only for created entries.
393 bool files_created_; 437 bool files_created_;
394 }; 438 };
395 439
396 } // namespace disk_cache 440 } // namespace disk_cache
397 441
398 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_ 442 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_
OLDNEW
« no previous file with comments | « net/disk_cache/simple/simple_entry_impl.cc ('k') | net/disk_cache/simple/simple_synchronous_entry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698