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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 // OpenEntry(). Constructs the new SimpleEntryImpl (if |result| is net::OK) | 82 // OpenEntry(). Constructs the new SimpleEntryImpl (if |result| is net::OK) |
83 // and passes it back to the caller via |out_entry|. Also runs | 83 // and passes it back to the caller via |out_entry|. Also runs |
84 // |completion_callback|. | 84 // |completion_callback|. |
85 static void CreationOperationComplete( | 85 static void CreationOperationComplete( |
86 const CompletionCallback& completion_callback, | 86 const CompletionCallback& completion_callback, |
87 Entry** out_entry, | 87 Entry** out_entry, |
88 SimpleSynchronousEntry* sync_entry); | 88 SimpleSynchronousEntry* sync_entry); |
89 | 89 |
90 // Called after a SimpleSynchronousEntry has completed an asynchronous IO | 90 // Called after a SimpleSynchronousEntry has completed an asynchronous IO |
91 // operation, such as ReadData() or WriteData(). Calls |completion_callback|. | 91 // operation, such as ReadData() or WriteData(). Calls |completion_callback|. |
92 // If |entry| no longer exists, then it ensures |sync_entry| is closed. | |
92 static void EntryOperationComplete( | 93 static void EntryOperationComplete( |
93 const CompletionCallback& completion_callback, | 94 const CompletionCallback& completion_callback, |
94 base::WeakPtr<SimpleEntryImpl> entry, | 95 base::WeakPtr<SimpleEntryImpl> entry, |
96 SimpleSynchronousEntry* sync_entry, | |
95 int result); | 97 int result); |
96 | 98 |
97 // Called on construction and also after the completion of asynchronous IO to | 99 // Called on construction and also after the completion of asynchronous IO to |
98 // initialize the IO thread copies of data returned by synchronous accessor | 100 // initialize the IO thread copies of data returned by synchronous accessor |
99 // functions. Copies data from |synchronous_entry_| into |this|, so that | 101 // functions. Copies data from |synchronous_entry_| into |this|, so that |
100 // values can be returned during our next IO operation. | 102 // values can be returned during our next IO operation. |
101 void SetSynchronousData(); | 103 void SetSynchronousData(); |
102 | 104 |
103 base::WeakPtrFactory<SimpleEntryImpl> weak_ptr_factory_; | 105 base::WeakPtrFactory<SimpleEntryImpl> weak_ptr_factory_; |
104 | 106 |
105 // |path_| and |key_| are copied from the synchronous entry on construction, | 107 // |path_| and |key_| are copied from the synchronous entry on construction, |
106 // and never updated as they are const. | 108 // and never updated as they are const. |
107 const base::FilePath path_; | 109 const base::FilePath path_; |
108 const std::string key_; | 110 const std::string key_; |
109 | 111 |
110 // |last_used_|, |last_modified_| and |data_size_| are copied from the | 112 // |last_used_|, |last_modified_| and |data_size_| are copied from the |
111 // synchronous entry at the completion of each item of asynchronous IO. | 113 // synchronous entry at the completion of each item of asynchronous IO. |
112 base::Time last_used_; | 114 base::Time last_used_; |
113 base::Time last_modified_; | 115 base::Time last_modified_; |
114 int32 data_size_[kSimpleEntryFileCount]; | 116 int32 data_size_[kSimpleEntryFileCount]; |
115 | 117 |
116 // The |synchronous_entry_| is the worker thread object that performs IO on | 118 // The |synchronous_entry_| is the worker thread object that performs IO on |
117 // entries. | 119 // entries. It's owned by this SimpleEntryImpl, which is responsible for its |
120 // destruction by calling SimpleSynchronousEntry::Close(). However, since | |
121 // |this| can be destroyed while a synchronous operation is completing, the | |
122 // |synchronous_entry_| must sometimes be destroyed when an operation | |
123 // completes and finds its owning SimpleEntryImpl has already been destroyed. | |
Randy Smith (Not in Mondays)
2013/02/26 21:13:12
So the way I read the code / another way to phrase
gavinp
2013/02/27 21:50:02
I like the way you wrote that ownership, so I've f
| |
118 SimpleSynchronousEntry* synchronous_entry_; | 124 SimpleSynchronousEntry* synchronous_entry_; |
119 | 125 |
120 // Set to true when a worker operation is posted on the |synchronous_entry_|, | 126 // Set to true when a worker operation is posted on the |synchronous_entry_|, |
121 // and false after. Used to insure thread safety by not allowing multiple | 127 // and false after. Used to insure thread safety by not allowing multiple |
122 // threads to access the |synchronous_entry_| simultaneously. | 128 // threads to access the |synchronous_entry_| simultaneously. |
123 bool synchronous_entry_in_use_by_worker_; | 129 bool synchronous_entry_in_use_by_worker_; |
124 }; | 130 }; |
125 | 131 |
126 } // namespace disk_cache | 132 } // namespace disk_cache |
127 | 133 |
128 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_ | 134 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_ |
OLD | NEW |