| 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/message_loop/message_loop_proxy.h" | 14 #include "base/message_loop/message_loop_proxy.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 17 #include "base/trace_event/trace_event.h" |
| 17 #include "storage/browser/blob/blob_data_builder.h" | 18 #include "storage/browser/blob/blob_data_builder.h" |
| 18 #include "storage/browser/blob/blob_data_handle.h" | 19 #include "storage/browser/blob/blob_data_handle.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 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 const GURL& url) { | 86 const GURL& url) { |
| 86 BlobURLMap::iterator found = | 87 BlobURLMap::iterator found = |
| 87 public_blob_urls_.find(BlobUrlHasRef(url) ? ClearBlobUrlRef(url) : url); | 88 public_blob_urls_.find(BlobUrlHasRef(url) ? ClearBlobUrlRef(url) : url); |
| 88 if (found == public_blob_urls_.end()) | 89 if (found == public_blob_urls_.end()) |
| 89 return scoped_ptr<BlobDataHandle>(); | 90 return scoped_ptr<BlobDataHandle>(); |
| 90 return GetBlobDataFromUUID(found->second); | 91 return GetBlobDataFromUUID(found->second); |
| 91 } | 92 } |
| 92 | 93 |
| 93 scoped_ptr<BlobDataHandle> BlobStorageContext::AddFinishedBlob( | 94 scoped_ptr<BlobDataHandle> BlobStorageContext::AddFinishedBlob( |
| 94 BlobDataBuilder* external_builder) { | 95 BlobDataBuilder* external_builder) { |
| 96 TRACE_EVENT0("Blob", "Context::AddFinishedBlob"); |
| 95 StartBuildingBlob(external_builder->uuid_); | 97 StartBuildingBlob(external_builder->uuid_); |
| 96 BlobMap::iterator found = blob_map_.find(external_builder->uuid_); | 98 BlobMap::iterator found = blob_map_.find(external_builder->uuid_); |
| 97 DCHECK(found != blob_map_.end()); | 99 DCHECK(found != blob_map_.end()); |
| 98 BlobMapEntry* entry = found->second; | 100 BlobMapEntry* entry = found->second; |
| 99 InternalBlobData::Builder* target_blob_builder = entry->data_builder.get(); | 101 InternalBlobData::Builder* target_blob_builder = entry->data_builder.get(); |
| 100 DCHECK(target_blob_builder); | 102 DCHECK(target_blob_builder); |
| 101 | 103 |
| 102 target_blob_builder->set_content_disposition( | 104 target_blob_builder->set_content_disposition( |
| 103 external_builder->content_disposition_); | 105 external_builder->content_disposition_); |
| 104 for (const auto& blob_item : external_builder->items_) { | 106 for (const auto& blob_item : external_builder->items_) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 } | 158 } |
| 157 | 159 |
| 158 void BlobStorageContext::StartBuildingBlob(const std::string& uuid) { | 160 void BlobStorageContext::StartBuildingBlob(const std::string& uuid) { |
| 159 DCHECK(!IsInUse(uuid) && !uuid.empty()); | 161 DCHECK(!IsInUse(uuid) && !uuid.empty()); |
| 160 blob_map_[uuid] = new BlobMapEntry(1, new InternalBlobData::Builder()); | 162 blob_map_[uuid] = new BlobMapEntry(1, new InternalBlobData::Builder()); |
| 161 } | 163 } |
| 162 | 164 |
| 163 void BlobStorageContext::AppendBlobDataItem( | 165 void BlobStorageContext::AppendBlobDataItem( |
| 164 const std::string& uuid, | 166 const std::string& uuid, |
| 165 const storage::DataElement& ipc_data_element) { | 167 const storage::DataElement& ipc_data_element) { |
| 168 TRACE_EVENT0("Blob", "Context::AppendBlobDataItem"); |
| 166 DCHECK(IsBeingBuilt(uuid)); | 169 DCHECK(IsBeingBuilt(uuid)); |
| 167 BlobMap::iterator found = blob_map_.find(uuid); | 170 BlobMap::iterator found = blob_map_.find(uuid); |
| 168 if (found == blob_map_.end()) | 171 if (found == blob_map_.end()) |
| 169 return; | 172 return; |
| 170 BlobMapEntry* entry = found->second; | 173 BlobMapEntry* entry = found->second; |
| 171 if (entry->flags & EXCEEDED_MEMORY) | 174 if (entry->flags & EXCEEDED_MEMORY) |
| 172 return; | 175 return; |
| 173 InternalBlobData::Builder* target_blob_builder = entry->data_builder.get(); | 176 InternalBlobData::Builder* target_blob_builder = entry->data_builder.get(); |
| 174 DCHECK(target_blob_builder); | 177 DCHECK(target_blob_builder); |
| 175 | 178 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 195 entry->data = entry->data_builder->Build(); | 198 entry->data = entry->data_builder->Build(); |
| 196 entry->data_builder.reset(); | 199 entry->data_builder.reset(); |
| 197 UMA_HISTOGRAM_COUNTS("Storage.Blob.ItemCount", entry->data->items().size()); | 200 UMA_HISTOGRAM_COUNTS("Storage.Blob.ItemCount", entry->data->items().size()); |
| 198 UMA_HISTOGRAM_BOOLEAN("Storage.Blob.ExceededMemory", | 201 UMA_HISTOGRAM_BOOLEAN("Storage.Blob.ExceededMemory", |
| 199 (entry->flags & EXCEEDED_MEMORY) == EXCEEDED_MEMORY); | 202 (entry->flags & EXCEEDED_MEMORY) == EXCEEDED_MEMORY); |
| 200 size_t total_memory = 0, nonshared_memory = 0; | 203 size_t total_memory = 0, nonshared_memory = 0; |
| 201 entry->data->GetMemoryUsage(&total_memory, &nonshared_memory); | 204 entry->data->GetMemoryUsage(&total_memory, &nonshared_memory); |
| 202 UMA_HISTOGRAM_COUNTS("Storage.Blob.TotalSize", total_memory / 1024); | 205 UMA_HISTOGRAM_COUNTS("Storage.Blob.TotalSize", total_memory / 1024); |
| 203 UMA_HISTOGRAM_COUNTS("Storage.Blob.TotalUnsharedSize", | 206 UMA_HISTOGRAM_COUNTS("Storage.Blob.TotalUnsharedSize", |
| 204 nonshared_memory / 1024); | 207 nonshared_memory / 1024); |
| 208 TRACE_COUNTER1("Blob", "MemoryStoreUsageBytes", memory_usage_); |
| 205 } | 209 } |
| 206 | 210 |
| 207 void BlobStorageContext::CancelBuildingBlob(const std::string& uuid) { | 211 void BlobStorageContext::CancelBuildingBlob(const std::string& uuid) { |
| 208 DCHECK(IsBeingBuilt(uuid)); | 212 DCHECK(IsBeingBuilt(uuid)); |
| 209 DecrementBlobRefCount(uuid); | 213 DecrementBlobRefCount(uuid); |
| 210 } | 214 } |
| 211 | 215 |
| 212 void BlobStorageContext::IncrementBlobRefCount(const std::string& uuid) { | 216 void BlobStorageContext::IncrementBlobRefCount(const std::string& uuid) { |
| 213 BlobMap::iterator found = blob_map_.find(uuid); | 217 BlobMap::iterator found = blob_map_.find(uuid); |
| 214 if (found == blob_map_.end()) { | 218 if (found == blob_map_.end()) { |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 if (found == blob_map_.end()) | 471 if (found == blob_map_.end()) |
| 468 return false; | 472 return false; |
| 469 return found->second->IsBeingBuilt(); | 473 return found->second->IsBeingBuilt(); |
| 470 } | 474 } |
| 471 | 475 |
| 472 bool BlobStorageContext::IsUrlRegistered(const GURL& blob_url) { | 476 bool BlobStorageContext::IsUrlRegistered(const GURL& blob_url) { |
| 473 return public_blob_urls_.find(blob_url) != public_blob_urls_.end(); | 477 return public_blob_urls_.find(blob_url) != public_blob_urls_.end(); |
| 474 } | 478 } |
| 475 | 479 |
| 476 } // namespace storage | 480 } // namespace storage |
| OLD | NEW |