OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_ |
| 6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/threading/thread_checker.h" |
| 12 #include "net/disk_cache/disk_cache.h" |
| 13 |
| 14 namespace net { |
| 15 class IOBuffer; |
| 16 } |
| 17 |
| 18 namespace disk_cache { |
| 19 |
| 20 class SimpleSynchronousEntry; |
| 21 |
| 22 // SimpleEntryImpl is the IO thread interface to an entry in the very simple |
| 23 // disk cache. It proxies for the SimpleSynchronousEntry, which performs IO |
| 24 // on the worker thread. |
| 25 class SimpleEntryImpl : public Entry { |
| 26 public: |
| 27 static int OpenEntry(const base::FilePath& path, |
| 28 const std::string& key, |
| 29 Entry** entry, |
| 30 const CompletionCallback& callback); |
| 31 |
| 32 static int CreateEntry(const base::FilePath& path, |
| 33 const std::string& key, |
| 34 Entry** entry, |
| 35 const CompletionCallback& callback); |
| 36 |
| 37 static int DoomEntry(const base::FilePath& path, |
| 38 const std::string& key, |
| 39 const CompletionCallback& callback); |
| 40 |
| 41 // From Entry: |
| 42 virtual void Doom() OVERRIDE; |
| 43 virtual void Close() OVERRIDE; |
| 44 virtual std::string GetKey() const OVERRIDE; |
| 45 virtual base::Time GetLastUsed() const OVERRIDE; |
| 46 virtual base::Time GetLastModified() const OVERRIDE; |
| 47 virtual int32 GetDataSize(int index) const OVERRIDE; |
| 48 virtual int ReadData(int index, |
| 49 int offset, |
| 50 net::IOBuffer* buf, |
| 51 int buf_len, |
| 52 const CompletionCallback& callback) OVERRIDE; |
| 53 virtual int WriteData(int index, |
| 54 int offset, |
| 55 net::IOBuffer* buf, |
| 56 int buf_len, |
| 57 const CompletionCallback& callback, |
| 58 bool truncate) OVERRIDE; |
| 59 virtual int ReadSparseData(int64 offset, |
| 60 net::IOBuffer* buf, |
| 61 int buf_len, |
| 62 const CompletionCallback& callback) OVERRIDE; |
| 63 virtual int WriteSparseData(int64 offset, |
| 64 net::IOBuffer* buf, |
| 65 int buf_len, |
| 66 const CompletionCallback& callback) OVERRIDE; |
| 67 virtual int GetAvailableRange(int64 offset, |
| 68 int len, |
| 69 int64* start, |
| 70 const CompletionCallback& callback) OVERRIDE; |
| 71 virtual bool CouldBeSparse() const OVERRIDE; |
| 72 virtual void CancelSparseIO() OVERRIDE; |
| 73 virtual int ReadyForSparseIO(const CompletionCallback& callback) OVERRIDE; |
| 74 |
| 75 private: |
| 76 class PendingCreationOperation; |
| 77 class PendingEntryOperation; |
| 78 |
| 79 friend class PendingCreationOperation; |
| 80 friend class PendingEntryOperation; |
| 81 |
| 82 explicit SimpleEntryImpl(SimpleSynchronousEntry* synchronous_entry); |
| 83 |
| 84 virtual ~SimpleEntryImpl(); |
| 85 |
| 86 // Clears the current |synchronous_entry_| and returns it. Used when posting |
| 87 // operations on the |synchronous_entry_| to the worker pool. This insures |
| 88 // accesses to |synchronous_entry_| are thread safe from the memory barriers |
| 89 // included in PostTask. |
| 90 SimpleSynchronousEntry* ReleaseSynchronousEntry(); |
| 91 |
| 92 // Sets the current |synchronous_entry_|. Called on completion of worker pool |
| 93 // IO to permit new operations to be launched. |
| 94 void SetSynchronousEntry(SimpleSynchronousEntry* synchronous_entry); |
| 95 |
| 96 base::ThreadChecker thread_checker_; |
| 97 base::WeakPtrFactory<SimpleEntryImpl> weak_ptr_factory_; |
| 98 std::string key_; |
| 99 |
| 100 // The |synchronous_entry_| is the worker thread object that performs IO on |
| 101 // entries. It is set to NULL while operations are pending to prevent unsafe |
| 102 // access from multiple threads. |
| 103 SimpleSynchronousEntry* synchronous_entry_; |
| 104 |
| 105 bool has_been_doomed_; |
| 106 }; |
| 107 |
| 108 } // namespace disk_cache |
| 109 |
| 110 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_ |
OLD | NEW |