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

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

Issue 1498003003: Remove kint64max. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: win fix Created 5 years 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_ENTRY_IMPL_H_ 5 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_
6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_ 6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_
7 7
mmenke 2015/12/07 16:18:18 include stdint
Avi (use Gerrit) 2015/12/07 16:24:30 It's used in the .h file, so I'm including it ther
8 #include <queue> 8 #include <queue>
9 #include <string> 9 #include <string>
10 10
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
15 #include "net/base/cache_type.h" 15 #include "net/base/cache_type.h"
16 #include "net/base/net_export.h" 16 #include "net/base/net_export.h"
17 #include "net/disk_cache/disk_cache.h" 17 #include "net/disk_cache/disk_cache.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 // The Backend provides an |ActiveEntryProxy| instance to this entry when it 50 // The Backend provides an |ActiveEntryProxy| instance to this entry when it
51 // is active, meaning it's the canonical entry for this |entry_hash_|. The 51 // is active, meaning it's the canonical entry for this |entry_hash_|. The
52 // entry can make itself inactive by deleting its proxy. 52 // entry can make itself inactive by deleting its proxy.
53 class ActiveEntryProxy { 53 class ActiveEntryProxy {
54 public: 54 public:
55 virtual ~ActiveEntryProxy() = 0; 55 virtual ~ActiveEntryProxy() = 0;
56 }; 56 };
57 57
58 SimpleEntryImpl(net::CacheType cache_type, 58 SimpleEntryImpl(net::CacheType cache_type,
59 const base::FilePath& path, 59 const base::FilePath& path,
60 uint64 entry_hash, 60 uint64_t entry_hash,
61 OperationsMode operations_mode, 61 OperationsMode operations_mode,
62 SimpleBackendImpl* backend, 62 SimpleBackendImpl* backend,
63 net::NetLog* net_log); 63 net::NetLog* net_log);
64 64
65 void SetActiveEntryProxy( 65 void SetActiveEntryProxy(
66 scoped_ptr<ActiveEntryProxy> active_entry_proxy); 66 scoped_ptr<ActiveEntryProxy> active_entry_proxy);
67 67
68 // Adds another reader/writer to this entry, if possible, returning |this| to 68 // Adds another reader/writer to this entry, if possible, returning |this| to
69 // |entry|. 69 // |entry|.
70 int OpenEntry(Entry** entry, const CompletionCallback& callback); 70 int OpenEntry(Entry** entry, const CompletionCallback& callback);
71 71
72 // Creates this entry, if possible. Returns |this| to |entry|. 72 // Creates this entry, if possible. Returns |this| to |entry|.
73 int CreateEntry(Entry** entry, const CompletionCallback& callback); 73 int CreateEntry(Entry** entry, const CompletionCallback& callback);
74 74
75 // Identical to Backend::Doom() except that it accepts a CompletionCallback. 75 // Identical to Backend::Doom() except that it accepts a CompletionCallback.
76 int DoomEntry(const CompletionCallback& callback); 76 int DoomEntry(const CompletionCallback& callback);
77 77
78 const std::string& key() const { return key_; } 78 const std::string& key() const { return key_; }
79 uint64 entry_hash() const { return entry_hash_; } 79 uint64_t entry_hash() const { return entry_hash_; }
80 void SetKey(const std::string& key); 80 void SetKey(const std::string& key);
81 81
82 // From Entry: 82 // From Entry:
83 void Doom() override; 83 void Doom() override;
84 void Close() override; 84 void Close() override;
85 std::string GetKey() const override; 85 std::string GetKey() const override;
86 base::Time GetLastUsed() const override; 86 base::Time GetLastUsed() const override;
87 base::Time GetLastModified() const override; 87 base::Time GetLastModified() const override;
88 int32 GetDataSize(int index) const override; 88 int32_t GetDataSize(int index) const override;
89 int ReadData(int stream_index, 89 int ReadData(int stream_index,
90 int offset, 90 int offset,
91 net::IOBuffer* buf, 91 net::IOBuffer* buf,
92 int buf_len, 92 int buf_len,
93 const CompletionCallback& callback) override; 93 const CompletionCallback& callback) override;
94 int WriteData(int stream_index, 94 int WriteData(int stream_index,
95 int offset, 95 int offset,
96 net::IOBuffer* buf, 96 net::IOBuffer* buf,
97 int buf_len, 97 int buf_len,
98 const CompletionCallback& callback, 98 const CompletionCallback& callback,
99 bool truncate) override; 99 bool truncate) override;
100 int ReadSparseData(int64 offset, 100 int ReadSparseData(int64_t offset,
101 net::IOBuffer* buf, 101 net::IOBuffer* buf,
102 int buf_len, 102 int buf_len,
103 const CompletionCallback& callback) override; 103 const CompletionCallback& callback) override;
104 int WriteSparseData(int64 offset, 104 int WriteSparseData(int64_t offset,
105 net::IOBuffer* buf, 105 net::IOBuffer* buf,
106 int buf_len, 106 int buf_len,
107 const CompletionCallback& callback) override; 107 const CompletionCallback& callback) override;
108 int GetAvailableRange(int64 offset, 108 int GetAvailableRange(int64_t offset,
109 int len, 109 int len,
110 int64* start, 110 int64_t* start,
111 const CompletionCallback& callback) override; 111 const CompletionCallback& callback) override;
112 bool CouldBeSparse() const override; 112 bool CouldBeSparse() const override;
113 void CancelSparseIO() override; 113 void CancelSparseIO() override;
114 int ReadyForSparseIO(const CompletionCallback& callback) override; 114 int ReadyForSparseIO(const CompletionCallback& callback) override;
115 115
116 private: 116 private:
117 class ScopedOperationRunner; 117 class ScopedOperationRunner;
118 friend class ScopedOperationRunner; 118 friend class ScopedOperationRunner;
119 119
120 enum State { 120 enum State {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 int buf_len, 186 int buf_len,
187 const CompletionCallback& callback); 187 const CompletionCallback& callback);
188 188
189 void WriteDataInternal(int index, 189 void WriteDataInternal(int index,
190 int offset, 190 int offset,
191 net::IOBuffer* buf, 191 net::IOBuffer* buf,
192 int buf_len, 192 int buf_len,
193 const CompletionCallback& callback, 193 const CompletionCallback& callback,
194 bool truncate); 194 bool truncate);
195 195
196 void ReadSparseDataInternal(int64 sparse_offset, 196 void ReadSparseDataInternal(int64_t sparse_offset,
197 net::IOBuffer* buf, 197 net::IOBuffer* buf,
198 int buf_len, 198 int buf_len,
199 const CompletionCallback& callback); 199 const CompletionCallback& callback);
200 200
201 void WriteSparseDataInternal(int64 sparse_offset, 201 void WriteSparseDataInternal(int64_t sparse_offset,
202 net::IOBuffer* buf, 202 net::IOBuffer* buf,
203 int buf_len, 203 int buf_len,
204 const CompletionCallback& callback); 204 const CompletionCallback& callback);
205 205
206 void GetAvailableRangeInternal(int64 sparse_offset, 206 void GetAvailableRangeInternal(int64_t sparse_offset,
207 int len, 207 int len,
208 int64* out_start, 208 int64_t* out_start,
209 const CompletionCallback& callback); 209 const CompletionCallback& callback);
210 210
211 void DoomEntryInternal(const CompletionCallback& callback); 211 void DoomEntryInternal(const CompletionCallback& callback);
212 212
213 // Called after a SimpleSynchronousEntry has completed CreateEntry() or 213 // Called after a SimpleSynchronousEntry has completed CreateEntry() or
214 // OpenEntry(). If |in_sync_entry| is non-NULL, creation is successful and we 214 // OpenEntry(). If |in_sync_entry| is non-NULL, creation is successful and we
215 // can return |this| SimpleEntryImpl to |*out_entry|. Runs 215 // can return |this| SimpleEntryImpl to |*out_entry|. Runs
216 // |completion_callback|. 216 // |completion_callback|.
217 void CreationOperationComplete( 217 void CreationOperationComplete(
218 const CompletionCallback& completion_callback, 218 const CompletionCallback& completion_callback,
(...skipping 10 matching lines...) Expand all
229 // Internal utility method used by other completion methods. Calls 229 // Internal utility method used by other completion methods. Calls
230 // |completion_callback| after updating state and dooming on errors. 230 // |completion_callback| after updating state and dooming on errors.
231 void EntryOperationComplete(const CompletionCallback& completion_callback, 231 void EntryOperationComplete(const CompletionCallback& completion_callback,
232 const SimpleEntryStat& entry_stat, 232 const SimpleEntryStat& entry_stat,
233 scoped_ptr<int> result); 233 scoped_ptr<int> result);
234 234
235 // Called after an asynchronous read. Updates |crc32s_| if possible. 235 // Called after an asynchronous read. Updates |crc32s_| if possible.
236 void ReadOperationComplete(int stream_index, 236 void ReadOperationComplete(int stream_index,
237 int offset, 237 int offset,
238 const CompletionCallback& completion_callback, 238 const CompletionCallback& completion_callback,
239 scoped_ptr<uint32> read_crc32, 239 scoped_ptr<uint32_t> read_crc32,
240 scoped_ptr<SimpleEntryStat> entry_stat, 240 scoped_ptr<SimpleEntryStat> entry_stat,
241 scoped_ptr<int> result); 241 scoped_ptr<int> result);
242 242
243 // Called after an asynchronous write completes. 243 // Called after an asynchronous write completes.
244 void WriteOperationComplete(int stream_index, 244 void WriteOperationComplete(int stream_index,
245 const CompletionCallback& completion_callback, 245 const CompletionCallback& completion_callback,
246 scoped_ptr<SimpleEntryStat> entry_stat, 246 scoped_ptr<SimpleEntryStat> entry_stat,
247 scoped_ptr<int> result); 247 scoped_ptr<int> result);
248 248
249 void ReadSparseOperationComplete( 249 void ReadSparseOperationComplete(
(...skipping 22 matching lines...) Expand all
272 int stream_index, 272 int stream_index,
273 int orig_result, 273 int orig_result,
274 const CompletionCallback& completion_callback, 274 const CompletionCallback& completion_callback,
275 scoped_ptr<int> result); 275 scoped_ptr<int> result);
276 276
277 // Called after completion of asynchronous IO and receiving file metadata for 277 // Called after completion of asynchronous IO and receiving file metadata for
278 // the entry in |entry_stat|. Updates the metadata in the entry and in the 278 // the entry in |entry_stat|. Updates the metadata in the entry and in the
279 // index to make them available on next IO operations. 279 // index to make them available on next IO operations.
280 void UpdateDataFromEntryStat(const SimpleEntryStat& entry_stat); 280 void UpdateDataFromEntryStat(const SimpleEntryStat& entry_stat);
281 281
282 int64 GetDiskUsage() const; 282 int64_t GetDiskUsage() const;
283 283
284 // Used to report histograms. 284 // Used to report histograms.
285 void RecordReadIsParallelizable(const SimpleEntryOperation& operation) const; 285 void RecordReadIsParallelizable(const SimpleEntryOperation& operation) const;
286 void RecordWriteDependencyType(const SimpleEntryOperation& operation) const; 286 void RecordWriteDependencyType(const SimpleEntryOperation& operation) const;
287 287
288 // Reads from the stream 0 data kept in memory. 288 // Reads from the stream 0 data kept in memory.
289 int ReadStream0Data(net::IOBuffer* buf, int offset, int buf_len); 289 int ReadStream0Data(net::IOBuffer* buf, int offset, int buf_len);
290 290
291 // Copies data from |buf| to the internal in-memory buffer for stream 0. If 291 // Copies data from |buf| to the internal in-memory buffer for stream 0. If
292 // |truncate| is set to true, the target buffer will be truncated at |offset| 292 // |truncate| is set to true, the target buffer will be truncated at |offset|
(...skipping 12 matching lines...) Expand all
305 scoped_ptr<ActiveEntryProxy> active_entry_proxy_; 305 scoped_ptr<ActiveEntryProxy> active_entry_proxy_;
306 306
307 // All nonstatic SimpleEntryImpl methods should always be called on the IO 307 // All nonstatic SimpleEntryImpl methods should always be called on the IO
308 // thread, in all cases. |io_thread_checker_| documents and enforces this. 308 // thread, in all cases. |io_thread_checker_| documents and enforces this.
309 base::ThreadChecker io_thread_checker_; 309 base::ThreadChecker io_thread_checker_;
310 310
311 const base::WeakPtr<SimpleBackendImpl> backend_; 311 const base::WeakPtr<SimpleBackendImpl> backend_;
312 const net::CacheType cache_type_; 312 const net::CacheType cache_type_;
313 const scoped_refptr<base::TaskRunner> worker_pool_; 313 const scoped_refptr<base::TaskRunner> worker_pool_;
314 const base::FilePath path_; 314 const base::FilePath path_;
315 const uint64 entry_hash_; 315 const uint64_t entry_hash_;
316 const bool use_optimistic_operations_; 316 const bool use_optimistic_operations_;
317 std::string key_; 317 std::string key_;
318 318
319 // |last_used_|, |last_modified_| and |data_size_| are copied from the 319 // |last_used_|, |last_modified_| and |data_size_| are copied from the
320 // synchronous entry at the completion of each item of asynchronous IO. 320 // synchronous entry at the completion of each item of asynchronous IO.
321 // TODO(clamy): Unify last_used_ with data in the index. 321 // TODO(clamy): Unify last_used_ with data in the index.
322 base::Time last_used_; 322 base::Time last_used_;
323 base::Time last_modified_; 323 base::Time last_modified_;
324 int32 data_size_[kSimpleEntryStreamCount]; 324 int32_t data_size_[kSimpleEntryStreamCount];
325 int32 sparse_data_size_; 325 int32_t sparse_data_size_;
326 326
327 // Number of times this object has been returned from Backend::OpenEntry() and 327 // Number of times this object has been returned from Backend::OpenEntry() and
328 // Backend::CreateEntry() without subsequent Entry::Close() calls. Used to 328 // Backend::CreateEntry() without subsequent Entry::Close() calls. Used to
329 // notify the backend when this entry not used by any callers. 329 // notify the backend when this entry not used by any callers.
330 int open_count_; 330 int open_count_;
331 331
332 bool doomed_; 332 bool doomed_;
333 333
334 State state_; 334 State state_;
335 335
336 // When possible, we compute a crc32, for the data in each entry as we read or 336 // When possible, we compute a crc32, for the data in each entry as we read or
337 // write. For each stream, |crc32s_[index]| is the crc32 of that stream from 337 // write. For each stream, |crc32s_[index]| is the crc32 of that stream from
338 // [0 .. |crc32s_end_offset_|). If |crc32s_end_offset_[index] == 0| then the 338 // [0 .. |crc32s_end_offset_|). If |crc32s_end_offset_[index] == 0| then the
339 // value of |crc32s_[index]| is undefined. 339 // value of |crc32s_[index]| is undefined.
340 // Note at this can only be done in the current implementation in the case of 340 // Note at this can only be done in the current implementation in the case of
341 // a single entry reader that reads serially through the entire file. 341 // a single entry reader that reads serially through the entire file.
342 // Extending this to multiple readers is possible, but isn't currently worth 342 // Extending this to multiple readers is possible, but isn't currently worth
343 // it; see http://crbug.com/488076#c3 for details. 343 // it; see http://crbug.com/488076#c3 for details.
344 int32 crc32s_end_offset_[kSimpleEntryStreamCount]; 344 int32_t crc32s_end_offset_[kSimpleEntryStreamCount];
345 uint32 crc32s_[kSimpleEntryStreamCount]; 345 uint32_t crc32s_[kSimpleEntryStreamCount];
346 346
347 // If |have_written_[index]| is true, we have written to the file that 347 // If |have_written_[index]| is true, we have written to the file that
348 // contains stream |index|. 348 // contains stream |index|.
349 bool have_written_[kSimpleEntryStreamCount]; 349 bool have_written_[kSimpleEntryStreamCount];
350 350
351 // Reflects how much CRC checking has been done with the entry. This state is 351 // Reflects how much CRC checking has been done with the entry. This state is
352 // reported on closing each entry stream. 352 // reported on closing each entry stream.
353 CheckCrcResult crc_check_state_[kSimpleEntryStreamCount]; 353 CheckCrcResult crc_check_state_[kSimpleEntryStreamCount];
354 354
355 // The |synchronous_entry_| is the worker thread object that performs IO on 355 // The |synchronous_entry_| is the worker thread object that performs IO on
(...skipping 18 matching lines...) Expand all
374 // 1 on disk, to reduce the number of file descriptors and save disk space. 374 // 1 on disk, to reduce the number of file descriptors and save disk space.
375 // This strategy allows stream 1 to change size easily. Since stream 0 is only 375 // This strategy allows stream 1 to change size easily. Since stream 0 is only
376 // used to write HTTP headers, the memory consumption of keeping it in memory 376 // used to write HTTP headers, the memory consumption of keeping it in memory
377 // is acceptable. 377 // is acceptable.
378 scoped_refptr<net::GrowableIOBuffer> stream_0_data_; 378 scoped_refptr<net::GrowableIOBuffer> stream_0_data_;
379 }; 379 };
380 380
381 } // namespace disk_cache 381 } // namespace disk_cache
382 382
383 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_ 383 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698