Index: net/disk_cache/v3/sparse_control_v3.h |
=================================================================== |
--- net/disk_cache/v3/sparse_control_v3.h (revision 232523) |
+++ net/disk_cache/v3/sparse_control_v3.h (working copy) |
@@ -2,8 +2,8 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#ifndef NET_DISK_CACHE_SPARSE_CONTROL_H_ |
-#define NET_DISK_CACHE_SPARSE_CONTROL_H_ |
+#ifndef NET_DISK_CACHE_V3_SPARSE_CONTROL_V3_H_ |
+#define NET_DISK_CACHE_V3_SPARSE_CONTROL_V3_H_ |
#include <string> |
#include <vector> |
@@ -12,7 +12,7 @@ |
#include "base/compiler_specific.h" |
#include "net/base/completion_callback.h" |
#include "net/disk_cache/bitmap.h" |
-#include "net/disk_cache/disk_format.h" |
+#include "net/disk_cache/disk_format_base.h" |
namespace net { |
class IOBuffer; |
@@ -22,14 +22,14 @@ |
namespace disk_cache { |
class Entry; |
-class EntryImpl; |
+class EntryImplV3; |
// This class provides support for the sparse capabilities of the disk cache. |
// Basically, sparse IO is directed from EntryImpl to this class, and we split |
// the operation into multiple small pieces, sending each one to the |
// appropriate entry. An instance of this class is asociated with each entry |
// used directly for sparse operations (the entry passed in to the constructor). |
-class SparseControl { |
+class SparseControlV3 { |
public: |
typedef net::CompletionCallback CompletionCallback; |
@@ -41,9 +41,11 @@ |
kGetRangeOperation |
}; |
- explicit SparseControl(EntryImpl* entry); |
- ~SparseControl(); |
+ explicit SparseControlV3(EntryImplV3* entry); |
+ ~SparseControlV3(); |
+ void Close(); |
+ |
// Performs a quick test to see if the entry is sparse or not, without |
// generating disk IO (so the answer provided is only a best effort). |
bool CouldBeSparse() const; |
@@ -58,7 +60,8 @@ |
int buf_len, const CompletionCallback& callback); |
// Implements Entry::GetAvailableRange(). |
- int GetAvailableRange(int64 offset, int len, int64* start); |
+ int GetAvailableRange(int64 offset, int len, int64* start, |
+ const CompletionCallback& callback); |
// Cancels the current sparse operation (if any). |
void CancelIO(); |
@@ -69,45 +72,57 @@ |
int ReadyToUse(const CompletionCallback& completion_callback); |
// Deletes the children entries of |entry|. |
- static void DeleteChildren(EntryImpl* entry); |
+ static void DeleteChildren(EntryImplV3* entry); |
private: |
- // Initializes the object for the current entry. If this entry already stores |
- // sparse data, or can be used to do it, it updates the relevant information |
- // on disk and returns net::OK. Otherwise it returns a net error code. |
- int Init(); |
+ enum State { |
+ STATE_NONE, |
+ STATE_INIT, |
+ STATE_CREATE_SPARSE_ENTRY, |
+ STATE_CREATE_SPARSE_ENTRY_COMPLETE, |
+ STATE_OPEN_SPARSE_ENTRY, |
+ STATE_OPEN_SPARSE_ENTRY_COMPLETE, |
+ STATE_READ_BITMAP_COMPLETE, |
+ STATE_GET_CHILD_KEY, |
+ STATE_OPEN_CHILD, |
+ STATE_OPEN_CHILD_COMPLETE, |
+ STATE_READ_SIGNATURE_COMPLETE, |
+ STATE_CLOSE_CHILD, |
+ STATE_CLOSE_CHILD_COMPLETE, |
+ STATE_CREATE_CHILD, |
+ STATE_CREATE_CHILD_COMPLETE, |
+ STATE_WRITE_BITMAP, |
+ STATE_WRITE_BITMAP_COMPLETE, |
+ STATE_DO_CHILD_IO, |
+ STATE_DO_CHILD_IO_COMPLETE, |
+ STATE_CLOSE |
+ }; |
- // Creates a new sparse entry or opens an aready created entry from disk. |
- // These methods just read / write the required info from disk for the current |
- // entry, and verify that everything is correct. The return value is a net |
- // error code. |
- int CreateSparseEntry(); |
- int OpenSparseEntry(int data_len); |
+ int DoLoop(int result); |
+ int DoInit(); |
+ int DoCreateSparseEntry(); |
+ int DoCreateSparseEntryComplete(int result); |
+ int DoOpenSparseEntry(int data_len); |
+ int DoOpenSparseEntryComplete(int result); |
+ int DoReadBitmapComplete(int result); |
+ int DoGetChildKey(); |
+ int DoOpenChild(); |
+ int DoOpenChildComplete(int result); |
+ int DoReadSignatureComplete(int result); |
+ int DoCloseChild(); |
+ int DoCloseChildComplete(int result); |
+ int DoCreateChild(); |
+ int DoCreateChildComplete(int result); |
+ int DoWriteBitmap(); |
+ int DoWriteBitmapComplete(int result); |
+ int DoChildIO(); |
+ int DoChildIOComplete(int result); |
+ int DoClose(); |
- // Opens and closes a child entry. A child entry is a regular EntryImpl object |
- // with a key derived from the key of the resource to store and the range |
- // stored by that child. |
- bool OpenChild(); |
- void CloseChild(); |
- |
- // Continues the current operation (open) without a current child. |
- bool ContinueWithoutChild(const std::string& key); |
- |
- // Writes to disk the tracking information for this entry. |
- void WriteSparseData(); |
- |
- // Performs a single operation with the current child. Returns true when we |
- // should move on to the next child and false when we should interrupt our |
- // work. |
- bool DoChildIO(); |
- |
- // Performs the required work after a single IO operations finishes. |
- void DoChildIOCompleted(int result); |
- |
std::string GenerateChildKey(); |
// Deletes the current child and continues the current operation (open). |
- bool KillChildAndContinue(const std::string& key, bool fatal); |
+ int KillChildAndContinue(); |
// Returns true if the required child is tracked by the parent entry, i.e. it |
// was already created. |
@@ -135,23 +150,28 @@ |
void InitChildData(); |
// Performs the required work for GetAvailableRange for one child. |
- int DoGetAvailableRange(); |
+ int GetAvailableRangeImpl(); |
+ void LogChildOperationStart(); |
+ void LogChildOperationEnd(int result); |
+ int LogCompletion(int result); |
+ |
// Reports to the user that we are done. |
- void DoUserCallback(); |
- void DoAbortCallbacks(); |
+ void HandleResult(int result); |
+ void HanldeAbortCallbacks(); |
// Invoked by the callback of asynchronous operations. |
- void OnChildIOCompleted(int result); |
+ void OnIOComplete(int result); |
- EntryImpl* entry_; // The sparse entry. |
- EntryImpl* child_; // The current child entry. |
+ EntryImplV3* entry_; // The sparse entry. |
+ Entry* child_; // The current child entry. |
SparseOperation operation_; |
- bool pending_; // True if any child IO operation returned pending. |
- bool finished_; |
+ State next_state_; |
bool init_; |
bool range_found_; // True if GetAvailableRange found something. |
bool abort_; // True if we should abort the current operation ASAP. |
+ bool valid_; |
+ bool closing_; |
SparseHeader sparse_header_; // Data about the children of entry_. |
Bitmap children_map_; // The actual bitmap of children. |
@@ -159,17 +179,21 @@ |
Bitmap child_map_; // The allocation map as a bitmap. |
CompletionCallback user_callback_; |
+ CompletionCallback callback_; |
std::vector<CompletionCallback> abort_callbacks_; |
int64 offset_; // Current sparse offset. |
scoped_refptr<net::DrainableIOBuffer> user_buf_; |
+ scoped_refptr<net::IOBuffer> buf_; |
+ std::string key_; |
int buf_len_; // Bytes to read or write. |
int child_offset_; // Offset to use for the current child. |
int child_len_; // Bytes to read or write for this child. |
int result_; |
+ int64* range_start_; |
- DISALLOW_COPY_AND_ASSIGN(SparseControl); |
+ DISALLOW_COPY_AND_ASSIGN(SparseControlV3); |
}; |
} // namespace disk_cache |
-#endif // NET_DISK_CACHE_SPARSE_CONTROL_H_ |
+#endif // NET_DISK_CACHE_V3_SPARSE_CONTROL_V3_H_ |