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 <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 ipc_data.offset(), length, | 276 ipc_data.offset(), length, |
277 ipc_data.expected_modification_time()); | 277 ipc_data.expected_modification_time()); |
278 blob_item = new BlobDataItem(element.Pass()); | 278 blob_item = new BlobDataItem(element.Pass()); |
279 break; | 279 break; |
280 case DataElement::TYPE_BLOB: | 280 case DataElement::TYPE_BLOB: |
281 // This is a temporary item that will be deconstructed later. | 281 // This is a temporary item that will be deconstructed later. |
282 element->SetToBlobRange(ipc_data.blob_uuid(), ipc_data.offset(), | 282 element->SetToBlobRange(ipc_data.blob_uuid(), ipc_data.offset(), |
283 ipc_data.length()); | 283 ipc_data.length()); |
284 blob_item = new BlobDataItem(element.Pass()); | 284 blob_item = new BlobDataItem(element.Pass()); |
285 break; | 285 break; |
286 case DataElement::TYPE_DISK_CACHE_ENTRY: // This type can't be sent by IPC. | |
287 NOTREACHED(); | |
288 break; | |
286 default: | 289 default: |
287 NOTREACHED(); | 290 NOTREACHED(); |
288 break; | 291 break; |
289 } | 292 } |
290 | 293 |
291 return blob_item; | 294 return blob_item; |
292 } | 295 } |
293 | 296 |
294 bool BlobStorageContext::AppendAllocatedBlobItem( | 297 bool BlobStorageContext::AppendAllocatedBlobItem( |
295 const std::string& target_blob_uuid, | 298 const std::string& target_blob_uuid, |
296 scoped_refptr<BlobDataItem> blob_item, | 299 scoped_refptr<BlobDataItem> blob_item, |
297 InternalBlobData::Builder* target_blob_builder) { | 300 InternalBlobData::Builder* target_blob_builder) { |
298 bool exceeded_memory = false; | 301 bool exceeded_memory = false; |
299 | 302 |
300 // The blob data is stored in the canonical way which only contains a | 303 // The blob data is stored in the canonical way which only contains a |
301 // list of Data, File, and FileSystem items. Aggregated TYPE_BLOB items | 304 // list of Data, File, and FileSystem items. Aggregated TYPE_BLOB items |
302 // are expanded into the primitive constituent types and reused if possible. | 305 // are expanded into the primitive constituent types and reused if possible. |
303 // 1) The Data item is denoted by the raw data and length. | 306 // 1) The Data item is denoted by the raw data and length. |
304 // 2) The File item is denoted by the file path, the range and the expected | 307 // 2) The File item is denoted by the file path, the range and the expected |
305 // modification time. | 308 // modification time. |
306 // 3) The FileSystem File item is denoted by the FileSystem URL, the range | 309 // 3) The FileSystem File item is denoted by the FileSystem URL, the range |
307 // and the expected modification time. | 310 // and the expected modification time. |
308 // 4) The Blob item is denoted by the source blob and an offset and size. | 311 // 4) The Blob item is denoted by the source blob and an offset and size. |
309 // Internal items that are fully used by the new blob (not cut by the | 312 // Internal items that are fully used by the new blob (not cut by the |
310 // offset or size) are shared between the blobs. Otherwise, the relevant | 313 // offset or size) are shared between the blobs. Otherwise, the relevant |
311 // portion of the item is copied. | 314 // portion of the item is copied. |
315 // 5) The Disk Cache entry is denoted by the disk_cache::Entry* and the | |
316 // stream number. The entire stream is used. | |
312 | 317 |
313 const DataElement& data_element = blob_item->data_element(); | 318 uint64 length = blob_item->GetLength(); |
314 uint64 length = data_element.length(); | 319 uint64 offset = blob_item->GetOffset(); |
315 uint64 offset = data_element.offset(); | |
316 UMA_HISTOGRAM_COUNTS("Storage.Blob.StorageSizeBeforeAppend", | 320 UMA_HISTOGRAM_COUNTS("Storage.Blob.StorageSizeBeforeAppend", |
317 memory_usage_ / 1024); | 321 memory_usage_ / 1024); |
318 switch (data_element.type()) { | 322 switch (blob_item->data_element().type()) { |
319 case DataElement::TYPE_BYTES: | 323 case DataElement::TYPE_BYTES: |
320 UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.Bytes", length / 1024); | 324 UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.Bytes", length / 1024); |
321 DCHECK(!offset); | 325 DCHECK(!offset); |
322 if (memory_usage_ + length > kMaxMemoryUsage) { | 326 if (memory_usage_ + length > kMaxMemoryUsage) { |
323 exceeded_memory = true; | 327 exceeded_memory = true; |
324 break; | 328 break; |
325 } | 329 } |
326 memory_usage_ += length; | 330 memory_usage_ += length; |
327 target_blob_builder->AppendSharedBlobItem( | 331 target_blob_builder->AppendSharedBlobItem( |
328 new ShareableBlobDataItem(target_blob_uuid, blob_item)); | 332 new ShareableBlobDataItem(target_blob_uuid, blob_item)); |
(...skipping 19 matching lines...) Expand all Loading... | |
348 } | 352 } |
349 target_blob_builder->AppendSharedBlobItem( | 353 target_blob_builder->AppendSharedBlobItem( |
350 new ShareableBlobDataItem(target_blob_uuid, blob_item)); | 354 new ShareableBlobDataItem(target_blob_uuid, blob_item)); |
351 break; | 355 break; |
352 } | 356 } |
353 case DataElement::TYPE_BLOB: { | 357 case DataElement::TYPE_BLOB: { |
354 UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.Blob", | 358 UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.Blob", |
355 (length - offset) / 1024); | 359 (length - offset) / 1024); |
356 // We grab the handle to ensure it stays around while we copy it. | 360 // We grab the handle to ensure it stays around while we copy it. |
357 scoped_ptr<BlobDataHandle> src = | 361 scoped_ptr<BlobDataHandle> src = |
358 GetBlobDataFromUUID(data_element.blob_uuid()); | 362 GetBlobDataFromUUID(blob_item->data_element().blob_uuid()); |
359 if (src) { | 363 if (src) { |
360 BlobMapEntry* other_entry = | 364 BlobMapEntry* other_entry = |
361 blob_map_.find(data_element.blob_uuid())->second; | 365 blob_map_.find(blob_item->data_element().blob_uuid())->second; |
362 DCHECK(other_entry->data); | 366 DCHECK(other_entry->data); |
363 exceeded_memory = !AppendBlob(target_blob_uuid, *other_entry->data, | 367 exceeded_memory = !AppendBlob(target_blob_uuid, *other_entry->data, |
364 offset, length, target_blob_builder); | 368 offset, length, target_blob_builder); |
365 } | 369 } |
366 break; | 370 break; |
367 } | 371 } |
372 case DataElement::TYPE_DISK_CACHE_ENTRY: { | |
373 UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.CacheEntry", | |
374 (length - offset) / 1024); | |
375 target_blob_builder->AppendSharedBlobItem( | |
376 new ShareableBlobDataItem(target_blob_uuid, blob_item)); | |
377 break; | |
378 } | |
368 default: | 379 default: |
369 NOTREACHED(); | 380 NOTREACHED(); |
370 break; | 381 break; |
371 } | 382 } |
372 UMA_HISTOGRAM_COUNTS("Storage.Blob.StorageSizeAfterAppend", | 383 UMA_HISTOGRAM_COUNTS("Storage.Blob.StorageSizeAfterAppend", |
373 memory_usage_ / 1024); | 384 memory_usage_ / 1024); |
374 | 385 |
375 return !exceeded_memory; | 386 return !exceeded_memory; |
376 } | 387 } |
377 | 388 |
(...skipping 18 matching lines...) Expand all Loading... | |
396 } | 407 } |
397 | 408 |
398 for (; iter != items.end() && length > 0; ++iter) { | 409 for (; iter != items.end() && length > 0; ++iter) { |
399 scoped_refptr<ShareableBlobDataItem> shareable_item = iter->get(); | 410 scoped_refptr<ShareableBlobDataItem> shareable_item = iter->get(); |
400 const BlobDataItem& item = *(shareable_item->item()); | 411 const BlobDataItem& item = *(shareable_item->item()); |
401 uint64_t item_length = item.GetLength(); | 412 uint64_t item_length = item.GetLength(); |
402 DCHECK_GT(item_length, offset); | 413 DCHECK_GT(item_length, offset); |
403 uint64_t current_length = item_length - offset; | 414 uint64_t current_length = item_length - offset; |
404 uint64_t new_length = current_length > length ? length : current_length; | 415 uint64_t new_length = current_length > length ? length : current_length; |
405 | 416 |
406 bool reusing_blob_item = offset == 0 && new_length == item_length; | 417 // Always reuse disk cache entries, as they never have an offset or length. |
dmurph
2015/05/29 19:13:43
Ah, this might be a problem. If I try to splice a
gavinp
2015/06/04 18:40:00
OK, I went through this, and I think I get it. I w
| |
418 bool reusing_blob_item = | |
419 item.type() == DataElement::TYPE_DISK_CACHE_ENTRY || | |
420 (offset == 0 && new_length == item_length); | |
407 UMA_HISTOGRAM_BOOLEAN("Storage.Blob.ReusedItem", reusing_blob_item); | 421 UMA_HISTOGRAM_BOOLEAN("Storage.Blob.ReusedItem", reusing_blob_item); |
408 if (reusing_blob_item) { | 422 if (reusing_blob_item) { |
409 shareable_item->referencing_blobs().insert(target_blob_uuid); | 423 shareable_item->referencing_blobs().insert(target_blob_uuid); |
410 target_blob_builder->AppendSharedBlobItem(shareable_item); | 424 target_blob_builder->AppendSharedBlobItem(shareable_item); |
411 length -= new_length; | 425 length -= new_length; |
412 continue; | 426 continue; |
413 } | 427 } |
414 | 428 |
415 // We need to do copying of the items when we have a different offset or | 429 // We need to do copying of the items when we have a different offset or |
416 // length | 430 // length |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
470 if (found == blob_map_.end()) | 484 if (found == blob_map_.end()) |
471 return false; | 485 return false; |
472 return found->second->IsBeingBuilt(); | 486 return found->second->IsBeingBuilt(); |
473 } | 487 } |
474 | 488 |
475 bool BlobStorageContext::IsUrlRegistered(const GURL& blob_url) { | 489 bool BlobStorageContext::IsUrlRegistered(const GURL& blob_url) { |
476 return public_blob_urls_.find(blob_url) != public_blob_urls_.end(); | 490 return public_blob_urls_.find(blob_url) != public_blob_urls_.end(); |
477 } | 491 } |
478 | 492 |
479 } // namespace storage | 493 } // namespace storage |
OLD | NEW |