Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 { |
|
pasko
2013/09/17 16:40:52
I am sorry to bother you with dumb work, but now i
clamy
2013/09/18 16:17:15
Done.
| |
| 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 file_index) const; | |
| 41 int GetFileSize(const std::string& key, int file_index) const; | |
| 42 | |
| 34 base::Time last_used; | 43 base::Time last_used; |
| 35 base::Time last_modified; | 44 base::Time last_modified; |
| 36 int32 data_size[kSimpleEntryFileCount]; | 45 int32 data_size[kSimpleEntryStreamCount]; |
| 37 }; | 46 }; |
| 38 | 47 |
| 39 struct SimpleEntryCreationResults { | 48 struct SimpleEntryCreationResults { |
| 40 explicit SimpleEntryCreationResults(SimpleEntryStat entry_stat); | 49 explicit SimpleEntryCreationResults(SimpleEntryStat entry_stat); |
| 41 ~SimpleEntryCreationResults(); | 50 ~SimpleEntryCreationResults(); |
| 42 | 51 |
| 43 SimpleSynchronousEntry* sync_entry; | 52 SimpleSynchronousEntry* sync_entry; |
| 53 scoped_refptr<net::GrowableIOBuffer> stream_0_data; | |
| 44 SimpleEntryStat entry_stat; | 54 SimpleEntryStat entry_stat; |
| 45 int result; | 55 int result; |
| 46 }; | 56 }; |
| 47 | 57 |
| 48 // Worker thread interface to the very simple cache. This interface is not | 58 // 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 | 59 // thread safe, and callers must ensure that it is only ever accessed from |
| 50 // a single thread between synchronization points. | 60 // a single thread between synchronization points. |
| 51 class SimpleSynchronousEntry { | 61 class SimpleSynchronousEntry { |
| 52 public: | 62 public: |
| 53 struct CRCRecord { | 63 struct CRCRecord { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 // Like |DoomEntry()| above. Deletes all entries corresponding to the | 105 // Like |DoomEntry()| above. Deletes all entries corresponding to the |
| 96 // |key_hashes|. Succeeds only when all entries are deleted. Returns a net | 106 // |key_hashes|. Succeeds only when all entries are deleted. Returns a net |
| 97 // error code. | 107 // error code. |
| 98 static int DoomEntrySet(scoped_ptr<std::vector<uint64> > key_hashes, | 108 static int DoomEntrySet(scoped_ptr<std::vector<uint64> > key_hashes, |
| 99 const base::FilePath& path); | 109 const base::FilePath& path); |
| 100 | 110 |
| 101 // N.B. ReadData(), WriteData(), CheckEOFRecord() and Close() may block on IO. | 111 // N.B. ReadData(), WriteData(), CheckEOFRecord() and Close() may block on IO. |
| 102 void ReadData(const EntryOperationData& in_entry_op, | 112 void ReadData(const EntryOperationData& in_entry_op, |
| 103 net::IOBuffer* out_buf, | 113 net::IOBuffer* out_buf, |
| 104 uint32* out_crc32, | 114 uint32* out_crc32, |
| 105 base::Time* out_last_used, | 115 SimpleEntryStat* out_entry_stat, |
| 106 int* out_result) const; | 116 int* out_result) const; |
| 107 void WriteData(const EntryOperationData& in_entry_op, | 117 void WriteData(const EntryOperationData& in_entry_op, |
| 108 net::IOBuffer* in_buf, | 118 net::IOBuffer* in_buf, |
| 109 SimpleEntryStat* out_entry_stat, | 119 SimpleEntryStat* out_entry_stat, |
| 110 int* out_result) const; | 120 int* out_result) const; |
| 111 void CheckEOFRecord(int index, | 121 void CheckEOFRecord(int index, |
| 112 int data_size, | 122 const SimpleEntryStat& entry_stat, |
| 113 uint32 expected_crc32, | 123 uint32 expected_crc32, |
| 114 int* out_result) const; | 124 int* out_result) const; |
| 115 | 125 |
| 116 // Close all streams, and add write EOF records to streams indicated by the | 126 // Close all streams, and add write EOF records to streams indicated by the |
| 117 // CRCRecord entries in |crc32s_to_write|. | 127 // CRCRecord entries in |crc32s_to_write|. |
| 118 void Close(const SimpleEntryStat& entry_stat, | 128 void Close(const SimpleEntryStat& entry_stat, |
| 119 scoped_ptr<std::vector<CRCRecord> > crc32s_to_write); | 129 scoped_ptr<std::vector<CRCRecord> > crc32s_to_write, |
| 130 net::GrowableIOBuffer* stream_0_data); | |
| 120 | 131 |
| 121 const base::FilePath& path() const { return path_; } | 132 const base::FilePath& path() const { return path_; } |
| 122 std::string key() const { return key_; } | 133 std::string key() const { return key_; } |
| 123 | 134 |
| 124 private: | 135 private: |
| 125 SimpleSynchronousEntry( | 136 SimpleSynchronousEntry( |
| 126 net::CacheType cache_type, | 137 net::CacheType cache_type, |
| 127 const base::FilePath& path, | 138 const base::FilePath& path, |
| 128 const std::string& key, | 139 const std::string& key, |
| 129 uint64 entry_hash); | 140 uint64 entry_hash); |
| 130 | 141 |
| 131 // Like Entry, the SimpleSynchronousEntry self releases when Close() is | 142 // Like Entry, the SimpleSynchronousEntry self releases when Close() is |
| 132 // called. | 143 // called. |
| 133 ~SimpleSynchronousEntry(); | 144 ~SimpleSynchronousEntry(); |
| 134 | 145 |
| 135 bool OpenOrCreateFiles(bool create, | 146 bool OpenOrCreateFiles(bool create, |
| 136 bool had_index, | 147 bool had_index, |
| 137 SimpleEntryStat* out_entry_stat); | 148 SimpleEntryStat* out_entry_stat); |
| 138 void CloseFiles(); | 149 void CloseFiles(); |
| 139 | 150 |
| 140 // Returns a net error, i.e. net::OK on success. |had_index| is passed | 151 // 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 | 152 // from the main entry for metrics purposes, and is true if the index was |
| 142 // initialized when the open operation began. | 153 // initialized when the open operation began. |
| 143 int InitializeForOpen(bool had_index, SimpleEntryStat* out_entry_stat); | 154 int InitializeForOpen(bool had_index, |
| 155 SimpleEntryStat* out_entry_stat, | |
| 156 scoped_refptr<net::GrowableIOBuffer>* stream_0_data); | |
| 144 | 157 |
| 145 // Returns a net error, including net::OK on success and net::FILE_EXISTS | 158 // 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 | 159 // 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 | 160 // for metrics purposes, and is true if the index was initialized when the |
| 148 // create operation began. | 161 // create operation began. |
| 149 int InitializeForCreate(bool had_index, SimpleEntryStat* out_entry_stat); | 162 int InitializeForCreate(bool had_index, SimpleEntryStat* out_entry_stat); |
| 150 | 163 |
| 164 // Allocates and fills a buffer with stream 0 data in |stream_0_data|, then | |
| 165 // checks its crc32. | |
| 166 int ReadAndValidateStream0( | |
| 167 int total_data_size, | |
| 168 SimpleEntryStat* out_entry_stat, | |
| 169 scoped_refptr<net::GrowableIOBuffer>* stream_0_data) const; | |
| 170 | |
| 171 int GetEOFRecordData(int index, | |
| 172 const SimpleEntryStat& entry_stat, | |
| 173 bool* out_has_crc32, | |
| 174 uint32* out_crc32, | |
| 175 int* out_data_size) const; | |
| 151 void Doom() const; | 176 void Doom() const; |
| 152 | 177 |
| 153 static bool DeleteFilesForEntryHash(const base::FilePath& path, | 178 static bool DeleteFilesForEntryHash(const base::FilePath& path, |
| 154 uint64 entry_hash); | 179 uint64 entry_hash); |
| 155 | 180 |
| 156 const net::CacheType cache_type_; | 181 const net::CacheType cache_type_; |
| 157 const base::FilePath path_; | 182 const base::FilePath path_; |
| 158 const uint64 entry_hash_; | 183 const uint64 entry_hash_; |
| 159 std::string key_; | 184 std::string key_; |
| 160 | 185 |
| 161 bool have_open_files_; | 186 bool have_open_files_; |
| 162 bool initialized_; | 187 bool initialized_; |
| 163 | 188 |
| 164 base::PlatformFile files_[kSimpleEntryFileCount]; | 189 base::PlatformFile files_[kSimpleEntryFileCount]; |
| 165 }; | 190 }; |
| 166 | 191 |
| 167 } // namespace disk_cache | 192 } // namespace disk_cache |
| 168 | 193 |
| 169 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_ | 194 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_ |
| OLD | NEW |