OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #include "storage/browser/blob/blob_storage_context.h" | 5 #include "storage/browser/blob/blob_storage_context.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/stl_util.h" | |
12 #include "storage/browser/blob/blob_data_handle.h" | 13 #include "storage/browser/blob/blob_data_handle.h" |
13 #include "storage/common/blob/blob_data.h" | 14 #include "storage/common/blob/blob_data.h" |
14 #include "url/gurl.h" | 15 #include "url/gurl.h" |
15 | 16 |
16 namespace storage { | 17 namespace storage { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 // We can't use GURL directly for these hash fragment manipulations | 21 // We can't use GURL directly for these hash fragment manipulations |
21 // since it doesn't have specific knowlege of the BlobURL format. GURL | 22 // since it doesn't have specific knowlege of the BlobURL format. GURL |
(...skipping 14 matching lines...) Expand all Loading... | |
36 // TODO(michaeln): use base::SysInfo::AmountOfPhysicalMemoryMB() in some | 37 // TODO(michaeln): use base::SysInfo::AmountOfPhysicalMemoryMB() in some |
37 // way to come up with a better limit. | 38 // way to come up with a better limit. |
38 static const int64 kMaxMemoryUsage = 500 * 1024 * 1024; // Half a gig. | 39 static const int64 kMaxMemoryUsage = 500 * 1024 * 1024; // Half a gig. |
39 | 40 |
40 } // namespace | 41 } // namespace |
41 | 42 |
42 BlobStorageContext::BlobMapEntry::BlobMapEntry() | 43 BlobStorageContext::BlobMapEntry::BlobMapEntry() |
43 : refcount(0), flags(0) { | 44 : refcount(0), flags(0) { |
44 } | 45 } |
45 | 46 |
46 BlobStorageContext::BlobMapEntry::BlobMapEntry( | 47 BlobStorageContext::BlobMapEntry::BlobMapEntry(int refcount, |
47 int refcount, int flags, BlobData* data) | 48 int flags, |
48 : refcount(refcount), flags(flags), data(data) { | 49 BlobDataBuilder* data) |
50 : refcount(refcount), flags(flags), data_builder(data) { | |
49 } | 51 } |
50 | 52 |
51 BlobStorageContext::BlobMapEntry::~BlobMapEntry() { | 53 BlobStorageContext::BlobMapEntry::~BlobMapEntry() { |
52 } | 54 } |
53 | 55 |
54 BlobStorageContext::BlobStorageContext() | 56 BlobStorageContext::BlobStorageContext() |
55 : memory_usage_(0) { | 57 : memory_usage_(0) { |
56 } | 58 } |
57 | 59 |
58 BlobStorageContext::~BlobStorageContext() { | 60 BlobStorageContext::~BlobStorageContext() { |
61 STLDeleteContainerPairSecondPointers(blob_map_.begin(), blob_map_.end()); | |
59 } | 62 } |
60 | 63 |
61 scoped_ptr<BlobDataHandle> BlobStorageContext::GetBlobDataFromUUID( | 64 scoped_ptr<BlobDataHandle> BlobStorageContext::GetBlobDataFromUUID( |
62 const std::string& uuid) { | 65 const std::string& uuid) { |
63 scoped_ptr<BlobDataHandle> result; | 66 scoped_ptr<BlobDataHandle> result; |
64 BlobMap::iterator found = blob_map_.find(uuid); | 67 BlobMap::iterator found = blob_map_.find(uuid); |
65 if (found == blob_map_.end()) | 68 if (found == blob_map_.end()) |
66 return result.Pass(); | 69 return result.Pass(); |
67 if (found->second.flags & EXCEEDED_MEMORY) | 70 auto* entry = found->second; |
71 if (entry->flags & EXCEEDED_MEMORY) | |
68 return result.Pass(); | 72 return result.Pass(); |
69 DCHECK(!(found->second.flags & BEING_BUILT)); | 73 DCHECK(!(entry->flags & BEING_BUILT)); |
70 result.reset(new BlobDataHandle( | 74 result.reset( |
71 found->second.data.get(), this, base::MessageLoopProxy::current().get())); | 75 new BlobDataHandle(uuid, this, base::MessageLoopProxy::current().get())); |
72 return result.Pass(); | 76 return result.Pass(); |
73 } | 77 } |
74 | 78 |
75 scoped_ptr<BlobDataHandle> BlobStorageContext::GetBlobDataFromPublicURL( | 79 scoped_ptr<BlobDataHandle> BlobStorageContext::GetBlobDataFromPublicURL( |
76 const GURL& url) { | 80 const GURL& url) { |
77 BlobURLMap::iterator found = public_blob_urls_.find( | 81 BlobURLMap::iterator found = public_blob_urls_.find( |
78 BlobUrlHasRef(url) ? ClearBlobUrlRef(url) : url); | 82 BlobUrlHasRef(url) ? ClearBlobUrlRef(url) : url); |
79 if (found == public_blob_urls_.end()) | 83 if (found == public_blob_urls_.end()) |
80 return scoped_ptr<BlobDataHandle>(); | 84 return scoped_ptr<BlobDataHandle>(); |
81 return GetBlobDataFromUUID(found->second); | 85 return GetBlobDataFromUUID(found->second); |
82 } | 86 } |
83 | 87 |
84 scoped_ptr<BlobDataHandle> BlobStorageContext::AddFinishedBlob( | 88 scoped_ptr<BlobDataHandle> BlobStorageContext::AddFinishedBlob( |
85 const BlobData* data) { | 89 const BlobDataBuilder& data) { |
86 StartBuildingBlob(data->uuid()); | 90 StartBuildingBlob(data.uuid_); |
87 for (std::vector<BlobData::Item>::const_iterator iter = | 91 for (const auto& blob_item : data.items_) { |
michaeln
2015/01/21 01:46:41
nit {}'s not needed
dmurph
2015/01/21 22:40:11
Done.
| |
88 data->items().begin(); | 92 AppendBlobDataItem(data.uuid_, *(blob_item->item_)); |
89 iter != data->items().end(); ++iter) { | |
90 AppendBlobDataItem(data->uuid(), *iter); | |
91 } | 93 } |
92 FinishBuildingBlob(data->uuid(), data->content_type()); | 94 FinishBuildingBlob(data.uuid_, data.content_type_); |
93 scoped_ptr<BlobDataHandle> handle = GetBlobDataFromUUID(data->uuid()); | 95 scoped_ptr<BlobDataHandle> handle = GetBlobDataFromUUID(data.uuid_); |
94 DecrementBlobRefCount(data->uuid()); | 96 DecrementBlobRefCount(data.uuid_); |
95 return handle.Pass(); | 97 return handle.Pass(); |
96 } | 98 } |
97 | 99 |
98 bool BlobStorageContext::RegisterPublicBlobURL( | 100 bool BlobStorageContext::RegisterPublicBlobURL( |
99 const GURL& blob_url, const std::string& uuid) { | 101 const GURL& blob_url, const std::string& uuid) { |
100 DCHECK(!BlobUrlHasRef(blob_url)); | 102 DCHECK(!BlobUrlHasRef(blob_url)); |
101 DCHECK(IsInUse(uuid)); | 103 DCHECK(IsInUse(uuid)); |
102 DCHECK(!IsUrlRegistered(blob_url)); | 104 DCHECK(!IsUrlRegistered(blob_url)); |
103 if (!IsInUse(uuid) || IsUrlRegistered(blob_url)) | 105 if (!IsInUse(uuid) || IsUrlRegistered(blob_url)) |
104 return false; | 106 return false; |
105 IncrementBlobRefCount(uuid); | 107 IncrementBlobRefCount(uuid); |
106 public_blob_urls_[blob_url] = uuid; | 108 public_blob_urls_[blob_url] = uuid; |
107 return true; | 109 return true; |
108 } | 110 } |
109 | 111 |
110 void BlobStorageContext::RevokePublicBlobURL(const GURL& blob_url) { | 112 void BlobStorageContext::RevokePublicBlobURL(const GURL& blob_url) { |
111 DCHECK(!BlobUrlHasRef(blob_url)); | 113 DCHECK(!BlobUrlHasRef(blob_url)); |
112 if (!IsUrlRegistered(blob_url)) | 114 if (!IsUrlRegistered(blob_url)) |
113 return; | 115 return; |
114 DecrementBlobRefCount(public_blob_urls_[blob_url]); | 116 DecrementBlobRefCount(public_blob_urls_[blob_url]); |
115 public_blob_urls_.erase(blob_url); | 117 public_blob_urls_.erase(blob_url); |
116 } | 118 } |
117 | 119 |
120 scoped_ptr<BlobDataSnapshot> BlobStorageContext::CreateSnapshot( | |
121 const std::string& uuid) { | |
122 scoped_ptr<BlobDataSnapshot> result; | |
123 auto found = blob_map_.find(uuid); | |
124 DCHECK(found != blob_map_.end()) | |
125 << "Blob should be in map, as the handle is still around"; | |
126 auto* entry = found->second; | |
michaeln
2015/01/21 01:46:41
Probably writing BlobMapEntry* instead of auto* wo
dmurph
2015/01/21 22:40:11
Done.
| |
127 DCHECK(!(entry->flags & BEING_BUILT)); | |
128 result.reset(new BlobDataSnapshot(*entry->data)); | |
129 return result.Pass(); | |
130 } | |
131 | |
118 void BlobStorageContext::StartBuildingBlob(const std::string& uuid) { | 132 void BlobStorageContext::StartBuildingBlob(const std::string& uuid) { |
119 DCHECK(!IsInUse(uuid) && !uuid.empty()); | 133 DCHECK(!IsInUse(uuid) && !uuid.empty()); |
120 blob_map_[uuid] = BlobMapEntry(1, BEING_BUILT, new BlobData(uuid)); | 134 blob_map_[uuid] = new BlobMapEntry(1, BEING_BUILT, new BlobDataBuilder(uuid)); |
121 } | 135 } |
122 | 136 |
123 void BlobStorageContext::AppendBlobDataItem( | 137 void BlobStorageContext::AppendBlobDataItem(const std::string& uuid, |
124 const std::string& uuid, const BlobData::Item& item) { | 138 const DataElement& item) { |
125 DCHECK(IsBeingBuilt(uuid)); | 139 DCHECK(IsBeingBuilt(uuid)); |
126 BlobMap::iterator found = blob_map_.find(uuid); | 140 BlobMap::iterator found = blob_map_.find(uuid); |
127 if (found == blob_map_.end()) | 141 if (found == blob_map_.end()) |
128 return; | 142 return; |
129 if (found->second.flags & EXCEEDED_MEMORY) | 143 auto* entry = found->second; |
michaeln
2015/01/21 01:46:41
ditto BlobMapEntry*
dmurph
2015/01/21 22:40:11
Done.
| |
144 if (entry->flags & EXCEEDED_MEMORY) | |
130 return; | 145 return; |
131 BlobData* target_blob_data = found->second.data.get(); | 146 BlobDataBuilder* target_blob_data = entry->data_builder.get(); |
132 DCHECK(target_blob_data); | 147 DCHECK(target_blob_data); |
133 | 148 |
134 bool exceeded_memory = false; | 149 bool exceeded_memory = false; |
135 | 150 |
136 // The blob data is stored in the canonical way which only contains a | 151 // The blob data is stored in the canonical way which only contains a |
137 // list of Data, File, and FileSystem items. Aggregated TYPE_BLOB items | 152 // list of Data, File, and FileSystem items. Aggregated TYPE_BLOB items |
138 // are expanded into the primitive constituent types. | 153 // are expanded into the primitive constituent types. |
139 // 1) The Data item is denoted by the raw data and length. | 154 // 1) The Data item is denoted by the raw data and length. |
140 // 2) The File item is denoted by the file path, the range and the expected | 155 // 2) The File item is denoted by the file path, the range and the expected |
141 // modification time. | 156 // modification time. |
142 // 3) The FileSystem File item is denoted by the FileSystem URL, the range | 157 // 3) The FileSystem File item is denoted by the FileSystem URL, the range |
143 // and the expected modification time. | 158 // and the expected modification time. |
144 // 4) The Blob items are expanded. | 159 // 4) The Blob items are expanded. |
145 // TODO(michaeln): Would be nice to avoid copying Data items when expanding. | 160 // TODO(michaeln): Would be nice to avoid copying Data items when expanding. |
146 | 161 |
147 uint64 length = item.length(); | 162 uint64 length = item.length(); |
148 DCHECK_GT(length, 0u); | 163 DCHECK_GT(length, 0u); |
149 UMA_HISTOGRAM_COUNTS("Storage.Blob.StorageSizeBeforeAppend", | 164 UMA_HISTOGRAM_COUNTS("Storage.Blob.StorageSizeBeforeAppend", |
150 memory_usage_ / 1024); | 165 memory_usage_ / 1024); |
151 switch (item.type()) { | 166 switch (item.type()) { |
152 case BlobData::Item::TYPE_BYTES: | 167 case DataElement::TYPE_BYTES: |
153 UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.Bytes", length / 1024); | 168 UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.Bytes", length / 1024); |
154 DCHECK(!item.offset()); | 169 DCHECK(!item.offset()); |
155 exceeded_memory = !AppendBytesItem(target_blob_data, item.bytes(), | 170 exceeded_memory = !AppendBytesItem(target_blob_data, item.bytes(), |
156 static_cast<int64>(length)); | 171 static_cast<int64>(length)); |
157 break; | 172 break; |
158 case BlobData::Item::TYPE_FILE: | 173 case DataElement::TYPE_FILE: |
159 UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.File", length / 1024); | 174 UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.File", length / 1024); |
160 AppendFileItem(target_blob_data, item.path(), item.offset(), length, | 175 AppendFileItem(target_blob_data, item.path(), item.offset(), |
161 item.expected_modification_time()); | 176 item.length(), item.expected_modification_time()); |
162 break; | 177 break; |
163 case BlobData::Item::TYPE_FILE_FILESYSTEM: | 178 case DataElement::TYPE_FILE_FILESYSTEM: |
164 UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.FileSystem", length / 1024); | 179 UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.FileSystem", length / 1024); |
165 AppendFileSystemFileItem(target_blob_data, item.filesystem_url(), | 180 AppendFileSystemFileItem(target_blob_data, item.filesystem_url(), |
166 item.offset(), length, | 181 item.offset(), item.length(), |
167 item.expected_modification_time()); | 182 item.expected_modification_time()); |
168 break; | 183 break; |
169 case BlobData::Item::TYPE_BLOB: { | 184 case DataElement::TYPE_BLOB: { |
170 UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.Blob", length / 1024); | 185 UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.Blob", length / 1024); |
186 // We grab the handle to ensure it stays around while we copy it. | |
171 scoped_ptr<BlobDataHandle> src = GetBlobDataFromUUID(item.blob_uuid()); | 187 scoped_ptr<BlobDataHandle> src = GetBlobDataFromUUID(item.blob_uuid()); |
172 if (src) | 188 if (src) { |
173 exceeded_memory = !ExpandStorageItems(target_blob_data, | 189 auto* entry = blob_map_.find(item.blob_uuid())->second;\ |
michaeln
2015/01/21 01:46:41
Ditto BlobMapEntry* vs auto*, and you probably did
dmurph
2015/01/21 22:40:11
Done.
| |
174 src->data(), | 190 DCHECK(entry->data); |
175 item.offset(), | 191 exceeded_memory = !ExpandStorageItems(target_blob_data, *entry->data, |
176 item.length()); | 192 item.offset(), item.length()); |
193 } | |
177 break; | 194 break; |
178 } | 195 } |
179 default: | 196 default: |
180 NOTREACHED(); | 197 NOTREACHED(); |
181 break; | 198 break; |
182 } | 199 } |
183 UMA_HISTOGRAM_COUNTS("Storage.Blob.StorageSizeAfterAppend", | 200 UMA_HISTOGRAM_COUNTS("Storage.Blob.StorageSizeAfterAppend", |
184 memory_usage_ / 1024); | 201 memory_usage_ / 1024); |
185 | 202 |
186 // If we're using too much memory, drop this blob's data. | 203 // If we're using too much memory, drop this blob's data. |
187 // TODO(michaeln): Blob memory storage does not yet spill over to disk, | 204 // TODO(michaeln): Blob memory storage does not yet spill over to disk, |
188 // as a stop gap, we'll prevent memory usage over a max amount. | 205 // as a stop gap, we'll prevent memory usage over a max amount. |
189 if (exceeded_memory) { | 206 if (exceeded_memory) { |
190 memory_usage_ -= target_blob_data->GetMemoryUsage(); | 207 memory_usage_ -= target_blob_data->GetMemoryUsage(); |
191 found->second.flags |= EXCEEDED_MEMORY; | 208 entry->flags |= EXCEEDED_MEMORY; |
192 found->second.data = new BlobData(uuid); | 209 entry->data_builder.reset(new BlobDataBuilder(uuid)); |
193 return; | 210 return; |
194 } | 211 } |
195 } | 212 } |
196 | 213 |
197 void BlobStorageContext::FinishBuildingBlob( | 214 void BlobStorageContext::FinishBuildingBlob( |
198 const std::string& uuid, const std::string& content_type) { | 215 const std::string& uuid, const std::string& content_type) { |
199 DCHECK(IsBeingBuilt(uuid)); | 216 DCHECK(IsBeingBuilt(uuid)); |
200 BlobMap::iterator found = blob_map_.find(uuid); | 217 BlobMap::iterator found = blob_map_.find(uuid); |
201 if (found == blob_map_.end()) | 218 if (found == blob_map_.end()) |
202 return; | 219 return; |
203 found->second.data->set_content_type(content_type); | 220 auto* entry = found->second; |
michaeln
2015/01/21 01:46:41
ditto BlobMapEntry* vs auto*
dmurph
2015/01/21 22:40:11
Done.
| |
204 found->second.flags &= ~BEING_BUILT; | 221 entry->data_builder->set_content_type(content_type); |
205 UMA_HISTOGRAM_COUNTS("Storage.Blob.ItemCount", | 222 entry->data = entry->data_builder->Build().Pass(); |
206 found->second.data->items().size()); | 223 entry->data_builder.reset(); |
207 UMA_HISTOGRAM_BOOLEAN( | 224 entry->flags &= ~BEING_BUILT; |
208 "Storage.Blob.ExceededMemory", | 225 UMA_HISTOGRAM_COUNTS("Storage.Blob.ItemCount", entry->data->items().size()); |
209 (found->second.flags & EXCEEDED_MEMORY) == EXCEEDED_MEMORY); | 226 UMA_HISTOGRAM_BOOLEAN("Storage.Blob.ExceededMemory", |
227 (entry->flags & EXCEEDED_MEMORY) == EXCEEDED_MEMORY); | |
210 } | 228 } |
211 | 229 |
212 void BlobStorageContext::CancelBuildingBlob(const std::string& uuid) { | 230 void BlobStorageContext::CancelBuildingBlob(const std::string& uuid) { |
213 DCHECK(IsBeingBuilt(uuid)); | 231 DCHECK(IsBeingBuilt(uuid)); |
214 DecrementBlobRefCount(uuid); | 232 DecrementBlobRefCount(uuid); |
215 } | 233 } |
216 | 234 |
217 void BlobStorageContext::IncrementBlobRefCount(const std::string& uuid) { | 235 void BlobStorageContext::IncrementBlobRefCount(const std::string& uuid) { |
218 BlobMap::iterator found = blob_map_.find(uuid); | 236 BlobMap::iterator found = blob_map_.find(uuid); |
219 if (found == blob_map_.end()) { | 237 if (found == blob_map_.end()) { |
220 DCHECK(false); | 238 DCHECK(false); |
221 return; | 239 return; |
222 } | 240 } |
223 ++(found->second.refcount); | 241 ++(found->second->refcount); |
224 } | 242 } |
225 | 243 |
226 void BlobStorageContext::DecrementBlobRefCount(const std::string& uuid) { | 244 void BlobStorageContext::DecrementBlobRefCount(const std::string& uuid) { |
227 BlobMap::iterator found = blob_map_.find(uuid); | 245 BlobMap::iterator found = blob_map_.find(uuid); |
228 if (found == blob_map_.end()) | 246 if (found == blob_map_.end()) |
229 return; | 247 return; |
230 DCHECK_EQ(found->second.data->uuid(), uuid); | 248 auto* entry = found->second; |
231 if (--(found->second.refcount) == 0) { | 249 DCHECK_EQ(entry->data->uuid(), uuid); |
232 memory_usage_ -= found->second.data->GetMemoryUsage(); | 250 if (--(entry->refcount) == 0) { |
251 memory_usage_ -= entry->data->GetMemoryUsage(); | |
252 delete entry; | |
233 blob_map_.erase(found); | 253 blob_map_.erase(found); |
234 } | 254 } |
235 } | 255 } |
236 | 256 |
237 bool BlobStorageContext::ExpandStorageItems( | 257 bool BlobStorageContext::ExpandStorageItems( |
238 BlobData* target_blob_data, BlobData* src_blob_data, | 258 BlobDataBuilder* target_blob_data, |
239 uint64 offset, uint64 length) { | 259 const BlobDataSnapshot& src_blob_data, |
240 DCHECK(target_blob_data && src_blob_data && | 260 uint64 offset, |
241 length != static_cast<uint64>(-1)); | 261 uint64 length) { |
262 DCHECK(target_blob_data && length != static_cast<uint64>(-1)); | |
242 | 263 |
243 std::vector<BlobData::Item>::const_iterator iter = | 264 auto& items = src_blob_data.items(); |
michaeln
2015/01/21 01:46:41
i'm wondering what type items is?
In addition to
dmurph
2015/01/21 22:40:11
It's a long type, which is why I omitted it. I pu
| |
244 src_blob_data->items().begin(); | 265 auto iter = items.begin(); |
245 if (offset) { | 266 if (offset) { |
246 for (; iter != src_blob_data->items().end(); ++iter) { | 267 for (; iter != items.end(); ++iter) { |
247 if (offset >= iter->length()) | 268 const BlobDataItem& item = *(iter->get()); |
248 offset -= iter->length(); | 269 if (offset >= item.length()) |
270 offset -= item.length(); | |
249 else | 271 else |
250 break; | 272 break; |
251 } | 273 } |
252 } | 274 } |
253 | 275 |
254 for (; iter != src_blob_data->items().end() && length > 0; ++iter) { | 276 for (; iter != items.end() && length > 0; ++iter) { |
255 uint64 current_length = iter->length() - offset; | 277 const BlobDataItem& item = *(iter->get()); |
278 uint64 current_length = item.length() - offset; | |
256 uint64 new_length = current_length > length ? length : current_length; | 279 uint64 new_length = current_length > length ? length : current_length; |
257 if (iter->type() == BlobData::Item::TYPE_BYTES) { | 280 if (iter->get()->type() == DataElement::TYPE_BYTES) { |
258 if (!AppendBytesItem( | 281 if (!AppendBytesItem( |
259 target_blob_data, | 282 target_blob_data, |
260 iter->bytes() + static_cast<size_t>(iter->offset() + offset), | 283 item.bytes() + static_cast<size_t>(item.offset() + offset), |
261 static_cast<int64>(new_length))) { | 284 static_cast<int64>(new_length))) { |
262 return false; // exceeded memory | 285 return false; // exceeded memory |
263 } | 286 } |
264 } else if (iter->type() == BlobData::Item::TYPE_FILE) { | 287 } else if (item.type() == DataElement::TYPE_FILE) { |
265 AppendFileItem(target_blob_data, | 288 AppendFileItem(target_blob_data, item.path(), item.offset() + offset, |
266 iter->path(), | 289 new_length, item.expected_modification_time()); |
267 iter->offset() + offset, | |
268 new_length, | |
269 iter->expected_modification_time()); | |
270 } else { | 290 } else { |
271 DCHECK(iter->type() == BlobData::Item::TYPE_FILE_FILESYSTEM); | 291 DCHECK(item.type() == DataElement::TYPE_FILE_FILESYSTEM); |
272 AppendFileSystemFileItem(target_blob_data, | 292 AppendFileSystemFileItem(target_blob_data, item.filesystem_url(), |
273 iter->filesystem_url(), | 293 item.offset() + offset, new_length, |
274 iter->offset() + offset, | 294 item.expected_modification_time()); |
275 new_length, | |
276 iter->expected_modification_time()); | |
277 } | 295 } |
278 length -= new_length; | 296 length -= new_length; |
279 offset = 0; | 297 offset = 0; |
280 } | 298 } |
281 return true; | 299 return true; |
282 } | 300 } |
283 | 301 |
284 bool BlobStorageContext::AppendBytesItem( | 302 bool BlobStorageContext::AppendBytesItem(BlobDataBuilder* target_blob_data, |
285 BlobData* target_blob_data, const char* bytes, int64 length) { | 303 const char* bytes, |
304 int64 length) { | |
286 if (length < 0) { | 305 if (length < 0) { |
287 DCHECK(false); | 306 DCHECK(false); |
288 return false; | 307 return false; |
289 } | 308 } |
290 if (memory_usage_ + length > kMaxMemoryUsage) | 309 if (memory_usage_ + length > kMaxMemoryUsage) { |
291 return false; | 310 return false; |
311 } | |
292 target_blob_data->AppendData(bytes, static_cast<size_t>(length)); | 312 target_blob_data->AppendData(bytes, static_cast<size_t>(length)); |
293 memory_usage_ += length; | 313 memory_usage_ += length; |
294 return true; | 314 return true; |
295 } | 315 } |
296 | 316 |
297 void BlobStorageContext::AppendFileItem( | 317 void BlobStorageContext::AppendFileItem( |
298 BlobData* target_blob_data, | 318 BlobDataBuilder* target_blob_data, |
299 const base::FilePath& file_path, uint64 offset, uint64 length, | 319 const base::FilePath& file_path, |
320 uint64 offset, | |
321 uint64 length, | |
300 const base::Time& expected_modification_time) { | 322 const base::Time& expected_modification_time) { |
301 target_blob_data->AppendFile(file_path, offset, length, | |
302 expected_modification_time); | |
303 | |
304 // It may be a temporary file that should be deleted when no longer needed. | 323 // It may be a temporary file that should be deleted when no longer needed. |
305 scoped_refptr<ShareableFileReference> shareable_file = | 324 scoped_refptr<ShareableFileReference> shareable_file = |
306 ShareableFileReference::Get(file_path); | 325 ShareableFileReference::Get(file_path); |
307 if (shareable_file.get()) | 326 |
308 target_blob_data->AttachShareableFileReference(shareable_file.get()); | 327 target_blob_data->AppendFile(file_path, offset, length, |
328 expected_modification_time, shareable_file); | |
309 } | 329 } |
310 | 330 |
311 void BlobStorageContext::AppendFileSystemFileItem( | 331 void BlobStorageContext::AppendFileSystemFileItem( |
312 BlobData* target_blob_data, | 332 BlobDataBuilder* target_blob_data, |
313 const GURL& filesystem_url, uint64 offset, uint64 length, | 333 const GURL& filesystem_url, |
334 uint64 offset, | |
335 uint64 length, | |
314 const base::Time& expected_modification_time) { | 336 const base::Time& expected_modification_time) { |
315 target_blob_data->AppendFileSystemFile(filesystem_url, offset, length, | 337 target_blob_data->AppendFileSystemFile(filesystem_url, offset, length, |
316 expected_modification_time); | 338 expected_modification_time); |
317 } | 339 } |
318 | 340 |
319 bool BlobStorageContext::IsInUse(const std::string& uuid) { | 341 bool BlobStorageContext::IsInUse(const std::string& uuid) { |
320 return blob_map_.find(uuid) != blob_map_.end(); | 342 return blob_map_.find(uuid) != blob_map_.end(); |
321 } | 343 } |
322 | 344 |
323 bool BlobStorageContext::IsBeingBuilt(const std::string& uuid) { | 345 bool BlobStorageContext::IsBeingBuilt(const std::string& uuid) { |
324 BlobMap::iterator found = blob_map_.find(uuid); | 346 BlobMap::iterator found = blob_map_.find(uuid); |
325 if (found == blob_map_.end()) | 347 if (found == blob_map_.end()) |
326 return false; | 348 return false; |
327 return found->second.flags & BEING_BUILT; | 349 return (found->second->flags & BEING_BUILT) && found->second->data_builder; |
michaeln
2015/01/21 01:46:41
BEING_BUILT seems redundant now that we have the m
dmurph
2015/01/21 22:40:11
Sounds good. I'll keep 'flags' around, as we'll p
| |
328 } | 350 } |
329 | 351 |
330 bool BlobStorageContext::IsUrlRegistered(const GURL& blob_url) { | 352 bool BlobStorageContext::IsUrlRegistered(const GURL& blob_url) { |
331 return public_blob_urls_.find(blob_url) != public_blob_urls_.end(); | 353 return public_blob_urls_.find(blob_url) != public_blob_urls_.end(); |
332 } | 354 } |
333 | 355 |
334 } // namespace storage | 356 } // namespace storage |
OLD | NEW |