Index: net/disk_cache/simple/simple_entry_impl.h |
diff --git a/net/disk_cache/simple/simple_entry_impl.h b/net/disk_cache/simple/simple_entry_impl.h |
index 616aaddf7663fadbd28c782a386cd13d436868c6..b241a65fc5170f8d87b409736649a6dba68a77d9 100644 |
--- a/net/disk_cache/simple/simple_entry_impl.h |
+++ b/net/disk_cache/simple/simple_entry_impl.h |
@@ -8,6 +8,7 @@ |
#include <string> |
#include "base/files/file_path.h" |
+#include "base/memory/ref_counted.h" |
#include "base/memory/weak_ptr.h" |
#include "base/threading/thread_checker.h" |
#include "net/disk_cache/disk_cache.h" |
@@ -26,7 +27,8 @@ class SimpleSynchronousEntry; |
// SimpleEntryImpl is the IO thread interface to an entry in the very simple |
// disk cache. It proxies for the SimpleSynchronousEntry, which performs IO |
// on the worker thread. |
-class SimpleEntryImpl : public Entry { |
+class SimpleEntryImpl : public Entry, public base::RefCounted<SimpleEntryImpl> { |
+ friend class base::RefCounted<SimpleEntryImpl>; |
public: |
static int OpenEntry(base::WeakPtr<SimpleIndex> index, |
const base::FilePath& path, |
@@ -80,8 +82,10 @@ class SimpleEntryImpl : public Entry { |
virtual int ReadyForSparseIO(const CompletionCallback& callback) OVERRIDE; |
private: |
- SimpleEntryImpl(SimpleSynchronousEntry* synchronous_entry, |
- base::WeakPtr<SimpleIndex> index); |
+ SimpleEntryImpl(base::WeakPtr<SimpleIndex> index, |
+ const base::FilePath& path, |
+ const std::string& key); |
+ |
virtual ~SimpleEntryImpl(); |
@@ -89,37 +93,40 @@ class SimpleEntryImpl : public Entry { |
// OpenEntry(). Constructs the new SimpleEntryImpl (if |result| is net::OK) |
// and passes it back to the caller via |out_entry|. Also runs |
// |completion_callback|. |
- static void CreationOperationComplete( |
- base::WeakPtr<SimpleIndex> index, |
+ void CreationOperationComplete( |
const CompletionCallback& completion_callback, |
- const std::string& key, |
- Entry** out_entry, |
SimpleSynchronousEntry* sync_entry); |
// Called after a SimpleSynchronousEntry has completed an asynchronous IO |
// operation, such as ReadData() or WriteData(). Calls |completion_callback|. |
- // If |entry| no longer exists, then it ensures |sync_entry| is closed. |
- static void EntryOperationComplete( |
- base::WeakPtr<SimpleIndex> index, |
+ void EntryOperationComplete( |
const CompletionCallback& completion_callback, |
- base::WeakPtr<SimpleEntryImpl> entry, |
- SimpleSynchronousEntry* sync_entry, |
int result); |
+ // Called after a SimpleSynchronousEntry has been successfully created for |
+ // this entry. After this call, the SimpleEntryImpl claims |sync_entry| and |
+ // is responsible for closing it. |
+ void Initialize(SimpleSynchronousEntry* sync_entry); |
+ |
// Called on construction and also after the completion of asynchronous IO to |
// initialize the IO thread copies of data returned by synchronous accessor |
// functions. Copies data from |synchronous_entry_| into |this|, so that |
// values can be returned during our next IO operation. |
void SetSynchronousData(); |
+ // The disk_cache::Entry API requires a self delete on Close(). At the same |
+ // time, we use ref counting to keep the SimpleEntryImpl alive while IO |
+ // operations are pending. This |self_| reference is set to |this| at |
+ // initialization and holds the implicit reference built in to the API. On |
+ // Close(), we set |self_ = NULL| so the Entry will self release after the |
+ // last pending IO operation completes. |
+ scoped_refptr<SimpleEntryImpl> self_; |
+ |
// All nonstatic SimpleEntryImpl methods should always be called on the IO |
// thread, in all cases. |io_thread_checker_| documents and enforces this. |
base::ThreadChecker io_thread_checker_; |
- base::WeakPtrFactory<SimpleEntryImpl> weak_ptr_factory_; |
- |
- // |path_| and |key_| are copied from the synchronous entry on construction, |
- // and never updated as they are const. |
+ const base::WeakPtr<SimpleIndex> index_; |
const base::FilePath path_; |
const std::string key_; |
@@ -140,8 +147,6 @@ class SimpleEntryImpl : public Entry { |
// and false after. Used to ensure thread safety by not allowing multiple |
// threads to access the |synchronous_entry_| simultaneously. |
bool synchronous_entry_in_use_by_worker_; |
- |
- base::WeakPtr<SimpleIndex> index_; |
}; |
} // namespace disk_cache |