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

Side by Side Diff: content/child/blob_storage/blob_consolidation.h

Issue 1183713003: Blob Consolidation & Registry Hookup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: file path fix Created 5 years, 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | content/child/blob_storage/blob_consolidation.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_UNKNOWN,
36 ERROR_WRONG_TYPE,
37 ERROR_OUT_OF_BOUNDS,
38 OK
39 };
40 struct ConsolidatedItem {
41 ConsolidatedItem();
42 ConsolidatedItem(storage::DataElement::Type type,
43 uint64_t offset,
44 uint64_t length);
45 ~ConsolidatedItem();
46
47 storage::DataElement::Type type;
48 uint64_t offset;
49 uint64_t length;
50
51 base::FilePath path; // For TYPE_FILE.
52 GURL filesystem_url; // For TYPE_FILE_FILESYSTEM.
53 double expected_modification_time; // For TYPE_FILE, TYPE_FILE_FILESYSTEM.
54 std::string blob_uuid; // For TYPE_BLOB.
55 // Only populated if len(items) > 1. Used for binary search.
56 // Since the offset of the first item is always 0, we exclude this.
57 std::vector<size_t> offsets; // For TYPE_BYTES.
58 std::vector<blink::WebThreadSafeData> data; // For TYPE_BYTES.
59 };
60
61 BlobConsolidation();
62 ~BlobConsolidation();
63
64 void AddDataItem(const blink::WebThreadSafeData& data);
65 void AddFileItem(const base::FilePath& path,
66 uint64_t offset,
67 uint64_t length,
68 double expected_modification_time);
69 void AddBlobItem(const std::string& uuid, uint64_t offset, uint64_t length);
70 void AddFileSystemItem(const GURL& url,
71 uint64_t offset,
72 uint64_t length,
73 double expected_modification_time);
74
75 // These are the resulting consolidated items, constructed from the Add*
76 // methods. This configuration is used to describe the data to the browser,
77 // even though one consolidated memory items can contain multiple data parts.
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,
93 size_t consolidated_size,
94 void* memory_out);
95
96 private:
97 size_t total_memory_;
98 std::vector<ConsolidatedItem> consolidated_items_;
99
100 DISALLOW_COPY_AND_ASSIGN(BlobConsolidation);
101 };
102
103 } // namespace content
104 #endif // CONTENT_CHILD_BLOB_STORAGE_BLOB_CONSOLIDATION_H_
OLDNEW
« no previous file with comments | « no previous file | content/child/blob_storage/blob_consolidation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698