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