| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 scoped_ptr<BlobDataHandle> BlobStorageContext::GetBlobDataFromPublicURL( | 86 scoped_ptr<BlobDataHandle> BlobStorageContext::GetBlobDataFromPublicURL( |
| 87 const GURL& url) { | 87 const GURL& url) { |
| 88 BlobURLMap::iterator found = | 88 BlobURLMap::iterator found = |
| 89 public_blob_urls_.find(BlobUrlHasRef(url) ? ClearBlobUrlRef(url) : url); | 89 public_blob_urls_.find(BlobUrlHasRef(url) ? ClearBlobUrlRef(url) : url); |
| 90 if (found == public_blob_urls_.end()) | 90 if (found == public_blob_urls_.end()) |
| 91 return scoped_ptr<BlobDataHandle>(); | 91 return scoped_ptr<BlobDataHandle>(); |
| 92 return GetBlobDataFromUUID(found->second); | 92 return GetBlobDataFromUUID(found->second); |
| 93 } | 93 } |
| 94 | 94 |
| 95 scoped_ptr<BlobDataHandle> BlobStorageContext::AddFinishedBlob( | 95 scoped_ptr<BlobDataHandle> BlobStorageContext::AddFinishedBlob( |
| 96 BlobDataBuilder* external_builder) { | 96 const BlobDataBuilder& external_builder) { |
| 97 TRACE_EVENT0("Blob", "Context::AddFinishedBlob"); | 97 TRACE_EVENT0("Blob", "Context::AddFinishedBlob"); |
| 98 StartBuildingBlob(external_builder->uuid_); | 98 StartBuildingBlob(external_builder.uuid_); |
| 99 BlobMap::iterator found = blob_map_.find(external_builder->uuid_); | 99 BlobMap::iterator found = blob_map_.find(external_builder.uuid_); |
| 100 DCHECK(found != blob_map_.end()); | 100 DCHECK(found != blob_map_.end()); |
| 101 BlobMapEntry* entry = found->second; | 101 BlobMapEntry* entry = found->second; |
| 102 InternalBlobData::Builder* target_blob_builder = entry->data_builder.get(); | 102 InternalBlobData::Builder* target_blob_builder = entry->data_builder.get(); |
| 103 DCHECK(target_blob_builder); | 103 DCHECK(target_blob_builder); |
| 104 | 104 |
| 105 target_blob_builder->set_content_disposition( | 105 target_blob_builder->set_content_disposition( |
| 106 external_builder->content_disposition_); | 106 external_builder.content_disposition_); |
| 107 for (const auto& blob_item : external_builder->items_) { | 107 for (const auto& blob_item : external_builder.items_) { |
| 108 if (!AppendAllocatedBlobItem(external_builder->uuid_, blob_item, | 108 if (!AppendAllocatedBlobItem(external_builder.uuid_, blob_item, |
| 109 target_blob_builder)) { | 109 target_blob_builder)) { |
| 110 BlobEntryExceededMemory(entry); | 110 BlobEntryExceededMemory(entry); |
| 111 break; | 111 break; |
| 112 } | 112 } |
| 113 } | 113 } |
| 114 | 114 |
| 115 FinishBuildingBlob(external_builder->uuid_, external_builder->content_type_); | 115 FinishBuildingBlob(external_builder.uuid_, external_builder.content_type_); |
| 116 scoped_ptr<BlobDataHandle> handle = | 116 scoped_ptr<BlobDataHandle> handle = |
| 117 GetBlobDataFromUUID(external_builder->uuid_); | 117 GetBlobDataFromUUID(external_builder.uuid_); |
| 118 DecrementBlobRefCount(external_builder->uuid_); | 118 DecrementBlobRefCount(external_builder.uuid_); |
| 119 return handle.Pass(); | 119 return handle.Pass(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 scoped_ptr<BlobDataHandle> BlobStorageContext::AddFinishedBlob( |
| 123 const BlobDataBuilder* builder) { |
| 124 DCHECK(builder); |
| 125 return AddFinishedBlob(*builder); |
| 126 } |
| 127 |
| 122 bool BlobStorageContext::RegisterPublicBlobURL(const GURL& blob_url, | 128 bool BlobStorageContext::RegisterPublicBlobURL(const GURL& blob_url, |
| 123 const std::string& uuid) { | 129 const std::string& uuid) { |
| 124 DCHECK(!BlobUrlHasRef(blob_url)); | 130 DCHECK(!BlobUrlHasRef(blob_url)); |
| 125 DCHECK(IsInUse(uuid)); | 131 DCHECK(IsInUse(uuid)); |
| 126 DCHECK(!IsUrlRegistered(blob_url)); | 132 DCHECK(!IsUrlRegistered(blob_url)); |
| 127 if (!IsInUse(uuid) || IsUrlRegistered(blob_url)) | 133 if (!IsInUse(uuid) || IsUrlRegistered(blob_url)) |
| 128 return false; | 134 return false; |
| 129 IncrementBlobRefCount(uuid); | 135 IncrementBlobRefCount(uuid); |
| 130 public_blob_urls_[blob_url] = uuid; | 136 public_blob_urls_[blob_url] = uuid; |
| 131 return true; | 137 return true; |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 if (found == blob_map_.end()) | 497 if (found == blob_map_.end()) |
| 492 return false; | 498 return false; |
| 493 return found->second->IsBeingBuilt(); | 499 return found->second->IsBeingBuilt(); |
| 494 } | 500 } |
| 495 | 501 |
| 496 bool BlobStorageContext::IsUrlRegistered(const GURL& blob_url) { | 502 bool BlobStorageContext::IsUrlRegistered(const GURL& blob_url) { |
| 497 return public_blob_urls_.find(blob_url) != public_blob_urls_.end(); | 503 return public_blob_urls_.find(blob_url) != public_blob_urls_.end(); |
| 498 } | 504 } |
| 499 | 505 |
| 500 } // namespace storage | 506 } // namespace storage |
| OLD | NEW |