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

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

Issue 478573003: Connect SimpleCache Backend active_entries_ more closely to Entry lifetime. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove inline destructor Created 6 years, 4 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 | Annotate | Revision Log
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
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/memory/weak_ptr.h"
15 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
16 #include "net/base/cache_type.h" 15 #include "net/base/cache_type.h"
17 #include "net/base/net_export.h" 16 #include "net/base/net_export.h"
18 #include "net/base/net_log.h" 17 #include "net/base/net_log.h"
19 #include "net/disk_cache/disk_cache.h" 18 #include "net/disk_cache/disk_cache.h"
20 #include "net/disk_cache/simple/simple_entry_format.h" 19 #include "net/disk_cache/simple/simple_entry_format.h"
21 #include "net/disk_cache/simple/simple_entry_operation.h" 20 #include "net/disk_cache/simple/simple_entry_operation.h"
22 21
23 namespace base { 22 namespace base {
24 class TaskRunner; 23 class TaskRunner;
25 } 24 }
26 25
27 namespace net { 26 namespace net {
28 class GrowableIOBuffer; 27 class GrowableIOBuffer;
29 class IOBuffer; 28 class IOBuffer;
30 } 29 }
31 30
32 namespace disk_cache { 31 namespace disk_cache {
33 32
34 class SimpleBackendImpl; 33 class SimpleBackendImpl;
35 class SimpleSynchronousEntry; 34 class SimpleSynchronousEntry;
36 class SimpleEntryStat; 35 class SimpleEntryStat;
37 struct SimpleEntryCreationResults; 36 struct SimpleEntryCreationResults;
38 37
39 // SimpleEntryImpl is the IO thread interface to an entry in the very simple 38 // SimpleEntryImpl is the IO thread interface to an entry in the very simple
40 // disk cache. It proxies for the SimpleSynchronousEntry, which performs IO 39 // disk cache. It proxies for the SimpleSynchronousEntry, which performs IO
41 // on the worker thread. 40 // on the worker thread.
42 class NET_EXPORT_PRIVATE SimpleEntryImpl : public Entry, 41 class NET_EXPORT_PRIVATE SimpleEntryImpl : public Entry,
43 public base::RefCounted<SimpleEntryImpl>, 42 public base::RefCounted<SimpleEntryImpl> {
44 public base::SupportsWeakPtr<SimpleEntryImpl> {
45 friend class base::RefCounted<SimpleEntryImpl>; 43 friend class base::RefCounted<SimpleEntryImpl>;
46 public: 44 public:
47 enum OperationsMode { 45 enum OperationsMode {
48 NON_OPTIMISTIC_OPERATIONS, 46 NON_OPTIMISTIC_OPERATIONS,
49 OPTIMISTIC_OPERATIONS, 47 OPTIMISTIC_OPERATIONS,
50 }; 48 };
51 49
50 // The Backend can provide an instance of BackendDisconnector to an entry, to
51 // allow the entry to remove itself from the Backend for instance when doomed
52 // or destructed.
53 class BackendDisconnector {
54 public:
55 virtual ~BackendDisconnector() = 0;
56 };
57
52 SimpleEntryImpl(net::CacheType cache_type, 58 SimpleEntryImpl(net::CacheType cache_type,
53 const base::FilePath& path, 59 const base::FilePath& path,
54 uint64 entry_hash, 60 uint64 entry_hash,
55 OperationsMode operations_mode, 61 OperationsMode operations_mode,
56 SimpleBackendImpl* backend, 62 SimpleBackendImpl* backend,
57 net::NetLog* net_log); 63 net::NetLog* net_log);
58 64
65 // The provided |backend_disconnector| will be destroyed when this object
66 // no longer is to be managed by its backend.
67 void SetBackendDisconnector(
68 scoped_ptr<BackendDisconnector> backend_disconnector);
69
59 // Adds another reader/writer to this entry, if possible, returning |this| to 70 // Adds another reader/writer to this entry, if possible, returning |this| to
60 // |entry|. 71 // |entry|.
61 int OpenEntry(Entry** entry, const CompletionCallback& callback); 72 int OpenEntry(Entry** entry, const CompletionCallback& callback);
62 73
63 // Creates this entry, if possible. Returns |this| to |entry|. 74 // Creates this entry, if possible. Returns |this| to |entry|.
64 int CreateEntry(Entry** entry, const CompletionCallback& callback); 75 int CreateEntry(Entry** entry, const CompletionCallback& callback);
65 76
66 // Identical to Backend::Doom() except that it accepts a CompletionCallback. 77 // Identical to Backend::Doom() except that it accepts a CompletionCallback.
67 int DoomEntry(const CompletionCallback& callback); 78 int DoomEntry(const CompletionCallback& callback);
68 79
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 int offset, int buf_len, 301 int offset, int buf_len,
291 bool truncate); 302 bool truncate);
292 303
293 // Updates |crc32s_| and |crc32s_end_offset_| for a write of the data in 304 // Updates |crc32s_| and |crc32s_end_offset_| for a write of the data in
294 // |buffer| on |stream_index|, starting at |offset| and of length |length|. 305 // |buffer| on |stream_index|, starting at |offset| and of length |length|.
295 void AdvanceCrc(net::IOBuffer* buffer, 306 void AdvanceCrc(net::IOBuffer* buffer,
296 int offset, 307 int offset,
297 int length, 308 int length,
298 int stream_index); 309 int stream_index);
299 310
311 // The |backend_disconnector_| is among our first methods to insure that the
Deprecated (see juliatuttle) 2014/08/22 19:26:38 This is a field, not a method, and isn't destructi
gavinp 2014/08/25 13:18:27 Removed this comment. And I think its placement is
312 // entry removes itself from the backend early.
313 scoped_ptr<BackendDisconnector> backend_disconnector_;
314
300 // All nonstatic SimpleEntryImpl methods should always be called on the IO 315 // All nonstatic SimpleEntryImpl methods should always be called on the IO
301 // thread, in all cases. |io_thread_checker_| documents and enforces this. 316 // thread, in all cases. |io_thread_checker_| documents and enforces this.
302 base::ThreadChecker io_thread_checker_; 317 base::ThreadChecker io_thread_checker_;
303 318
304 const base::WeakPtr<SimpleBackendImpl> backend_; 319 const base::WeakPtr<SimpleBackendImpl> backend_;
305 const net::CacheType cache_type_; 320 const net::CacheType cache_type_;
306 const scoped_refptr<base::TaskRunner> worker_pool_; 321 const scoped_refptr<base::TaskRunner> worker_pool_;
307 const base::FilePath path_; 322 const base::FilePath path_;
308 const uint64 entry_hash_; 323 const uint64 entry_hash_;
309 const bool use_optimistic_operations_; 324 const bool use_optimistic_operations_;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 // 1 on disk, to reduce the number of file descriptors and save disk space. 378 // 1 on disk, to reduce the number of file descriptors and save disk space.
364 // This strategy allows stream 1 to change size easily. Since stream 0 is only 379 // This strategy allows stream 1 to change size easily. Since stream 0 is only
365 // used to write HTTP headers, the memory consumption of keeping it in memory 380 // used to write HTTP headers, the memory consumption of keeping it in memory
366 // is acceptable. 381 // is acceptable.
367 scoped_refptr<net::GrowableIOBuffer> stream_0_data_; 382 scoped_refptr<net::GrowableIOBuffer> stream_0_data_;
368 }; 383 };
369 384
370 } // namespace disk_cache 385 } // namespace disk_cache
371 386
372 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_ 387 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698