Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Unified Diff: net/disk_cache/v3/sparse_control_v3.h

Issue 15203004: Disk cache: Reference CL for the implementation of file format version 3. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: IndexTable review Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/disk_cache/v3/index_table_unittest.cc ('k') | net/disk_cache/v3/sparse_control_v3.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/v3/sparse_control_v3.h
===================================================================
--- net/disk_cache/v3/sparse_control_v3.h (revision 0)
+++ net/disk_cache/v3/sparse_control_v3.h (revision 0)
@@ -0,0 +1,199 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_DISK_CACHE_V3_SPARSE_CONTROL_V3_H_
+#define NET_DISK_CACHE_V3_SPARSE_CONTROL_V3_H_
+
+#include <string>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "net/base/completion_callback.h"
+#include "net/disk_cache/bitmap.h"
+#include "net/disk_cache/disk_format_base.h"
+
+namespace net {
+class IOBuffer;
+class DrainableIOBuffer;
+}
+
+namespace disk_cache {
+
+class Entry;
+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 SparseControlV3 {
+ public:
+ typedef net::CompletionCallback CompletionCallback;
+
+ // The operation to perform.
+ enum SparseOperation {
+ kNoOperation,
+ kReadOperation,
+ kWriteOperation,
+ kGetRangeOperation
+ };
+
+ 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;
+
+ // Performs an actual sparse read or write operation for this entry. |op| is
+ // the operation to perform, |offset| is the desired sparse offset, |buf| and
+ // |buf_len| specify the actual data to use and |callback| is the callback
+ // to use for asynchronous operations. See the description of the Read /
+ // WriteSparseData for details about the arguments. The return value is the
+ // number of bytes read or written, or a net error code.
+ int StartIO(SparseOperation op, int64 offset, net::IOBuffer* buf,
+ int buf_len, const CompletionCallback& callback);
+
+ // Implements Entry::GetAvailableRange().
+ int GetAvailableRange(int64 offset, int len, int64* start,
+ const CompletionCallback& callback);
+
+ // Cancels the current sparse operation (if any).
+ void CancelIO();
+
+ // Returns OK if the entry can be used for new IO or ERR_IO_PENDING if we are
+ // busy. If the entry is busy, we'll invoke the callback when we are ready
+ // again. See disk_cache::Entry::ReadyToUse() for more info.
+ int ReadyToUse(const CompletionCallback& completion_callback);
+
+ // Deletes the children entries of |entry|.
+ static void DeleteChildren(EntryImplV3* entry);
+
+ private:
+ 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
+ };
+
+ 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();
+
+ std::string GenerateChildKey();
+
+ // Deletes the current child and continues the current operation (open).
+ int KillChildAndContinue();
+
+ // Returns true if the required child is tracked by the parent entry, i.e. it
+ // was already created.
+ bool ChildPresent();
+
+ // Sets the bit for the current child to the provided |value|. In other words,
+ // starts or stops tracking this child.
+ void SetChildBit(bool value);
+
+ // Verify that the range to be accessed for the current child is appropriate.
+ // Returns false if an error is detected or there is no need to perform the
+ // current IO operation (for instance if the required range is not stored by
+ // the child).
+ bool VerifyRange();
+
+ // Updates the contents bitmap for the current range, based on the result of
+ // the current operation.
+ void UpdateRange(int result);
+
+ // Returns the number of bytes stored at |block_index|, if its allocation-bit
+ // is off (because it is not completely filled).
+ int PartialBlockLength(int block_index) const;
+
+ // Initializes the sparse info for the current child.
+ void InitChildData();
+
+ // Performs the required work for GetAvailableRange for one child.
+ int GetAvailableRangeImpl();
+
+ void LogChildOperationStart();
+ void LogChildOperationEnd(int result);
+ int LogCompletion(int result);
+
+ // Reports to the user that we are done.
+ void HandleResult(int result);
+ void HanldeAbortCallbacks();
+
+ // Invoked by the callback of asynchronous operations.
+ void OnIOComplete(int result);
+
+ EntryImplV3* entry_; // The sparse entry.
+ Entry* child_; // The current child entry.
+ SparseOperation operation_;
+ 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.
+ SparseData child_data_; // Parent and allocation map of child_.
+ 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(SparseControlV3);
+};
+
+} // namespace disk_cache
+
+#endif // NET_DISK_CACHE_V3_SPARSE_CONTROL_V3_H_
Property changes on: net\disk_cache\v3\sparse_control_v3.h
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « net/disk_cache/v3/index_table_unittest.cc ('k') | net/disk_cache/v3/sparse_control_v3.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698