summaryrefslogtreecommitdiff
path: root/chromium/net/disk_cache/simple/simple_synchronous_entry.h
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/net/disk_cache/simple/simple_synchronous_entry.h')
-rw-r--r--chromium/net/disk_cache/simple/simple_synchronous_entry.h72
1 files changed, 47 insertions, 25 deletions
diff --git a/chromium/net/disk_cache/simple/simple_synchronous_entry.h b/chromium/net/disk_cache/simple/simple_synchronous_entry.h
index 963f665b931..3c939a835a5 100644
--- a/chromium/net/disk_cache/simple/simple_synchronous_entry.h
+++ b/chromium/net/disk_cache/simple/simple_synchronous_entry.h
@@ -9,14 +9,15 @@
#include <algorithm>
#include <map>
+#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/files/file.h"
#include "base/files/file_path.h"
+#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
-#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
#include "net/base/cache_type.h"
#include "net/base/net_export.h"
@@ -27,6 +28,8 @@ class GrowableIOBuffer;
class IOBuffer;
}
+FORWARD_DECLARE_TEST(DiskCacheBackendTest, SimpleCacheEnumerationLongKeys);
+
namespace disk_cache {
class SimpleSynchronousEntry;
@@ -41,12 +44,10 @@ class NET_EXPORT_PRIVATE SimpleEntryStat {
const int32_t data_size[],
const int32_t sparse_data_size);
- int GetOffsetInFile(const std::string& key,
- int offset,
- int stream_index) const;
- int GetEOFOffsetInFile(const std::string& key, int stream_index) const;
- int GetLastEOFOffsetInFile(const std::string& key, int file_index) const;
- int64_t GetFileSize(const std::string& key, int file_index) const;
+ int GetOffsetInFile(size_t key_length, int offset, int stream_index) const;
+ int GetEOFOffsetInFile(size_t key_length, int stream_index) const;
+ int GetLastEOFOffsetInFile(size_t key_length, int file_index) const;
+ int64_t GetFileSize(size_t key_length, int file_index) const;
base::Time last_used() const { return last_used_; }
base::Time last_modified() const { return last_modified_; }
@@ -114,8 +115,12 @@ class SimpleSynchronousEntry {
bool doomed;
};
+ // Opens a disk cache entry on disk. The |key| parameter is optional, if empty
+ // the operation may be slower. The |entry_hash| parameter is required.
+ // |had_index| is provided only for histograms.
static void OpenEntry(net::CacheType cache_type,
const base::FilePath& path,
+ const std::string& key,
uint64_t entry_hash,
bool had_index,
SimpleEntryCreationResults* out_results);
@@ -150,7 +155,7 @@ class SimpleSynchronousEntry {
net::IOBuffer* out_buf,
uint32_t* out_crc32,
SimpleEntryStat* entry_stat,
- int* out_result) const;
+ int* out_result);
void WriteData(const EntryOperationData& in_entry_op,
net::IOBuffer* in_buf,
SimpleEntryStat* out_entry_stat,
@@ -176,13 +181,16 @@ class SimpleSynchronousEntry {
// Close all streams, and add write EOF records to streams indicated by the
// CRCRecord entries in |crc32s_to_write|.
void Close(const SimpleEntryStat& entry_stat,
- scoped_ptr<std::vector<CRCRecord> > crc32s_to_write,
+ std::unique_ptr<std::vector<CRCRecord>> crc32s_to_write,
net::GrowableIOBuffer* stream_0_data);
const base::FilePath& path() const { return path_; }
std::string key() const { return key_; }
private:
+ FRIEND_TEST_ALL_PREFIXES(::DiskCacheBackendTest,
+ SimpleCacheEnumerationLongKeys);
+
enum CreateEntryResult {
CREATE_ENTRY_SUCCESS = 0,
CREATE_ENTRY_PLATFORM_FILE_ERROR = 1,
@@ -207,10 +215,16 @@ class SimpleSynchronousEntry {
}
};
+ // When opening an entry without knowing the key, the header must be read
+ // without knowing the size of the key. This is how much to read initially, to
+ // make it likely the entire key is read.
+ static const size_t kInitialHeaderRead = 64 * 1024;
+
SimpleSynchronousEntry(net::CacheType cache_type,
const base::FilePath& path,
const std::string& key,
- uint64_t entry_hash);
+ uint64_t entry_hash,
+ bool had_index);
// Like Entry, the SimpleSynchronousEntry self releases when Close() is
// called.
@@ -227,18 +241,19 @@ class SimpleSynchronousEntry {
bool MaybeCreateFile(int file_index,
FileRequired file_required,
base::File::Error* out_error);
- bool OpenFiles(bool had_index,
- SimpleEntryStat* out_entry_stat);
- bool CreateFiles(bool had_index,
- SimpleEntryStat* out_entry_stat);
+ bool OpenFiles(SimpleEntryStat* out_entry_stat);
+ bool CreateFiles(SimpleEntryStat* out_entry_stat);
void CloseFile(int index);
void CloseFiles();
- // Returns a net error, i.e. net::OK on success. |had_index| is passed
- // from the main entry for metrics purposes, and is true if the index was
- // initialized when the open operation began.
- int InitializeForOpen(bool had_index,
- SimpleEntryStat* out_entry_stat,
+ // Read the header and key at the beginning of the file, and validate that
+ // they are correct. If this entry was opened with a key, the key is checked
+ // for a match. If not, then the |key_| member is set based on the value in
+ // this header. Records histograms if any check is failed.
+ bool CheckHeaderAndKey(int file_index);
+
+ // Returns a net error, i.e. net::OK on success.
+ int InitializeForOpen(SimpleEntryStat* out_entry_stat,
scoped_refptr<net::GrowableIOBuffer>* stream_0_data,
uint32_t* out_stream_0_crc32);
@@ -248,22 +263,21 @@ class SimpleSynchronousEntry {
bool InitializeCreatedFile(int index, CreateEntryResult* out_result);
// Returns a net error, including net::OK on success and net::FILE_EXISTS
- // when the entry already exists. |had_index| is passed from the main entry
- // for metrics purposes, and is true if the index was initialized when the
- // create operation began.
- int InitializeForCreate(bool had_index, SimpleEntryStat* out_entry_stat);
+ // when the entry already exists.
+ int InitializeForCreate(SimpleEntryStat* out_entry_stat);
// Allocates and fills a buffer with stream 0 data in |stream_0_data|, then
// checks its crc32.
int ReadAndValidateStream0(
- int total_data_size,
+ int file_size,
SimpleEntryStat* out_entry_stat,
scoped_refptr<net::GrowableIOBuffer>* stream_0_data,
- uint32_t* out_stream_0_crc32) const;
+ uint32_t* out_stream_0_crc32);
int GetEOFRecordData(int index,
const SimpleEntryStat& entry_stat,
bool* out_has_crc32,
+ bool* out_has_key_sha256,
uint32_t* out_crc32,
int* out_data_size) const;
void Doom() const;
@@ -320,11 +334,19 @@ class SimpleSynchronousEntry {
const net::CacheType cache_type_;
const base::FilePath path_;
const uint64_t entry_hash_;
+ const bool had_index_;
std::string key_;
bool have_open_files_;
bool initialized_;
+ // Normally false. This is set to true when an entry is opened without
+ // checking the file headers. Any subsequent read will perform the check
+ // before completing.
+ bool header_and_key_check_needed_[kSimpleEntryFileCount] = {
+ false,
+ };
+
base::File files_[kSimpleEntryFileCount];
// True if the corresponding stream is empty and therefore no on-disk file