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

Unified Diff: net/disk_cache/simple/simple_entry_impl.h

Issue 12192005: Add new simple disk cache backend. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix dcheck Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
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
new file mode 100644
index 0000000000000000000000000000000000000000..a6f642eb10c83d048fdb2a6c68f310d3287155e6
--- /dev/null
+++ b/net/disk_cache/simple/simple_entry_impl.h
@@ -0,0 +1,110 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_
+#define NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_
+
+#include <string>
+
+#include "base/memory/weak_ptr.h"
+#include "base/threading/thread_checker.h"
+#include "net/disk_cache/disk_cache.h"
+
+namespace net {
+class IOBuffer;
+}
+
+namespace disk_cache {
+
+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 {
+ public:
+ static int OpenEntry(const base::FilePath& path,
+ const std::string& key,
+ Entry** entry,
+ const CompletionCallback& callback);
+
+ static int CreateEntry(const base::FilePath& path,
+ const std::string& key,
+ Entry** entry,
+ const CompletionCallback& callback);
+
+ static int DoomEntry(const base::FilePath& path,
+ const std::string& key,
+ const CompletionCallback& callback);
+
+ // From Entry:
+ virtual void Doom() OVERRIDE;
+ virtual void Close() OVERRIDE;
+ virtual std::string GetKey() const OVERRIDE;
+ virtual base::Time GetLastUsed() const OVERRIDE;
+ virtual base::Time GetLastModified() const OVERRIDE;
+ virtual int32 GetDataSize(int index) const OVERRIDE;
+ virtual int ReadData(int index,
+ int offset,
+ net::IOBuffer* buf,
+ int buf_len,
+ const CompletionCallback& callback) OVERRIDE;
+ virtual int WriteData(int index,
+ int offset,
+ net::IOBuffer* buf,
+ int buf_len,
+ const CompletionCallback& callback,
+ bool truncate) OVERRIDE;
+ virtual int ReadSparseData(int64 offset,
+ net::IOBuffer* buf,
+ int buf_len,
+ const CompletionCallback& callback) OVERRIDE;
+ virtual int WriteSparseData(int64 offset,
+ net::IOBuffer* buf,
+ int buf_len,
+ const CompletionCallback& callback) OVERRIDE;
+ virtual int GetAvailableRange(int64 offset,
+ int len,
+ int64* start,
+ const CompletionCallback& callback) OVERRIDE;
+ virtual bool CouldBeSparse() const OVERRIDE;
+ virtual void CancelSparseIO() OVERRIDE;
+ virtual int ReadyForSparseIO(const CompletionCallback& callback) OVERRIDE;
+
+ private:
+ class PendingCreationOperation;
+ class PendingEntryOperation;
+
+ friend class PendingCreationOperation;
+ friend class PendingEntryOperation;
+
+ explicit SimpleEntryImpl(SimpleSynchronousEntry* synchronous_entry);
+
+ virtual ~SimpleEntryImpl();
+
+ // Clears the current |synchronous_entry_| and returns it. Used when posting
+ // operations on the |synchronous_entry_| to the worker pool. This insures
felipeg 2013/02/12 13:25:20 s/insures/ensures/
gavinp 2013/02/12 15:45:57 Done.
+ // accesses to |synchronous_entry_| are thread safe from the memory barriers
+ // included in PostTask.
+ SimpleSynchronousEntry* ReleaseSynchronousEntry();
+
+ // Sets the current |synchronous_entry_|. Called on completion of worker pool
+ // IO to permit new operations to be launched.
+ void SetSynchronousEntry(SimpleSynchronousEntry* synchronous_entry);
+
+ base::ThreadChecker thread_checker_;
+ base::WeakPtrFactory<SimpleEntryImpl> weak_ptr_factory_;
+ std::string key_;
+
+ // The |synchronous_entry_| is the worker thread object that performs IO on
+ // entries. It is set to NULL while operations are pending to prevent unsafe
+ // access from multiple threads.
+ SimpleSynchronousEntry* synchronous_entry_;
+
+ bool has_been_doomed_;
+};
+
+} // namespace disk_cache
+
+#endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_

Powered by Google App Engine
This is Rietveld 408576698