Index: net/disk_cache/flash/flash_entry_impl.h |
diff --git a/net/disk_cache/flash/flash_entry_impl.h b/net/disk_cache/flash/flash_entry_impl.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2901347c14483756a4b4d7d2c041267c21981125 |
--- /dev/null |
+++ b/net/disk_cache/flash/flash_entry_impl.h |
@@ -0,0 +1,104 @@ |
+// Copyright (c) 2012 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_FLASH_ENTRY_IMPL_H_ |
+#define NET_DISK_CACHE_FLASH_ENTRY_IMPL_H_ |
+ |
+#include <string> |
+ |
+#include "base/memory/ref_counted.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "net/base/net_export.h" |
+#include "net/disk_cache/disk_cache.h" |
+#include "net/disk_cache/flash/internal_entry.h" |
+ |
+namespace base { |
+ |
+class MessageLoopProxy; |
+ |
+} // namespace base |
+ |
+namespace disk_cache { |
+ |
+class InternalEntry; |
+class IOBuffer; |
+class LogStore; |
+ |
+// Context switches are slow on Android. In order to minimize the context |
rvargas (doing something else)
2013/04/05 18:15:41
nit: Remove the first sentence?. It is vague and e
agayev
2013/04/05 22:26:45
Done.
|
+// switches between IOThread and CacheThread, this disk_cache::Entry |
rvargas (doing something else)
2013/04/05 18:15:41
This layer doesn't know anything about IO or Cache
agayev
2013/04/05 22:26:45
Done.
|
+// implementation uses split objects to optimize the most common case, that is |
+// creating a new entry. |
rvargas (doing something else)
2013/04/05 18:15:41
creating a new entry is the most common case? that
agayev
2013/04/05 22:26:45
Done, I think :)
|
+// |
+// All asynchronous function calls on a new entry are served from IOThread |
rvargas (doing something else)
2013/04/05 18:15:41
nit: All calls are served synchronously.
agayev
2013/04/05 22:26:45
Done.
|
+// synchronously. When an object is destructed (via final Close() call), a |
+// message is posted to CacheThread to save the object to storage. |
+// |
+// When an entry is not new, every asynchronous call is posted to CacheThread, |
+// just as before; synchronous calls like GetKey() and GetDataSize() are served |
+// from the IOThread. |
+class NET_EXPORT_PRIVATE FlashEntryImpl |
+ : public Entry, |
+ public base::RefCountedThreadSafe<FlashEntryImpl> { |
+ friend class base::RefCountedThreadSafe<FlashEntryImpl>; |
+ public: |
+ FlashEntryImpl(const std::string& key, |
+ LogStore* store, |
+ base::MessageLoopProxy* cache_thread); |
+ FlashEntryImpl(int32 id, |
+ LogStore* store, |
+ base::MessageLoopProxy* cache_thread); |
+ |
+ int Init(const CompletionCallback& callback); |
+ |
+ // disk_cache::Entry interface. |
+ 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, IOBuffer* buf, int buf_len, |
+ const CompletionCallback& callback) OVERRIDE; |
+ virtual int WriteData(int index, int offset, IOBuffer* buf, int buf_len, |
+ const CompletionCallback& callback, |
+ bool truncate) OVERRIDE; |
+ virtual int ReadSparseData(int64 offset, IOBuffer* buf, int buf_len, |
+ const CompletionCallback& callback) OVERRIDE; |
+ virtual int WriteSparseData(int64 offset, 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: |
+ void OnInitComplete(scoped_ptr<KeyAndStreamSizes> key_and_stream_sizes); |
+ virtual ~FlashEntryImpl(); |
+ |
+ bool init_; |
+ std::string key_; |
+ |
+ // Used if |this| is an newly created entry. |
+ scoped_refptr<InternalEntry> new_internal_entry_; |
+ |
+ // Used if |this| is an existing entry. |
+ scoped_refptr<InternalEntry> old_internal_entry_; |
+ |
+ // Used if |this| is an existing entry. It is initialized once during Init(), |
rvargas (doing something else)
2013/04/05 18:15:41
So... it is not used for new entries?. It is initi
agayev
2013/04/05 22:26:45
Done. I was going to use it for old entry only, b
|
+ // and updated every time there is a successful WriteData() to |
+ // |old_internal_entry_|. |
+ int stream_sizes_[kFlashLogStoreEntryNumStreams]; |
+ |
+ // Copy of the callback for asynchronous calls on |old_internal_entry_|. |
+ CompletionCallback callback_; |
+ |
+ scoped_refptr<base::MessageLoopProxy> cache_thread_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(FlashEntryImpl); |
+}; |
+ |
+} // namespace disk_cache |
+ |
+#endif // NET_DISK_CACHE_FLASH_ENTRY_IMPL_H_ |