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 CONTENT_CHILD_BLOB_STORAGE_BLOB_CONSOLIDATION_H_ | |
6 #define CONTENT_CHILD_BLOB_STORAGE_BLOB_CONSOLIDATION_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/logging.h" | |
12 #include "base/macros.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "content/common/content_export.h" | |
15 #include "storage/common/data_element.h" | |
16 #include "third_party/WebKit/public/platform/WebThreadSafeData.h" | |
17 | |
18 namespace content { | |
19 | |
20 // This class facilitates the consolidation of memory items in blobs. No memory | |
21 // is copied to store items in this object. Instead, the memory is copied into | |
22 // the external char* array given to the ReadMemory method. | |
23 // Features: | |
24 // * Add_Item methods for building the blob. | |
25 // * consolidated_items for getting the consolidated items. This is | |
26 // used to describe the blob to the browser. | |
27 // * total_memory to get the total memory size of the blob. | |
28 // * ReadMemory for reading arbitrary memory from any consolidated item. | |
29 // | |
30 // NOTE: this class does not do memory accounting or garbage collecting. The | |
31 // memory for the blob sticks around until this class is destructed. | |
32 class CONTENT_EXPORT BlobConsolidation { | |
33 public: | |
34 enum class ReadStatus { | |
35 ERROR = 0, | |
36 ERROR_WRONG_TYPE, | |
37 ERROR_OUT_OF_BOUNDS, | |
38 DONE | |
kinuko
2015/06/25 05:04:19
nit: DONE -> OK maybe if DONE means no-error?
nit
dmurph
2015/06/25 23:38:54
I don't put the SUCCESS case first because it coul
| |
39 }; | |
40 struct ConsolidatedItem { | |
41 ConsolidatedItem(); | |
42 ConsolidatedItem(storage::DataElement::Type type, uint64_t offset, | |
43 uint64_t length); | |
44 ~ConsolidatedItem(); | |
45 | |
46 storage::DataElement::Type type; | |
47 uint64_t offset; | |
48 uint64_t length; | |
49 | |
50 base::FilePath path; // For TYPE_FILE. | |
51 GURL filesystem_url; // For TYPE_FILE_FILESYSTEM. | |
52 double expected_modification_time; // For TYPE_FILE, TYPE_FILE_FILESYSTEM. | |
53 std::string blob_uuid; // For TYPE_BLOB. | |
54 // Only populated if len(items) > 1. Used for binary search. | |
55 // Since the offset of the first item is always 0, we exclude this. | |
56 std::vector<size_t> offsets; // For TYPE_BYTES. | |
57 std::vector<blink::WebThreadSafeData> data; // For TYPE_BYTES. | |
58 }; | |
59 | |
60 BlobConsolidation(); | |
61 ~BlobConsolidation(); | |
62 | |
63 void AddDataItem(const blink::WebThreadSafeData& data); | |
64 void AddFileItem(const base::FilePath& path, | |
65 uint64_t offset, | |
66 uint64_t length, | |
67 double expected_modification_time); | |
68 void AddBlobItem(const std::string& uuid, | |
69 uint64_t offset, | |
70 uint64_t length); | |
71 void AddFileSystemItem(const GURL& url, | |
72 uint64_t offset, | |
73 uint64_t length, | |
74 double expected_modification_time); | |
75 | |
76 // This gets the consolidated items constructed from the WebBlobData. This | |
kinuko
2015/06/25 05:04:19
nit: The comment's a bit stale? Any of methods don
dmurph
2015/06/25 23:38:55
Done.
| |
77 // is used to describe the blob to the browser. | |
78 const std::vector<ConsolidatedItem>& consolidated_items() const { | |
79 return consolidated_items_; | |
80 } | |
81 | |
82 size_t total_memory() const { return total_memory_; } | |
83 | |
84 // Reads memory from the given item into the given buffer. Returns: | |
85 // * ReadStatus::ERROR if the state or arguments are invalid (see error log), | |
86 // * ReadStatus::ERROR_WRONG_TYPE if the item at the index isn't memory, | |
87 // * ReadStatus::ERROR_OUT_OF_BOUNDS if index, offset, or size are invalid, | |
88 // * ReadStatus::DONE if the memory has been successfully read. | |
89 // Precondition: memory_out must be a valid pointer to memory with a size of | |
90 // at least consolidated_size. | |
91 ReadStatus ReadMemory(size_t consolidated_item_index, | |
92 size_t consolidated_offset, size_t consolidated_size, | |
93 void* memory_out); | |
94 | |
95 private: | |
96 size_t total_memory_; | |
97 std::vector<ConsolidatedItem> consolidated_items_; | |
98 | |
99 DISALLOW_COPY_AND_ASSIGN(BlobConsolidation); | |
100 }; | |
101 | |
102 } // namespace content | |
103 #endif // CONTENT_CHILD_BLOB_STORAGE_BLOB_CONSOLIDATION_H_ | |
OLD | NEW |