| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_SPARSE_CONTROL_H_ | 5 #ifndef NET_DISK_CACHE_SPARSE_CONTROL_H_ |
| 6 #define NET_DISK_CACHE_SPARSE_CONTROL_H_ | 6 #define NET_DISK_CACHE_SPARSE_CONTROL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 12 #include "net/base/completion_callback.h" | 13 #include "net/base/completion_callback.h" |
| 13 #include "net/disk_cache/bitmap.h" | 14 #include "net/disk_cache/bitmap.h" |
| 14 #include "net/disk_cache/disk_format.h" | 15 #include "net/disk_cache/disk_format.h" |
| 15 | 16 |
| 16 namespace net { | 17 namespace net { |
| 17 class IOBuffer; | 18 class IOBuffer; |
| 18 class ReusedIOBuffer; | 19 class ReusedIOBuffer; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 // |buf_len| specify the actual data to use and |callback| is the callback | 57 // |buf_len| specify the actual data to use and |callback| is the callback |
| 57 // to use for asynchronous operations. See the description of the Read / | 58 // to use for asynchronous operations. See the description of the Read / |
| 58 // WriteSparseData for details about the arguments. The return value is the | 59 // WriteSparseData for details about the arguments. The return value is the |
| 59 // number of bytes read or written, or a net error code. | 60 // number of bytes read or written, or a net error code. |
| 60 int StartIO(SparseOperation op, int64 offset, net::IOBuffer* buf, | 61 int StartIO(SparseOperation op, int64 offset, net::IOBuffer* buf, |
| 61 int buf_len, net::CompletionCallback* callback); | 62 int buf_len, net::CompletionCallback* callback); |
| 62 | 63 |
| 63 // Implements Entry::GetAvailableRange(). | 64 // Implements Entry::GetAvailableRange(). |
| 64 int GetAvailableRange(int64 offset, int len, int64* start); | 65 int GetAvailableRange(int64 offset, int len, int64* start); |
| 65 | 66 |
| 67 // Cancels the current sparse operation (if any). |
| 68 void CancelIO(); |
| 69 |
| 70 // Returns OK if the entry can be used for new IO or ERR_IO_PENDING if we are |
| 71 // busy. If the entry is busy, we'll invoke the callback when we are ready |
| 72 // again. See disk_cache::Entry::ReadyToUse() for more info. |
| 73 int ReadyToUse(net::CompletionCallback* completion_callback); |
| 74 |
| 66 // Deletes the children entries of |entry|. | 75 // Deletes the children entries of |entry|. |
| 67 static void DeleteChildren(EntryImpl* entry); | 76 static void DeleteChildren(EntryImpl* entry); |
| 68 | 77 |
| 69 private: | 78 private: |
| 70 // Creates a new sparse entry or opens an aready created entry from disk. | 79 // Creates a new sparse entry or opens an aready created entry from disk. |
| 71 // These methods just read / write the required info from disk for the current | 80 // These methods just read / write the required info from disk for the current |
| 72 // entry, and verify that everything is correct. The return value is a net | 81 // entry, and verify that everything is correct. The return value is a net |
| 73 // error code. | 82 // error code. |
| 74 int CreateSparseEntry(); | 83 int CreateSparseEntry(); |
| 75 int OpenSparseEntry(int data_len); | 84 int OpenSparseEntry(int data_len); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 int DoGetAvailableRange(); | 136 int DoGetAvailableRange(); |
| 128 | 137 |
| 129 // Performs the required work after a single IO operations finishes. | 138 // Performs the required work after a single IO operations finishes. |
| 130 void DoChildIOCompleted(int result); | 139 void DoChildIOCompleted(int result); |
| 131 | 140 |
| 132 // Invoked by the callback of asynchronous operations. | 141 // Invoked by the callback of asynchronous operations. |
| 133 void OnChildIOCompleted(int result); | 142 void OnChildIOCompleted(int result); |
| 134 | 143 |
| 135 // Reports to the user that we are done. | 144 // Reports to the user that we are done. |
| 136 void DoUserCallback(); | 145 void DoUserCallback(); |
| 146 void DoAbortCallbacks(); |
| 137 | 147 |
| 138 EntryImpl* entry_; // The sparse entry. | 148 EntryImpl* entry_; // The sparse entry. |
| 139 Entry* child_; // The current child entry. | 149 Entry* child_; // The current child entry. |
| 140 SparseOperation operation_; | 150 SparseOperation operation_; |
| 141 bool pending_; // True if any child IO operation returned pending. | 151 bool pending_; // True if any child IO operation returned pending. |
| 142 bool finished_; | 152 bool finished_; |
| 143 bool init_; | 153 bool init_; |
| 144 bool range_found_; // True if GetAvailableRange found something. | 154 bool range_found_; // True if GetAvailableRange found something. |
| 155 bool abort_; // True if we should abort the current operation ASAP. |
| 145 | 156 |
| 146 SparseHeader sparse_header_; // Data about the children of entry_. | 157 SparseHeader sparse_header_; // Data about the children of entry_. |
| 147 Bitmap children_map_; // The actual bitmap of children. | 158 Bitmap children_map_; // The actual bitmap of children. |
| 148 SparseData child_data_; // Parent and allocation map of child_. | 159 SparseData child_data_; // Parent and allocation map of child_. |
| 149 Bitmap child_map_; // The allocation map as a bitmap. | 160 Bitmap child_map_; // The allocation map as a bitmap. |
| 150 | 161 |
| 151 net::CompletionCallbackImpl<SparseControl> child_callback_; | 162 net::CompletionCallbackImpl<SparseControl> child_callback_; |
| 152 net::CompletionCallback* user_callback_; | 163 net::CompletionCallback* user_callback_; |
| 164 std::vector<net::CompletionCallback*> abort_callbacks_; |
| 153 int64 offset_; // Current sparse offset. | 165 int64 offset_; // Current sparse offset. |
| 154 scoped_refptr<net::ReusedIOBuffer> user_buf_; | 166 scoped_refptr<net::ReusedIOBuffer> user_buf_; |
| 155 int buf_len_; // Bytes to read or write. | 167 int buf_len_; // Bytes to read or write. |
| 156 int child_offset_; // Offset to use for the current child. | 168 int child_offset_; // Offset to use for the current child. |
| 157 int child_len_; // Bytes to read or write for this child. | 169 int child_len_; // Bytes to read or write for this child. |
| 158 int result_; | 170 int result_; |
| 159 | 171 |
| 160 DISALLOW_COPY_AND_ASSIGN(SparseControl); | 172 DISALLOW_COPY_AND_ASSIGN(SparseControl); |
| 161 }; | 173 }; |
| 162 | 174 |
| 163 } // namespace disk_cache | 175 } // namespace disk_cache |
| 164 | 176 |
| 165 #endif // NET_DISK_CACHE_SPARSE_CONTROL_H_ | 177 #endif // NET_DISK_CACHE_SPARSE_CONTROL_H_ |
| OLD | NEW |