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