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" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
17 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
18 #include "storage/browser/blob/blob_data_builder.h" | 18 #include "storage/browser/blob/blob_data_builder.h" |
19 #include "storage/browser/blob/shareable_file_reference.h" | |
19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
20 | 21 |
21 namespace storage { | 22 namespace storage { |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 // We can't use GURL directly for these hash fragment manipulations | 26 // We can't use GURL directly for these hash fragment manipulations |
26 // since it doesn't have specific knowlege of the BlobURL format. GURL | 27 // since it doesn't have specific knowlege of the BlobURL format. GURL |
27 // treats BlobURLs as if they were PathURLs which don't support hash | 28 // treats BlobURLs as if they were PathURLs which don't support hash |
28 // fragments. | 29 // fragments. |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 ipc_data.offset(), length, | 277 ipc_data.offset(), length, |
277 ipc_data.expected_modification_time()); | 278 ipc_data.expected_modification_time()); |
278 blob_item = new BlobDataItem(element.Pass()); | 279 blob_item = new BlobDataItem(element.Pass()); |
279 break; | 280 break; |
280 case DataElement::TYPE_BLOB: | 281 case DataElement::TYPE_BLOB: |
281 // This is a temporary item that will be deconstructed later. | 282 // This is a temporary item that will be deconstructed later. |
282 element->SetToBlobRange(ipc_data.blob_uuid(), ipc_data.offset(), | 283 element->SetToBlobRange(ipc_data.blob_uuid(), ipc_data.offset(), |
283 ipc_data.length()); | 284 ipc_data.length()); |
284 blob_item = new BlobDataItem(element.Pass()); | 285 blob_item = new BlobDataItem(element.Pass()); |
285 break; | 286 break; |
287 case DataElement::TYPE_DISK_CACHE_ENTRY: // This type can't be sent by IPC. | |
288 NOTREACHED(); | |
289 break; | |
286 default: | 290 default: |
287 NOTREACHED(); | 291 NOTREACHED(); |
288 break; | 292 break; |
289 } | 293 } |
290 | 294 |
291 return blob_item; | 295 return blob_item; |
292 } | 296 } |
293 | 297 |
294 bool BlobStorageContext::AppendAllocatedBlobItem( | 298 bool BlobStorageContext::AppendAllocatedBlobItem( |
295 const std::string& target_blob_uuid, | 299 const std::string& target_blob_uuid, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
358 GetBlobDataFromUUID(data_element.blob_uuid()); | 362 GetBlobDataFromUUID(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(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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
414 | 425 |
415 // We need to do copying of the items when we have a different offset or | 426 // We need to do copying of the items when we have a different offset or |
416 // length | 427 // length |
417 switch (item.type()) { | 428 switch (item.type()) { |
418 case DataElement::TYPE_BYTES: { | 429 case DataElement::TYPE_BYTES: { |
419 UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.BlobSlice.Bytes", | 430 UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.BlobSlice.Bytes", |
420 new_length / 1024); | 431 new_length / 1024); |
421 if (memory_usage_ + new_length > kMaxMemoryUsage) { | 432 if (memory_usage_ + new_length > kMaxMemoryUsage) { |
422 return false; | 433 return false; |
423 } | 434 } |
424 DCHECK(!item.offset()); | 435 DCHECK(!item.offset()); |
michaeln
2015/06/15 22:17:23
gavinp: looks like it is only because of this
gavinp
2015/06/16 16:07:47
Aha, thanks.
| |
425 scoped_ptr<DataElement> element(new DataElement()); | 436 scoped_ptr<DataElement> element(new DataElement()); |
426 element->SetToBytes(item.bytes() + offset, | 437 element->SetToBytes(item.bytes() + offset, |
gavinp
2015/06/15 14:01:19
michaeln: Your comment below on line 468 got me wo
| |
427 static_cast<int64>(new_length)); | 438 static_cast<int64>(new_length)); |
428 memory_usage_ += new_length; | 439 memory_usage_ += new_length; |
429 target_blob_builder->AppendSharedBlobItem(new ShareableBlobDataItem( | 440 target_blob_builder->AppendSharedBlobItem(new ShareableBlobDataItem( |
430 target_blob_uuid, new BlobDataItem(element.Pass()))); | 441 target_blob_uuid, new BlobDataItem(element.Pass()))); |
431 } break; | 442 } break; |
432 case DataElement::TYPE_FILE: { | 443 case DataElement::TYPE_FILE: { |
433 DCHECK_NE(item.length(), std::numeric_limits<uint64>::max()) | 444 DCHECK_NE(item.length(), std::numeric_limits<uint64>::max()) |
434 << "We cannot use a section of a file with an unknown length"; | 445 << "We cannot use a section of a file with an unknown length"; |
435 UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.BlobSlice.File", | 446 UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.BlobSlice.File", |
436 new_length / 1024); | 447 new_length / 1024); |
437 scoped_ptr<DataElement> element(new DataElement()); | 448 scoped_ptr<DataElement> element(new DataElement()); |
438 element->SetToFilePathRange(item.path(), item.offset() + offset, | 449 element->SetToFilePathRange(item.path(), item.offset() + offset, |
439 new_length, | 450 new_length, |
440 item.expected_modification_time()); | 451 item.expected_modification_time()); |
441 target_blob_builder->AppendSharedBlobItem(new ShareableBlobDataItem( | 452 target_blob_builder->AppendSharedBlobItem(new ShareableBlobDataItem( |
442 target_blob_uuid, | 453 target_blob_uuid, |
443 new BlobDataItem(element.Pass(), item.file_handle_))); | 454 new BlobDataItem(element.Pass(), item.data_handle_))); |
444 } break; | 455 } break; |
445 case DataElement::TYPE_FILE_FILESYSTEM: { | 456 case DataElement::TYPE_FILE_FILESYSTEM: { |
446 UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.BlobSlice.FileSystem", | 457 UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.BlobSlice.FileSystem", |
447 new_length / 1024); | 458 new_length / 1024); |
448 scoped_ptr<DataElement> element(new DataElement()); | 459 scoped_ptr<DataElement> element(new DataElement()); |
449 element->SetToFileSystemUrlRange(item.filesystem_url(), | 460 element->SetToFileSystemUrlRange(item.filesystem_url(), |
450 item.offset() + offset, new_length, | 461 item.offset() + offset, new_length, |
451 item.expected_modification_time()); | 462 item.expected_modification_time()); |
452 target_blob_builder->AppendSharedBlobItem(new ShareableBlobDataItem( | 463 target_blob_builder->AppendSharedBlobItem(new ShareableBlobDataItem( |
453 target_blob_uuid, new BlobDataItem(element.Pass()))); | 464 target_blob_uuid, new BlobDataItem(element.Pass()))); |
454 } break; | 465 } break; |
466 case DataElement::TYPE_DISK_CACHE_ENTRY: { | |
467 scoped_ptr<DataElement> element(new DataElement()); | |
468 element->SetToDiskCacheEntryRange(item.length() + offset, | |
michaeln
2015/06/12 23:43:06
should this be item.offset() + offset ?
gavinp
2015/06/15 14:01:19
Done.
| |
469 new_length); | |
470 target_blob_builder->AppendSharedBlobItem(new ShareableBlobDataItem( | |
471 target_blob_uuid, | |
472 new BlobDataItem(element.Pass(), item.data_handle_, | |
473 item.disk_cache_entry(), | |
474 item.disk_cache_stream_index()))); | |
475 } break; | |
455 default: | 476 default: |
456 CHECK(false) << "Illegal blob item type: " << item.type(); | 477 CHECK(false) << "Illegal blob item type: " << item.type(); |
457 } | 478 } |
458 length -= new_length; | 479 length -= new_length; |
459 offset = 0; | 480 offset = 0; |
460 } | 481 } |
461 return true; | 482 return true; |
462 } | 483 } |
463 | 484 |
464 bool BlobStorageContext::IsInUse(const std::string& uuid) { | 485 bool BlobStorageContext::IsInUse(const std::string& uuid) { |
465 return blob_map_.find(uuid) != blob_map_.end(); | 486 return blob_map_.find(uuid) != blob_map_.end(); |
466 } | 487 } |
467 | 488 |
468 bool BlobStorageContext::IsBeingBuilt(const std::string& uuid) { | 489 bool BlobStorageContext::IsBeingBuilt(const std::string& uuid) { |
469 BlobMap::iterator found = blob_map_.find(uuid); | 490 BlobMap::iterator found = blob_map_.find(uuid); |
470 if (found == blob_map_.end()) | 491 if (found == blob_map_.end()) |
471 return false; | 492 return false; |
472 return found->second->IsBeingBuilt(); | 493 return found->second->IsBeingBuilt(); |
473 } | 494 } |
474 | 495 |
475 bool BlobStorageContext::IsUrlRegistered(const GURL& blob_url) { | 496 bool BlobStorageContext::IsUrlRegistered(const GURL& blob_url) { |
476 return public_blob_urls_.find(blob_url) != public_blob_urls_.end(); | 497 return public_blob_urls_.find(blob_url) != public_blob_urls_.end(); |
477 } | 498 } |
478 | 499 |
479 } // namespace storage | 500 } // namespace storage |
OLD | NEW |