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 <queue> | |
8 #include <string> | 9 #include <string> |
9 | 10 |
10 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
12 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
13 #include "net/disk_cache/disk_cache.h" | 14 #include "net/disk_cache/disk_cache.h" |
14 #include "net/disk_cache/simple/simple_entry_format.h" | 15 #include "net/disk_cache/simple/simple_entry_format.h" |
15 #include "net/disk_cache/simple/simple_index.h" | 16 #include "net/disk_cache/simple/simple_index.h" |
16 | 17 |
17 | 18 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 virtual bool CouldBeSparse() const OVERRIDE; | 79 virtual bool CouldBeSparse() const OVERRIDE; |
79 virtual void CancelSparseIO() OVERRIDE; | 80 virtual void CancelSparseIO() OVERRIDE; |
80 virtual int ReadyForSparseIO(const CompletionCallback& callback) OVERRIDE; | 81 virtual int ReadyForSparseIO(const CompletionCallback& callback) OVERRIDE; |
81 | 82 |
82 private: | 83 private: |
83 SimpleEntryImpl(SimpleSynchronousEntry* synchronous_entry, | 84 SimpleEntryImpl(SimpleSynchronousEntry* synchronous_entry, |
84 base::WeakPtr<SimpleIndex> index); | 85 base::WeakPtr<SimpleIndex> index); |
85 | 86 |
86 virtual ~SimpleEntryImpl(); | 87 virtual ~SimpleEntryImpl(); |
87 | 88 |
89 // Runs next operation in the queue, if any and if there is no other operation | |
gavinp
2013/04/17 13:13:45
Nit: "Runs _the_ next", and also "if and _only_ if
felipeg
2013/04/17 13:34:18
Done.
| |
90 // running at the moment. Returns true if a operation has run. | |
gavinp
2013/04/17 13:13:45
What is this return value used for?
felipeg
2013/04/17 13:34:18
It will be used to implement the optimistic writes
| |
91 bool RunNextOperationIfNeeded(); | |
92 | |
93 void ReadDataInternal(int index, | |
94 int offset, | |
95 scoped_refptr<net::IOBuffer> buf, | |
96 int buf_len, | |
97 const CompletionCallback& callback); | |
98 | |
99 void WriteDataInternal(int index, | |
100 int offset, | |
101 scoped_refptr<net::IOBuffer> buf, | |
102 int buf_len, | |
103 const CompletionCallback& callback, | |
104 bool truncate); | |
105 | |
88 // Called after a SimpleSynchronousEntry has completed CreateEntry() or | 106 // Called after a SimpleSynchronousEntry has completed CreateEntry() or |
89 // OpenEntry(). Constructs the new SimpleEntryImpl (if |result| is net::OK) | 107 // OpenEntry(). Constructs the new SimpleEntryImpl (if |result| is net::OK) |
90 // and passes it back to the caller via |out_entry|. Also runs | 108 // and passes it back to the caller via |out_entry|. Also runs |
91 // |completion_callback|. | 109 // |completion_callback|. |
92 static void CreationOperationComplete( | 110 static void CreationOperationComplete( |
93 base::WeakPtr<SimpleIndex> index, | 111 base::WeakPtr<SimpleIndex> index, |
94 const CompletionCallback& completion_callback, | 112 const CompletionCallback& completion_callback, |
95 const std::string& key, | 113 const std::string& key, |
96 Entry** out_entry, | 114 Entry** out_entry, |
97 SimpleSynchronousEntry* sync_entry); | 115 SimpleSynchronousEntry* sync_entry); |
(...skipping 25 matching lines...) Expand all Loading... | |
123 const base::FilePath path_; | 141 const base::FilePath path_; |
124 const std::string key_; | 142 const std::string key_; |
125 | 143 |
126 // |last_used_|, |last_modified_| and |data_size_| are copied from the | 144 // |last_used_|, |last_modified_| and |data_size_| are copied from the |
127 // synchronous entry at the completion of each item of asynchronous IO. | 145 // synchronous entry at the completion of each item of asynchronous IO. |
128 base::Time last_used_; | 146 base::Time last_used_; |
129 base::Time last_modified_; | 147 base::Time last_modified_; |
130 int32 data_size_[kSimpleEntryFileCount]; | 148 int32 data_size_[kSimpleEntryFileCount]; |
131 | 149 |
132 // The |synchronous_entry_| is the worker thread object that performs IO on | 150 // The |synchronous_entry_| is the worker thread object that performs IO on |
133 // entries. It's owned by this SimpleEntryImpl whenever | 151 // entries. It's owned by this SimpleEntryImpl whenever |operation_running_| |
134 // |synchronous_entry_in_use_by_worker_| is false (i.e. when an operation | 152 // is false (i.e. when an operation is not pending on the worker pool). When |
135 // is not pending on the worker pool). When an operation is pending on the | 153 // an operation is pending on the worker pool, the |synchronous_entry_| is |
gavinp
2013/04/17 13:13:45
While we're here, the last sentence of this commen
felipeg
2013/04/17 13:34:18
Done.
| |
136 // worker pool, the |synchronous_entry_| is owned by itself. | 154 // owned by itself. |
137 SimpleSynchronousEntry* synchronous_entry_; | 155 SimpleSynchronousEntry* synchronous_entry_; |
138 | 156 |
139 // Set to true when a worker operation is posted on the |synchronous_entry_|, | 157 // Set to true when a worker operation is posted on the |synchronous_entry_|, |
140 // and false after. Used to ensure thread safety by not allowing multiple | 158 // and false after. Used to ensure thread safety by not allowing multiple |
141 // threads to access the |synchronous_entry_| simultaneously. | 159 // threads to access the |synchronous_entry_| simultaneously. |
142 bool synchronous_entry_in_use_by_worker_; | 160 bool operation_running_; |
161 std::queue<base::Closure> operations_; | |
gavinp
2013/04/17 13:13:45
pending_operations_ ?
felipeg
2013/04/17 13:34:18
Done.
| |
143 | 162 |
144 base::WeakPtr<SimpleIndex> index_; | 163 base::WeakPtr<SimpleIndex> index_; |
145 }; | 164 }; |
146 | 165 |
147 } // namespace disk_cache | 166 } // namespace disk_cache |
148 | 167 |
149 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_ | 168 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_ |
OLD | NEW |