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

Unified Diff: storage/browser/blob/blob_transport_strategy.h

Issue 1098853003: [BlobAsync] Patch 4: Browser Classes & Logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Non C++11 fixes, added nodisk logic and test Created 5 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: storage/browser/blob/blob_transport_strategy.h
diff --git a/storage/browser/blob/blob_transport_strategy.h b/storage/browser/blob/blob_transport_strategy.h
new file mode 100644
index 0000000000000000000000000000000000000000..5b3057c0fd4117b7a507d1ef89d65ed81106643d
--- /dev/null
+++ b/storage/browser/blob/blob_transport_strategy.h
@@ -0,0 +1,98 @@
+// Copyright 2015 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 STORAGE_BROWSER_BLOB_BLOB_TRANSPORT_STRATEGY_H_
+#define STORAGE_BROWSER_BLOB_BLOB_TRANSPORT_STRATEGY_H_
+
+#include <vector>
+
+#include "base/macros.h"
+#include "storage/browser/storage_browser_export.h"
+#include "storage/common/data_element.h"
+#include "storage/common/fileapi/blob_item_bytes_request.h"
+
+namespace storage {
+
+// This class determines and stores the strategy for asynchronously transporting
+// memory from the renderer to the browser. This involves two transformations:
+// 1. Transforming the data storage to be efficient in-transport. This can
+// mean that data is consolidated from cross-blob or cross-file boundaries
+// in the blob in a common block of shared memory or a file.
+// 2. Transforming the transport data into the browser storage representation.
+// This can simply mirror the renderer representation, or it can be instead
+// pointing to transport representation with offsets and sizes.
+//
+// The initial implementation of this is simple, but the protocol allows any
+// sort of flexibility, as everything has an offset and size specified.
+class STORAGE_EXPORT BlobTransportStrategy {
+ public:
+ enum Mode { MODE_UNKNOWN = 0, MODE_NO_DISK, MODE_DISK };
+
+ enum Error {
+ ERROR_NONE = 0,
+ ERROR_TOO_LARGE, // This item can't fit in disk or memory
+ ERROR_INVALID_PARAMS
+ };
+
+ struct MemoryItemRequest {
+ size_t browser_item_index;
+ size_t browser_item_offset;
+ BlobItemBytesRequest message;
+ };
+
+ BlobTransportStrategy();
+ virtual ~BlobTransportStrategy();
+
+ void Initialize(Mode mode, size_t max_ipc_memory_size,
+ size_t max_shared_memory_size, uint64_t max_file_size,
+ size_t max_blob_in_memory_size, uint64_t disk_space_left,
+ size_t memory_left,
+ const std::vector<DataElement> blob_item_infos);
kinuko 2015/04/30 15:04:21 nit: split the lines to have one parameter for eac
dmurph 2015/05/07 02:07:39 Done.
+
+ std::vector<uint64_t>& file_handles() { return file_handles_; }
+
+ std::vector<size_t>& shared_memory_handles() {
+ return shared_memory_handles_;
+ }
kinuko 2015/04/30 15:04:21 Are these intentionally made non-const references?
dmurph 2015/05/07 02:07:39 Whoops, done.
+
+ const std::vector<MemoryItemRequest>& requests() const { return requests_; }
+
+ Error error() const { return error_; }
+
+ // This iterates of the data elements and segments the 'bytes' data into
+ // the smallest number of segments given the max_segment_size.
+ // The callback describes either:
+ // * A non-memory item
+ // * A partition of a bytes element which will be populated into a given
+ // segment and segment offset.
+ // The function signature of the template functor is:
+ // void(DataElement::Type /*element_type*/,
+ // size_t /*element_index*/,
+ // SizeType /*element_offset*/,
+ // size_t /*segment_index*/,
+ // SizeType /*segment_offset*/,
+ // SizeType /*size*/)
kinuko 2015/04/30 15:04:21 would be nice to have a rough explanation about 'e
dmurph 2015/05/07 02:07:39 Done.
+ //
+ // Assumptions: All memory items are consolidated. As in, there are no two
+ // 'bytes' items next to eachother.
+ template <typename ForEachFunctor, typename SizeType>
+ static void ForEachWithSegment(const std::vector<DataElement> items,
kinuko 2015/04/30 15:04:21 nit: const ref
kinuko 2015/04/30 15:04:21 This could be private?
dmurph 2015/05/07 02:07:39 Done, done.
+ SizeType max_segment_size,
+ ForEachFunctor function);
+
+ private:
+ Error error_;
+
+ std::vector<uint64_t> file_handles_;
+ // can be size_t, but same as file handles so we can use the same methods.
kinuko 2015/04/30 15:04:21 ?
dmurph 2015/05/07 02:07:39 Whoops, forgot to remove this.
+ std::vector<size_t> shared_memory_handles_;
+
+ std::vector<MemoryItemRequest> requests_;
+
+ DISALLOW_COPY_AND_ASSIGN(BlobTransportStrategy);
+};
+
+} // namespace storage
+
+#endif // STORAGE_BROWSER_BLOB_BLOB_TRANSPORT_STRATEGY_H_

Powered by Google App Engine
This is Rietveld 408576698