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

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

Issue 1098853003: [BlobAsync] Patch 4: Browser Classes & Logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments Created 5 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
Index: storage/browser/blob/blob_async_builder_host.h
diff --git a/storage/browser/blob/blob_async_builder_host.h b/storage/browser/blob/blob_async_builder_host.h
new file mode 100644
index 0000000000000000000000000000000000000000..d6ae3e5909a7c867aa1598b6f4d4f80151c82744
--- /dev/null
+++ b/storage/browser/blob/blob_async_builder_host.h
@@ -0,0 +1,132 @@
+// 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_ASYNC_BUILDER_HOST_H_
+#define STORAGE_BROWSER_BLOB_BLOB_ASYNC_BUILDER_HOST_H_
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include "base/callback.h"
+#include "base/containers/scoped_ptr_map.h"
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/shared_memory_handle.h"
+#include "storage/browser/blob/blob_async_transport_strategy.h"
+#include "storage/browser/blob/blob_data_builder.h"
+#include "storage/browser/storage_browser_export.h"
+#include "storage/common/blob_storage/blob_item_bytes_request.h"
+#include "storage/common/blob_storage/blob_item_bytes_response.h"
+#include "storage/common/blob_storage/blob_storage_constants.h"
+#include "storage/common/data_element.h"
+
+namespace base {
+class SharedMemory;
+}
+
+namespace storage {
+
+// This class holds all blobs that are currently being built asynchronously for
+// a child process. It sends memory request, cancel, and done messages through
+// the given callbacks.
+// This also includes handling 'shortcut' logic, where the host will use the
+// initial data in the description instead of requesting for data if we have
+// enough immediate space.
+class STORAGE_EXPORT BlobAsyncBuilderHost {
+ public:
+ BlobAsyncBuilderHost();
+ virtual ~BlobAsyncBuilderHost();
+
+ // This method begins the construction of the blob given the descriptions.
+ // After this method is called, the following can happen:
+ // * The |done| callback is triggered immediately because we can shortcut the
+ // construction.
+ // * The |request_memory| callback is called to request memory from the
+ // renderer. This class waits for calls to OnMemoryResponses to continue.
+ // The last argument in the callback corresponds to file handle sizes.
+ // * The cancel callback is triggered if there is an error.
+ // Note: The builder given to the 'done' callback is destructed immediately
+ // after the callback is run.
kinuko 2015/11/24 15:38:16 nit: this comment's probably no longer necessary/a
dmurph 2015/11/24 22:27:33 Nice catch, thanks.
+ void StartBuildingBlob(
+ const std::string& uuid,
+ const std::string& type,
+ const std::vector<DataElement>& descriptions,
+ size_t memory_available,
+ base::Callback<void(const std::vector<storage::BlobItemBytesRequest>&,
+ const std::vector<base::SharedMemoryHandle>&,
+ const std::vector<uint64_t>&)> request_memory,
kinuko 2015/11/24 15:38:16 nit: I think we usually pass callbacks by const re
dmurph 2015/11/24 22:27:33 ok
+ base::Callback<void(const BlobDataBuilder&)> done,
+ base::Callback<void(IPCBlobCreationCancelCode)> cancel);
+
+ bool IsBuildingBlob(const std::string& uuid) const {
kinuko 2015/11/24 15:38:16 doesn't seem used in this CL
dmurph 2015/11/24 22:27:33 removed.
+ return async_blob_map_.find(uuid) != async_blob_map_.end();
+ }
+
+ // This is called when we have responses from the Renderer to our calls to
+ // the request_memory callback above.
+ void OnMemoryResponses(const std::string& uuid,
+ const std::vector<BlobItemBytesResponse>& responses);
+
+ // This erases the blob building state.
+ void StopBuildingBlob(const std::string& uuid);
kinuko 2015/11/24 15:38:17 ditto, doesn't seem to be used in this CL
dmurph 2015/11/24 22:27:33 Tested.
+
+ size_t blob_building_count() const { return async_blob_map_.size(); }
+
+ // For testing use only. Must be called before StartBuildingBlob.
+ void SetMemoryConstantsForTesting(size_t max_ipc_memory_size,
+ size_t max_shared_memory_size,
+ uint64_t max_file_size) {
+ max_ipc_memory_size_ = max_ipc_memory_size;
+ max_shared_memory_size_ = max_shared_memory_size;
+ max_file_size_ = max_file_size;
+ }
+
+ private:
+ struct BlobBuildingState {
+ BlobBuildingState();
+ ~BlobBuildingState();
+
+ std::string type;
+ BlobAsyncTransportStrategy transport_strategy;
+ size_t next_request;
+ size_t num_fulfilled_requests;
+ scoped_ptr<base::SharedMemory> shared_memory_block;
+ // This is the number of requests that have been sent to populate the above
+ // shared data. We won't ask for more data in shared memory until all
+ // requests have been responded to.
+ size_t num_shared_memory_requests;
+ // Only relevant if num_shared_memory_requests is > 0
+ size_t current_shared_memory_handle_index;
+
+ base::Callback<void(const std::vector<storage::BlobItemBytesRequest>&,
+ const std::vector<base::SharedMemoryHandle>&,
+ const std::vector<uint64_t>&)> request_memory_callback;
+ base::Callback<void(const BlobDataBuilder&)> done_callback;
+ base::Callback<void(IPCBlobCreationCancelCode)> cancel_callback;
+ };
+
+ typedef base::ScopedPtrMap<std::string, scoped_ptr<BlobBuildingState>>
kinuko 2015/11/24 15:38:16 nit: ScopedPtrMap is now deprecated, can use map<s
dmurph 2015/11/24 22:27:33 Done.
+ AsyncBlobMap;
+
+ // This is the 'main loop' of our memory requests to the renderer.
+ void ContinueBlobMemoryRequests(const std::string& uuid);
+
+ void CancelAndCleanup(const std::string& uuid,
+ IPCBlobCreationCancelCode code);
+ void DoneAndCleanup(const std::string& uuid);
+
+ AsyncBlobMap async_blob_map_;
+
+ // Here for testing.
+ size_t max_ipc_memory_size_ = kBlobStorageIPCThresholdBytes;
+ size_t max_shared_memory_size_ = kBlobStorageMaxSharedMemoryBytes;
+ uint64_t max_file_size_ = kBlobStorageMaxFileSizeBytes;
+
+ DISALLOW_COPY_AND_ASSIGN(BlobAsyncBuilderHost);
+};
+
+} // namespace storage
+#endif // STORAGE_BROWSER_BLOB_BLOB_ASYNC_BUILDER_HOST_H_

Powered by Google App Engine
This is Rietveld 408576698