OLD | NEW |
---|---|
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 <string> | 8 #include <string> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 class IOBuffer; | 22 class IOBuffer; |
23 } | 23 } |
24 | 24 |
25 namespace disk_cache { | 25 namespace disk_cache { |
26 | 26 |
27 class SimpleSynchronousEntry; | 27 class SimpleSynchronousEntry; |
28 | 28 |
29 // SimpleEntryImpl is the IO thread interface to an entry in the very simple | 29 // SimpleEntryImpl is the IO thread interface to an entry in the very simple |
30 // disk cache. It proxies for the SimpleSynchronousEntry, which performs IO | 30 // disk cache. It proxies for the SimpleSynchronousEntry, which performs IO |
31 // on the worker thread. | 31 // on the worker thread. |
32 | |
rvargas (doing something else)
2013/04/18 17:31:50
nit: extra line
| |
32 class SimpleEntryImpl : public Entry, | 33 class SimpleEntryImpl : public Entry, |
33 public base::RefCountedThreadSafe<SimpleEntryImpl> { | 34 public base::RefCountedThreadSafe<SimpleEntryImpl> { |
34 friend class base::RefCountedThreadSafe<SimpleEntryImpl>; | 35 friend class base::RefCountedThreadSafe<SimpleEntryImpl>; |
35 public: | 36 public: |
36 static int OpenEntry(const scoped_refptr<SimpleIndex>& index, | 37 static int OpenEntry(SimpleIndex* index, |
37 const base::FilePath& path, | 38 const base::FilePath& path, |
38 const std::string& key, | 39 const std::string& key, |
39 Entry** entry, | 40 Entry** entry, |
40 const CompletionCallback& callback); | 41 const CompletionCallback& callback); |
41 | 42 |
42 static int CreateEntry(const scoped_refptr<SimpleIndex>& index, | 43 static int CreateEntry(SimpleIndex* index, |
43 const base::FilePath& path, | 44 const base::FilePath& path, |
44 const std::string& key, | 45 const std::string& key, |
45 Entry** entry, | 46 Entry** entry, |
46 const CompletionCallback& callback); | 47 const CompletionCallback& callback); |
47 | 48 |
48 static int DoomEntry(const scoped_refptr<SimpleIndex>& index, | 49 static int DoomEntry(SimpleIndex* index, |
49 const base::FilePath& path, | 50 const base::FilePath& path, |
50 const std::string& key, | 51 const std::string& key, |
51 const CompletionCallback& callback); | 52 const CompletionCallback& callback); |
52 | 53 |
53 // From Entry: | 54 // From Entry: |
54 virtual void Doom() OVERRIDE; | 55 virtual void Doom() OVERRIDE; |
55 virtual void Close() OVERRIDE; | 56 virtual void Close() OVERRIDE; |
56 virtual std::string GetKey() const OVERRIDE; | 57 virtual std::string GetKey() const OVERRIDE; |
57 virtual base::Time GetLastUsed() const OVERRIDE; | 58 virtual base::Time GetLastUsed() const OVERRIDE; |
58 virtual base::Time GetLastModified() const OVERRIDE; | 59 virtual base::Time GetLastModified() const OVERRIDE; |
(...skipping 19 matching lines...) Expand all Loading... | |
78 const CompletionCallback& callback) OVERRIDE; | 79 const CompletionCallback& callback) OVERRIDE; |
79 virtual int GetAvailableRange(int64 offset, | 80 virtual int GetAvailableRange(int64 offset, |
80 int len, | 81 int len, |
81 int64* start, | 82 int64* start, |
82 const CompletionCallback& callback) OVERRIDE; | 83 const CompletionCallback& callback) OVERRIDE; |
83 virtual bool CouldBeSparse() const OVERRIDE; | 84 virtual bool CouldBeSparse() const OVERRIDE; |
84 virtual void CancelSparseIO() OVERRIDE; | 85 virtual void CancelSparseIO() OVERRIDE; |
85 virtual int ReadyForSparseIO(const CompletionCallback& callback) OVERRIDE; | 86 virtual int ReadyForSparseIO(const CompletionCallback& callback) OVERRIDE; |
86 | 87 |
87 private: | 88 private: |
88 SimpleEntryImpl(const scoped_refptr<SimpleIndex>& index, | 89 SimpleEntryImpl(SimpleIndex* index, |
89 const base::FilePath& path, | 90 const base::FilePath& path, |
90 const std::string& key); | 91 const std::string& key); |
91 | 92 |
92 virtual ~SimpleEntryImpl(); | 93 virtual ~SimpleEntryImpl(); |
93 | 94 |
94 // Called after a SimpleSynchronousEntry has completed CreateEntry() or | 95 // Called after a SimpleSynchronousEntry has completed CreateEntry() or |
95 // OpenEntry(). If |sync_entry| is non-NULL, creation is successful and we | 96 // OpenEntry(). If |sync_entry| is non-NULL, creation is successful and we |
96 // can return |this| SimpleEntryImpl to |*out_entry|. Runs | 97 // can return |this| SimpleEntryImpl to |*out_entry|. Runs |
97 // |completion_callback|. | 98 // |completion_callback|. |
98 void CreationOperationComplete( | 99 void CreationOperationComplete( |
(...skipping 10 matching lines...) Expand all Loading... | |
109 // Called on initialization and also after the completion of asynchronous IO | 110 // Called on initialization and also after the completion of asynchronous IO |
110 // to initialize the IO thread copies of data returned by synchronous accessor | 111 // to initialize the IO thread copies of data returned by synchronous accessor |
111 // functions. Copies data from |synchronous_entry_| into |this|, so that | 112 // functions. Copies data from |synchronous_entry_| into |this|, so that |
112 // values can be returned during our next IO operation. | 113 // values can be returned during our next IO operation. |
113 void SetSynchronousData(); | 114 void SetSynchronousData(); |
114 | 115 |
115 // All nonstatic SimpleEntryImpl methods should always be called on the IO | 116 // All nonstatic SimpleEntryImpl methods should always be called on the IO |
116 // thread, in all cases. |io_thread_checker_| documents and enforces this. | 117 // thread, in all cases. |io_thread_checker_| documents and enforces this. |
117 base::ThreadChecker io_thread_checker_; | 118 base::ThreadChecker io_thread_checker_; |
118 | 119 |
119 const scoped_refptr<base::MessageLoopProxy> constructor_thread_; | 120 const scoped_refptr<base::SingleThreadTaskRunner> constructor_thread_; |
120 const scoped_refptr<SimpleIndex> index_; | 121 const base::WeakPtr<SimpleIndex> index_; |
121 const base::FilePath path_; | 122 const base::FilePath path_; |
122 const std::string key_; | 123 const std::string key_; |
123 | 124 |
124 // |last_used_|, |last_modified_| and |data_size_| are copied from the | 125 // |last_used_|, |last_modified_| and |data_size_| are copied from the |
125 // synchronous entry at the completion of each item of asynchronous IO. | 126 // synchronous entry at the completion of each item of asynchronous IO. |
126 base::Time last_used_; | 127 base::Time last_used_; |
127 base::Time last_modified_; | 128 base::Time last_modified_; |
128 int32 data_size_[kSimpleEntryFileCount]; | 129 int32 data_size_[kSimpleEntryFileCount]; |
129 | 130 |
130 // The |synchronous_entry_| is the worker thread object that performs IO on | 131 // The |synchronous_entry_| is the worker thread object that performs IO on |
131 // entries. It's owned by this SimpleEntryImpl whenever | 132 // entries. It's owned by this SimpleEntryImpl whenever |
132 // |synchronous_entry_in_use_by_worker_| is false (i.e. when an operation | 133 // |synchronous_entry_in_use_by_worker_| is false (i.e. when an operation |
133 // is not pending on the worker pool). When an operation is pending on the | 134 // is not pending on the worker pool). When an operation is pending on the |
134 // worker pool, the |synchronous_entry_| is owned by itself. | 135 // worker pool, the |synchronous_entry_| is owned by itself. |
135 SimpleSynchronousEntry* synchronous_entry_; | 136 SimpleSynchronousEntry* synchronous_entry_; |
136 | 137 |
137 // Set to true when a worker operation is posted on the |synchronous_entry_|, | 138 // Set to true when a worker operation is posted on the |synchronous_entry_|, |
138 // and false after. Used to ensure thread safety by not allowing multiple | 139 // and false after. Used to ensure thread safety by not allowing multiple |
139 // threads to access the |synchronous_entry_| simultaneously. | 140 // threads to access the |synchronous_entry_| simultaneously. |
140 bool synchronous_entry_in_use_by_worker_; | 141 bool synchronous_entry_in_use_by_worker_; |
141 }; | 142 }; |
142 | 143 |
143 } // namespace disk_cache | 144 } // namespace disk_cache |
144 | 145 |
145 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_ | 146 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_ |
OLD | NEW |