| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 25 class Entry; | 25 class Entry; |
| 26 class EntryImpl; | 26 class EntryImpl; |
| 27 | 27 |
| 28 // This class provides support for the sparse capabilities of the disk cache. | 28 // This class provides support for the sparse capabilities of the disk cache. |
| 29 // Basically, sparse IO is directed from EntryImpl to this class, and we split | 29 // Basically, sparse IO is directed from EntryImpl to this class, and we split |
| 30 // the operation into multiple small pieces, sending each one to the | 30 // the operation into multiple small pieces, sending each one to the |
| 31 // appropriate entry. An instance of this class is asociated with each entry | 31 // appropriate entry. An instance of this class is asociated with each entry |
| 32 // used directly for sparse operations (the entry passed in to the constructor). | 32 // used directly for sparse operations (the entry passed in to the constructor). |
| 33 class SparseControl { | 33 class SparseControl { |
| 34 public: | 34 public: |
| 35 typedef net::CompletionCallback CompletionCallback; |
| 36 |
| 35 // The operation to perform. | 37 // The operation to perform. |
| 36 enum SparseOperation { | 38 enum SparseOperation { |
| 37 kNoOperation, | 39 kNoOperation, |
| 38 kReadOperation, | 40 kReadOperation, |
| 39 kWriteOperation, | 41 kWriteOperation, |
| 40 kGetRangeOperation | 42 kGetRangeOperation |
| 41 }; | 43 }; |
| 42 | 44 |
| 43 explicit SparseControl(EntryImpl* entry); | 45 explicit SparseControl(EntryImpl* entry); |
| 44 ~SparseControl(); | 46 ~SparseControl(); |
| 45 | 47 |
| 46 // Initializes the object for the current entry. If this entry already stores | 48 // Initializes the object for the current entry. If this entry already stores |
| 47 // sparse data, or can be used to do it, it updates the relevant information | 49 // sparse data, or can be used to do it, it updates the relevant information |
| 48 // on disk and returns net::OK. Otherwise it returns a net error code. | 50 // on disk and returns net::OK. Otherwise it returns a net error code. |
| 49 int Init(); | 51 int Init(); |
| 50 | 52 |
| 51 // Performs a quick test to see if the entry is sparse or not, without | 53 // Performs a quick test to see if the entry is sparse or not, without |
| 52 // generating disk IO (so the answer provided is only a best effort). | 54 // generating disk IO (so the answer provided is only a best effort). |
| 53 bool CouldBeSparse() const; | 55 bool CouldBeSparse() const; |
| 54 | 56 |
| 55 // Performs an actual sparse read or write operation for this entry. |op| is | 57 // Performs an actual sparse read or write operation for this entry. |op| is |
| 56 // the operation to perform, |offset| is the desired sparse offset, |buf| and | 58 // the operation to perform, |offset| is the desired sparse offset, |buf| and |
| 57 // |buf_len| specify the actual data to use and |callback| is the callback | 59 // |buf_len| specify the actual data to use and |callback| is the callback |
| 58 // to use for asynchronous operations. See the description of the Read / | 60 // to use for asynchronous operations. See the description of the Read / |
| 59 // WriteSparseData for details about the arguments. The return value is the | 61 // WriteSparseData for details about the arguments. The return value is the |
| 60 // number of bytes read or written, or a net error code. | 62 // number of bytes read or written, or a net error code. |
| 61 int StartIO(SparseOperation op, int64 offset, net::IOBuffer* buf, | 63 int StartIO(SparseOperation op, int64 offset, net::IOBuffer* buf, |
| 62 int buf_len, const net::CompletionCallback& callback); | 64 int buf_len, const CompletionCallback& callback); |
| 63 | 65 |
| 64 // Implements Entry::GetAvailableRange(). | 66 // Implements Entry::GetAvailableRange(). |
| 65 int GetAvailableRange(int64 offset, int len, int64* start); | 67 int GetAvailableRange(int64 offset, int len, int64* start); |
| 66 | 68 |
| 67 // Cancels the current sparse operation (if any). | 69 // Cancels the current sparse operation (if any). |
| 68 void CancelIO(); | 70 void CancelIO(); |
| 69 | 71 |
| 70 // Returns OK if the entry can be used for new IO or ERR_IO_PENDING if we are | 72 // 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 | 73 // 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. | 74 // again. See disk_cache::Entry::ReadyToUse() for more info. |
| 73 int ReadyToUse(const net::CompletionCallback& completion_callback); | 75 int ReadyToUse(const CompletionCallback& completion_callback); |
| 74 | 76 |
| 75 // Deletes the children entries of |entry|. | 77 // Deletes the children entries of |entry|. |
| 76 static void DeleteChildren(EntryImpl* entry); | 78 static void DeleteChildren(EntryImpl* entry); |
| 77 | 79 |
| 78 private: | 80 private: |
| 79 // Creates a new sparse entry or opens an aready created entry from disk. | 81 // Creates a new sparse entry or opens an aready created entry from disk. |
| 80 // These methods just read / write the required info from disk for the current | 82 // These methods just read / write the required info from disk for the current |
| 81 // entry, and verify that everything is correct. The return value is a net | 83 // entry, and verify that everything is correct. The return value is a net |
| 82 // error code. | 84 // error code. |
| 83 int CreateSparseEntry(); | 85 int CreateSparseEntry(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 bool finished_; | 154 bool finished_; |
| 153 bool init_; | 155 bool init_; |
| 154 bool range_found_; // True if GetAvailableRange found something. | 156 bool range_found_; // True if GetAvailableRange found something. |
| 155 bool abort_; // True if we should abort the current operation ASAP. | 157 bool abort_; // True if we should abort the current operation ASAP. |
| 156 | 158 |
| 157 SparseHeader sparse_header_; // Data about the children of entry_. | 159 SparseHeader sparse_header_; // Data about the children of entry_. |
| 158 Bitmap children_map_; // The actual bitmap of children. | 160 Bitmap children_map_; // The actual bitmap of children. |
| 159 SparseData child_data_; // Parent and allocation map of child_. | 161 SparseData child_data_; // Parent and allocation map of child_. |
| 160 Bitmap child_map_; // The allocation map as a bitmap. | 162 Bitmap child_map_; // The allocation map as a bitmap. |
| 161 | 163 |
| 162 net::CompletionCallback user_callback_; | 164 CompletionCallback user_callback_; |
| 163 std::vector<net::CompletionCallback> abort_callbacks_; | 165 std::vector<CompletionCallback> abort_callbacks_; |
| 164 int64 offset_; // Current sparse offset. | 166 int64 offset_; // Current sparse offset. |
| 165 scoped_refptr<net::DrainableIOBuffer> user_buf_; | 167 scoped_refptr<net::DrainableIOBuffer> user_buf_; |
| 166 int buf_len_; // Bytes to read or write. | 168 int buf_len_; // Bytes to read or write. |
| 167 int child_offset_; // Offset to use for the current child. | 169 int child_offset_; // Offset to use for the current child. |
| 168 int child_len_; // Bytes to read or write for this child. | 170 int child_len_; // Bytes to read or write for this child. |
| 169 int result_; | 171 int result_; |
| 170 | 172 |
| 171 DISALLOW_COPY_AND_ASSIGN(SparseControl); | 173 DISALLOW_COPY_AND_ASSIGN(SparseControl); |
| 172 }; | 174 }; |
| 173 | 175 |
| 174 } // namespace disk_cache | 176 } // namespace disk_cache |
| 175 | 177 |
| 176 #endif // NET_DISK_CACHE_SPARSE_CONTROL_H_ | 178 #endif // NET_DISK_CACHE_SPARSE_CONTROL_H_ |
| OLD | NEW |