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

Side by Side Diff: storage/browser/blob/blob_data_builder.h

Issue 1098853003: [BlobAsync] Patch 4: Browser Classes & Logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Missed duplicate invalid test Created 5 years 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
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_ 5 #ifndef STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_
6 #define STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_ 6 #define STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <ostream> 9 #include <ostream>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "storage/browser/blob/blob_data_item.h" 16 #include "storage/browser/blob/blob_data_item.h"
17 #include "storage/browser/blob/blob_data_snapshot.h" 17 #include "storage/browser/blob/blob_data_snapshot.h"
18 #include "storage/browser/storage_browser_export.h" 18 #include "storage/browser/storage_browser_export.h"
19 19
20 namespace disk_cache { 20 namespace disk_cache {
21 class Entry; 21 class Entry;
22 } 22 }
23 23
24 namespace storage { 24 namespace storage {
25 class BlobStorageContext; 25 class BlobStorageContext;
26 class ShareableFileReference;
26 27
27 class STORAGE_EXPORT BlobDataBuilder { 28 class STORAGE_EXPORT BlobDataBuilder {
28 public: 29 public:
29 using DataHandle = BlobDataItem::DataHandle; 30 using DataHandle = BlobDataItem::DataHandle;
30 31
32 // This is the filename used for the temporary file items added by
33 // AppendFutureFile.
34 const static char kAppendFutureFileTemporaryFileName[];
35
31 explicit BlobDataBuilder(const std::string& uuid); 36 explicit BlobDataBuilder(const std::string& uuid);
32 ~BlobDataBuilder(); 37 ~BlobDataBuilder();
33 38
34 const std::string& uuid() const { return uuid_; } 39 const std::string& uuid() const { return uuid_; }
35 40
36 // Validates the data element that was sent over IPC, and copies the data if 41 // Validates the data element that was sent over IPC, and copies the data if
37 // it's a 'bytes' element. Data elements of BYTES_DESCRIPTION or 42 // it's a 'bytes' element. Data elements of BYTES_DESCRIPTION or
38 // DISK_CACHE_ENTRY types are not valid IPC data element types, and cannot be 43 // DISK_CACHE_ENTRY types are not valid IPC data element types, and cannot be
39 // given to this method. 44 // given to this method.
40 void AppendIPCDataElement(const DataElement& ipc_data); 45 void AppendIPCDataElement(const DataElement& ipc_data);
41 46
42 // Copies the given data into the blob. 47 // Copies the given data into the blob.
43 void AppendData(const std::string& data) { 48 void AppendData(const std::string& data) {
44 AppendData(data.c_str(), data.size()); 49 AppendData(data.c_str(), data.size());
45 } 50 }
46 51
47 // Copies the given data into the blob. 52 // Copies the given data into the blob.
48 void AppendData(const char* data, size_t length); 53 void AppendData(const char* data, size_t length);
49 54
50 // Adds an item that is flagged for future data population. The memory is not 55 // Adds an item that is flagged for future data population. The memory is not
51 // allocated until the first call to PopulateFutureData. Returns the index of 56 // allocated until the first call to PopulateFutureData. Returns the index of
52 // the item (to be used in PopulateFutureData). 57 // the item (to be used in PopulateFutureData). |length| cannot be 0.
53 // Length cannot be 0.
54 size_t AppendFutureData(size_t length); 58 size_t AppendFutureData(size_t length);
55 59
56 // Populates a part of an item previously allocated with AppendFutureData. 60 // Populates a part of an item previously allocated with AppendFutureData.
57 // The first call to PopulateFutureData lazily allocates the memory for the 61 // The first call to PopulateFutureData lazily allocates the memory for the
58 // data element. 62 // data element.
59 // Returns true if: 63 // Returns true if:
60 // * The item was created by using AppendFutureData, 64 // * The item was created by using AppendFutureData,
61 // * The offset and length are valid, and 65 // * The offset and length are valid, and
62 // * data is a valid pointer. 66 // * data is a valid pointer.
63 bool PopulateFutureData(size_t index, 67 bool PopulateFutureData(size_t index,
64 const char* data, 68 const char* data,
65 size_t offset, 69 size_t offset,
66 size_t length); 70 size_t length);
67 71
72 // Adds an item that is flagged for future data population. Use
73 // 'PopulateFutureFile' to set the file path and expected modification time
74 // of this file. Returns the index of the item (to be used in
75 // PopulateFutureFile). The temporary filename used by this method is
76 // kAppendFutureFileTemporaryFileName. |length| cannot be 0.
77 size_t AppendFutureFile(uint64_t offset, uint64_t length);
78
79 // Populates a part of an item previously allocated with AppendFutureFile.
80 // Returns true if:
81 // * The item was created by using AppendFutureFile and
82 // * The filepath is valid.
83 bool PopulateFutureFile(
84 size_t index,
85 const scoped_refptr<ShareableFileReference>& file_reference,
86 const base::Time& expected_modification_time);
87
68 // You must know the length of the file, you cannot use kuint64max to specify 88 // You must know the length of the file, you cannot use kuint64max to specify
69 // the whole file. This method creates a ShareableFileReference to the given 89 // the whole file. This method creates a ShareableFileReference to the given
70 // file, which is stored in this builder. 90 // file, which is stored in this builder.
71 void AppendFile(const base::FilePath& file_path, 91 void AppendFile(const base::FilePath& file_path,
72 uint64_t offset, 92 uint64_t offset,
73 uint64_t length, 93 uint64_t length,
74 const base::Time& expected_modification_time); 94 const base::Time& expected_modification_time);
75 95
76 void AppendBlob(const std::string& uuid, uint64_t offset, uint64_t length); 96 void AppendBlob(const std::string& uuid, uint64_t offset, uint64_t length);
77 97
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 } 169 }
150 170
151 inline bool operator!=(const BlobDataBuilder& a, const BlobDataBuilder& b) { 171 inline bool operator!=(const BlobDataBuilder& a, const BlobDataBuilder& b) {
152 return !(a == b); 172 return !(a == b);
153 } 173 }
154 174
155 #endif // defined(UNIT_TEST) 175 #endif // defined(UNIT_TEST)
156 176
157 } // namespace storage 177 } // namespace storage
158 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_ 178 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_
OLDNEW
« no previous file with comments | « storage/browser/blob/blob_async_transport_strategy.cc ('k') | storage/browser/blob/blob_data_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698