| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 size_t total_memory = 0, nonshared_memory = 0; | 155 size_t total_memory = 0, nonshared_memory = 0; |
| 156 entry->data->GetMemoryUsage(&total_memory, &nonshared_memory); | 156 entry->data->GetMemoryUsage(&total_memory, &nonshared_memory); |
| 157 UMA_HISTOGRAM_COUNTS("Storage.Blob.TotalSize", total_memory / 1024); | 157 UMA_HISTOGRAM_COUNTS("Storage.Blob.TotalSize", total_memory / 1024); |
| 158 UMA_HISTOGRAM_COUNTS("Storage.Blob.TotalUnsharedSize", | 158 UMA_HISTOGRAM_COUNTS("Storage.Blob.TotalUnsharedSize", |
| 159 nonshared_memory / 1024); | 159 nonshared_memory / 1024); |
| 160 TRACE_COUNTER1("Blob", "MemoryStoreUsageBytes", memory_usage_); | 160 TRACE_COUNTER1("Blob", "MemoryStoreUsageBytes", memory_usage_); |
| 161 | 161 |
| 162 auto runner = base::ThreadTaskRunnerHandle::Get(); | 162 auto runner = base::ThreadTaskRunnerHandle::Get(); |
| 163 for (const auto& callback : entry->build_completion_callbacks) { | 163 for (const auto& callback : entry->build_completion_callbacks) { |
| 164 runner->PostTask(FROM_HERE, | 164 runner->PostTask(FROM_HERE, |
| 165 base::Bind(callback, entry->state == BlobState::COMPLETE)); | 165 base::Bind(callback, entry->state == BlobState::COMPLETE, |
| 166 entry->broken_reason)); |
| 166 } | 167 } |
| 167 entry->build_completion_callbacks.clear(); | 168 entry->build_completion_callbacks.clear(); |
| 168 } | 169 } |
| 169 | 170 |
| 170 void BlobStorageContext::CancelPendingBlob(const std::string& uuid, | 171 void BlobStorageContext::CancelPendingBlob(const std::string& uuid, |
| 171 IPCBlobCreationCancelCode reason) { | 172 IPCBlobCreationCancelCode reason) { |
| 172 BlobRegistryEntry* entry = registry_.GetEntry(uuid); | 173 BlobRegistryEntry* entry = registry_.GetEntry(uuid); |
| 173 DCHECK(entry && entry->state == BlobState::PENDING); | 174 DCHECK(entry && entry->state == BlobState::PENDING); |
| 174 entry->state = BlobState::BROKEN; | 175 entry->state = BlobState::BROKEN; |
| 175 entry->broken_reason = reason; | 176 entry->broken_reason = reason; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 bool BlobStorageContext::IsBeingBuilt(const std::string& uuid) const { | 228 bool BlobStorageContext::IsBeingBuilt(const std::string& uuid) const { |
| 228 const BlobRegistryEntry* entry = registry_.GetEntry(uuid); | 229 const BlobRegistryEntry* entry = registry_.GetEntry(uuid); |
| 229 if (!entry) { | 230 if (!entry) { |
| 230 return false; | 231 return false; |
| 231 } | 232 } |
| 232 return entry->state == BlobState::PENDING; | 233 return entry->state == BlobState::PENDING; |
| 233 } | 234 } |
| 234 | 235 |
| 235 void BlobStorageContext::RunOnConstructionComplete( | 236 void BlobStorageContext::RunOnConstructionComplete( |
| 236 const std::string& uuid, | 237 const std::string& uuid, |
| 237 const base::Callback<void(bool)>& done) { | 238 const BlobConstructedCallback& done) { |
| 238 BlobRegistryEntry* entry = registry_.GetEntry(uuid); | 239 BlobRegistryEntry* entry = registry_.GetEntry(uuid); |
| 239 DCHECK(entry); | 240 DCHECK(entry); |
| 240 switch (entry->state) { | 241 switch (entry->state) { |
| 241 case BlobState::COMPLETE: | 242 case BlobState::COMPLETE: |
| 242 done.Run(true); | 243 done.Run(true, IPCBlobCreationCancelCode::UNKNOWN); |
| 243 return; | 244 return; |
| 244 case BlobState::BROKEN: | 245 case BlobState::BROKEN: |
| 245 done.Run(false); | 246 done.Run(false, entry->broken_reason); |
| 246 return; | 247 return; |
| 247 case BlobState::PENDING: | 248 case BlobState::PENDING: |
| 248 entry->build_completion_callbacks.push_back(done); | 249 entry->build_completion_callbacks.push_back(done); |
| 249 return; | 250 return; |
| 250 } | 251 } |
| 251 NOTREACHED(); | 252 NOTREACHED(); |
| 252 } | 253 } |
| 253 | 254 |
| 254 bool BlobStorageContext::AppendAllocatedBlobItem( | 255 bool BlobStorageContext::AppendAllocatedBlobItem( |
| 255 const std::string& target_blob_uuid, | 256 const std::string& target_blob_uuid, |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 case DataElement::TYPE_UNKNOWN: | 446 case DataElement::TYPE_UNKNOWN: |
| 446 CHECK(false) << "Illegal blob item type: " << item.type(); | 447 CHECK(false) << "Illegal blob item type: " << item.type(); |
| 447 } | 448 } |
| 448 length -= new_length; | 449 length -= new_length; |
| 449 offset = 0; | 450 offset = 0; |
| 450 } | 451 } |
| 451 return true; | 452 return true; |
| 452 } | 453 } |
| 453 | 454 |
| 454 } // namespace storage | 455 } // namespace storage |
| OLD | NEW |