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

Unified Diff: content/child/blob_storage/blob_consolidation.h

Issue 1414123002: [BlobAsync] Renderer support for blob file writing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blob-hookup
Patch Set: Added test & simplified IPC callback[ Created 4 years, 8 months 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
Index: content/child/blob_storage/blob_consolidation.h
diff --git a/content/child/blob_storage/blob_consolidation.h b/content/child/blob_storage/blob_consolidation.h
index 7c581d4cf95ba2e3dace669abd2f4fc58a52d6de..6053a2395a7098ff4c78c4bca579b3f934c50bc4 100644
--- a/content/child/blob_storage/blob_consolidation.h
+++ b/content/child/blob_storage/blob_consolidation.h
@@ -13,8 +13,10 @@
#include <string>
#include <vector>
+#include "base/callback_forward.h"
#include "base/logging.h"
#include "base/macros.h"
+#include "base/memory/ref_counted.h"
#include "content/common/content_export.h"
#include "storage/common/data_element.h"
#include "third_party/WebKit/public/platform/WebThreadSafeData.h"
@@ -33,12 +35,14 @@ namespace content {
//
// NOTE: this class does not do memory accounting or garbage collecting. The
// memory for the blob sticks around until this class is destructed.
-class CONTENT_EXPORT BlobConsolidation {
+class CONTENT_EXPORT BlobConsolidation
+ : public base::RefCountedThreadSafe<BlobConsolidation> {
public:
enum class ReadStatus {
ERROR_UNKNOWN,
ERROR_WRONG_TYPE,
ERROR_OUT_OF_BOUNDS,
+ EARLY_ABORT,
michaeln 2016/04/21 01:58:41 maybe call this CANCELLED_BY_VISITOR to make it cl
dmurph 2016/04/22 22:37:09 Done.
OK
};
struct ConsolidatedItem {
@@ -64,7 +68,6 @@ class CONTENT_EXPORT BlobConsolidation {
};
BlobConsolidation();
- ~BlobConsolidation();
void AddDataItem(const blink::WebThreadSafeData& data);
void AddFileItem(const base::FilePath& path,
@@ -91,19 +94,41 @@ class CONTENT_EXPORT BlobConsolidation {
size_t total_memory() const { return total_memory_; }
- // Reads memory from the given item into the given buffer. Returns:
+ // This method calls the |visibor| callback with the given memory item,
michaeln 2016/04/21 01:58:41 spelling |visitor|
dmurph 2016/04/22 22:37:09 Done.
+ // offset, and size. Since items are consolidated, |visitor| can be called
+ // multiple times, where the |total_memory_read| variable keeps track of how
+ // much memory the visitor has seen. The return value of |visitor| determines
+ // if we should continue reading memory, where 'false' triggers an early
+ // return and we return EARLY_ABORT. |visitor| is guaranteed to be called
+ // only during this method call.
+ // Returns:
// * ReadStatus::ERROR if the state or arguments are invalid (see error log),
// * ReadStatus::ERROR_WRONG_TYPE if the item at the index isn't memory,
// * ReadStatus::ERROR_OUT_OF_BOUNDS if index, offset, or size are invalid,
- // * ReadStatus::DONE if the memory has been successfully read.
+ // * ReadStatus::EARLY_ABORT if the visitor returns false before we're done,
+ // * ReadStatus::DONE if the memory has been successfully visited.
+ ReadStatus VisitMemory(
+ size_t consolidated_item_index,
+ size_t consolidated_offset,
+ size_t consolidated_size,
+ base::Callback<bool(size_t /* total_memory_read */,
michaeln 2016/04/21 01:58:41 initially, i didn't understand the total_memory_re
dmurph 2016/04/22 22:37:09 I end up using it in the places I use this method.
+ const char* /* memory */,
+ size_t /* memory_size */)> visitor) const;
+
+ // Reads memory from the given item into the given buffer. This is a simple
+ // wrapper of VisitMemory. Returns the same values as VisitMemory, except we
+ // don't return EARLY_ABORT.
// Precondition: memory_out must be a valid pointer to memory with a size of
// at least consolidated_size.
ReadStatus ReadMemory(size_t consolidated_item_index,
size_t consolidated_offset,
size_t consolidated_size,
- void* memory_out);
+ void* memory_out) const;
private:
+ friend class base::RefCountedThreadSafe<BlobConsolidation>;
+ ~BlobConsolidation();
+
size_t total_memory_;
std::set<std::string> referenced_blobs_;
std::vector<ConsolidatedItem> consolidated_items_;
« no previous file with comments | « no previous file | content/child/blob_storage/blob_consolidation.cc » ('j') | content/child/blob_storage/blob_consolidation.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698