| OLD | NEW | 
|---|
|  | (Empty) | 
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |  | 
| 2 // Use of this source code is governed by a BSD-style license that can be |  | 
| 3 // found in the LICENSE file. |  | 
| 4 |  | 
| 5 #ifndef STORAGE_BROWSER_BLOB_BLOB_ASYNC_TRANSPORT_STRATEGY_H_ |  | 
| 6 #define STORAGE_BROWSER_BLOB_BLOB_ASYNC_TRANSPORT_STRATEGY_H_ |  | 
| 7 |  | 
| 8 #include <stddef.h> |  | 
| 9 #include <stdint.h> |  | 
| 10 |  | 
| 11 #include <map> |  | 
| 12 #include <vector> |  | 
| 13 |  | 
| 14 #include "base/macros.h" |  | 
| 15 #include "base/memory/scoped_ptr.h" |  | 
| 16 #include "storage/browser/blob/blob_data_builder.h" |  | 
| 17 #include "storage/browser/storage_browser_export.h" |  | 
| 18 #include "storage/common/blob_storage/blob_item_bytes_request.h" |  | 
| 19 #include "storage/common/data_element.h" |  | 
| 20 |  | 
| 21 namespace storage { |  | 
| 22 |  | 
| 23 // This class computes and stores the strategy for asynchronously transporting |  | 
| 24 // memory from the renderer to the browser. We take memory constraints of our |  | 
| 25 // system and the description of a blob, and figure out: |  | 
| 26 // 1) How to store the blob data in the browser process: in memory or on disk. |  | 
| 27 // 2) How to transport the data from the renderer: ipc payload, shared memory, |  | 
| 28 //    or file handles. |  | 
| 29 // We then generate data requests for that blob's memory and seed a |  | 
| 30 // BlobDataBuilder for storing that data. |  | 
| 31 // |  | 
| 32 // Note: This class does not compute requests by using the 'shortcut' method, |  | 
| 33 //       where the data is already present in the blob description, and will |  | 
| 34 //       always give the caller the full strategy for requesting all data from |  | 
| 35 //       the renderer. |  | 
| 36 class STORAGE_EXPORT BlobAsyncTransportStrategy { |  | 
| 37  public: |  | 
| 38   enum Error { |  | 
| 39     ERROR_NONE = 0, |  | 
| 40     ERROR_TOO_LARGE,  // This item can't fit in disk or memory |  | 
| 41     ERROR_INVALID_PARAMS |  | 
| 42   }; |  | 
| 43 |  | 
| 44   struct RendererMemoryItemRequest { |  | 
| 45     RendererMemoryItemRequest(); |  | 
| 46     // This is the index of the item in the builder on the browser side. |  | 
| 47     size_t browser_item_index; |  | 
| 48     // Note: For files this offset should always be 0, as the file offset in |  | 
| 49     //       segmentation is handled by the handle_offset in the message.  This |  | 
| 50     //       offset is used for populating a chunk when the data comes back to |  | 
| 51     //       the browser. |  | 
| 52     size_t browser_item_offset; |  | 
| 53     BlobItemBytesRequest message; |  | 
| 54     bool received; |  | 
| 55   }; |  | 
| 56 |  | 
| 57   BlobAsyncTransportStrategy(); |  | 
| 58   virtual ~BlobAsyncTransportStrategy(); |  | 
| 59 |  | 
| 60   // This call does the computation to create the requests and builder for the |  | 
| 61   // blob given the memory constraints and blob description. |memory_available| |  | 
| 62   // is the total amount of memory we can offer for storing blobs. |  | 
| 63   // This method can only be called once. |  | 
| 64   void Initialize(size_t max_ipc_memory_size, |  | 
| 65                   size_t max_shared_memory_size, |  | 
| 66                   size_t max_file_size, |  | 
| 67                   uint64_t disk_space_left, |  | 
| 68                   size_t memory_available, |  | 
| 69                   const std::string& uuid, |  | 
| 70                   const std::vector<DataElement>& blob_item_infos); |  | 
| 71 |  | 
| 72   // The sizes of the handles being used (by handle index) in the async |  | 
| 73   // operation. This is used for both files or shared memory, as their use is |  | 
| 74   // mutually exclusive. |  | 
| 75   const std::vector<size_t>& handle_sizes() const { return handle_sizes_; } |  | 
| 76 |  | 
| 77   // The requests for memory, segmented as described above, along with their |  | 
| 78   // destination browser indexes and offsets. |  | 
| 79   const std::vector<RendererMemoryItemRequest>& requests() const { |  | 
| 80     return requests_; |  | 
| 81   } |  | 
| 82 |  | 
| 83   // Marks the request at the given request number as recieved. |  | 
| 84   void MarkRequestAsReceived(size_t request_num) { |  | 
| 85     DCHECK_LT(request_num, requests_.size()); |  | 
| 86     requests_[request_num].received = true; |  | 
| 87   } |  | 
| 88 |  | 
| 89   // A BlobDataBuilder which can be used to construct the Blob in the |  | 
| 90   // BlobStorageContext object after: |  | 
| 91   // * The bytes items from AppendFutureData are populated by |  | 
| 92   //   PopulateFutureData. |  | 
| 93   // * The temporary files from AppendFutureFile are populated by |  | 
| 94   //   PopulateFutureFile. |  | 
| 95   BlobDataBuilder* blob_builder() { return builder_.get(); } |  | 
| 96 |  | 
| 97   // The total bytes size of memory items in the blob. |  | 
| 98   uint64_t total_bytes_size() const { return total_bytes_size_; } |  | 
| 99 |  | 
| 100   Error error() const { return error_; } |  | 
| 101 |  | 
| 102   static bool ShouldBeShortcut(const std::vector<DataElement>& items, |  | 
| 103                                size_t memory_available); |  | 
| 104 |  | 
| 105  private: |  | 
| 106   static void ComputeHandleSizes(uint64_t total_memory_size, |  | 
| 107                                  size_t max_segment_size, |  | 
| 108                                  std::vector<size_t>* segment_sizes); |  | 
| 109 |  | 
| 110   Error error_; |  | 
| 111 |  | 
| 112   // We use the same vector for shared memory handle sizes and file handle sizes |  | 
| 113   // because we only use one for any strategy. The size of the handles is capped |  | 
| 114   // by the |max_file_size| argument in Initialize, so we can just use size_t. |  | 
| 115   std::vector<size_t> handle_sizes_; |  | 
| 116 |  | 
| 117   uint64_t total_bytes_size_; |  | 
| 118   std::vector<RendererMemoryItemRequest> requests_; |  | 
| 119   scoped_ptr<BlobDataBuilder> builder_; |  | 
| 120 |  | 
| 121   DISALLOW_COPY_AND_ASSIGN(BlobAsyncTransportStrategy); |  | 
| 122 }; |  | 
| 123 |  | 
| 124 }  // namespace storage |  | 
| 125 |  | 
| 126 #endif  // STORAGE_BROWSER_BLOB_BLOB_ASYNC_TRANSPORT_STRATEGY_H_ |  | 
| OLD | NEW | 
|---|