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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 } | 368 } |
369 UMA_HISTOGRAM_COUNTS("Storage.Blob.StorageSizeAfterAppend", | 369 UMA_HISTOGRAM_COUNTS("Storage.Blob.StorageSizeAfterAppend", |
370 memory_usage_ / 1024); | 370 memory_usage_ / 1024); |
371 | 371 |
372 return !exceeded_memory; | 372 return !exceeded_memory; |
373 } | 373 } |
374 | 374 |
375 bool BlobStorageContext::AppendBlob( | 375 bool BlobStorageContext::AppendBlob( |
376 const std::string& target_blob_uuid, | 376 const std::string& target_blob_uuid, |
377 const InternalBlobData& blob, | 377 const InternalBlobData& blob, |
378 size_t offset, | 378 uint64_t offset, |
379 size_t length, | 379 uint64_t length, |
380 InternalBlobData::Builder* target_blob_builder) { | 380 InternalBlobData::Builder* target_blob_builder) { |
381 DCHECK(length > 0); | 381 DCHECK(length > 0); |
382 | 382 |
383 const std::vector<scoped_refptr<ShareableBlobDataItem>>& items = blob.items(); | 383 const std::vector<scoped_refptr<ShareableBlobDataItem>>& items = blob.items(); |
384 auto iter = items.begin(); | 384 auto iter = items.begin(); |
385 if (offset) { | 385 if (offset) { |
386 for (; iter != items.end(); ++iter) { | 386 for (; iter != items.end(); ++iter) { |
387 const BlobDataItem& item = *(iter->get()->item()); | 387 const BlobDataItem& item = *(iter->get()->item()); |
388 if (offset >= item.length()) | 388 if (offset >= item.length()) |
389 offset -= item.length(); | 389 offset -= item.length(); |
390 else | 390 else |
391 break; | 391 break; |
392 } | 392 } |
393 } | 393 } |
394 | 394 |
395 for (; iter != items.end() && length > 0; ++iter) { | 395 for (; iter != items.end() && length > 0; ++iter) { |
396 scoped_refptr<ShareableBlobDataItem> shareable_item = iter->get(); | 396 scoped_refptr<ShareableBlobDataItem> shareable_item = iter->get(); |
397 const BlobDataItem& item = *(shareable_item->item()); | 397 const BlobDataItem& item = *(shareable_item->item()); |
398 size_t item_length = item.length(); | 398 uint64_t item_length = item.length(); |
399 DCHECK_GT(item_length, offset); | 399 DCHECK_GT(item_length, offset); |
400 size_t current_length = item_length - offset; | 400 uint64_t current_length = item_length - offset; |
401 size_t new_length = current_length > length ? length : current_length; | 401 uint64_t new_length = current_length > length ? length : current_length; |
402 | 402 |
403 bool reusing_blob_item = offset == 0 && new_length == item.length(); | 403 bool reusing_blob_item = offset == 0 && new_length == item.length(); |
404 UMA_HISTOGRAM_BOOLEAN("Storage.Blob.ReusedItem", reusing_blob_item); | 404 UMA_HISTOGRAM_BOOLEAN("Storage.Blob.ReusedItem", reusing_blob_item); |
405 if (reusing_blob_item) { | 405 if (reusing_blob_item) { |
406 shareable_item->referencing_blobs().insert(target_blob_uuid); | 406 shareable_item->referencing_blobs().insert(target_blob_uuid); |
407 target_blob_builder->AppendSharedBlobItem(shareable_item); | 407 target_blob_builder->AppendSharedBlobItem(shareable_item); |
408 length -= new_length; | 408 length -= new_length; |
409 continue; | 409 continue; |
410 } | 410 } |
411 | 411 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 if (found == blob_map_.end()) | 467 if (found == blob_map_.end()) |
468 return false; | 468 return false; |
469 return found->second->IsBeingBuilt(); | 469 return found->second->IsBeingBuilt(); |
470 } | 470 } |
471 | 471 |
472 bool BlobStorageContext::IsUrlRegistered(const GURL& blob_url) { | 472 bool BlobStorageContext::IsUrlRegistered(const GURL& blob_url) { |
473 return public_blob_urls_.find(blob_url) != public_blob_urls_.end(); | 473 return public_blob_urls_.find(blob_url) != public_blob_urls_.end(); |
474 } | 474 } |
475 | 475 |
476 } // namespace storage | 476 } // namespace storage |
OLD | NEW |