| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "content/browser/blob_storage/blob_dispatcher_host.h" | 5 #include "content/browser/blob_storage/blob_dispatcher_host.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 return; | 212 return; |
| 213 } | 213 } |
| 214 VLOG(1) << "Blob construction of " << uuid << " cancelled by renderer. " | 214 VLOG(1) << "Blob construction of " << uuid << " cancelled by renderer. " |
| 215 << " Reason: " << static_cast<int>(code) << "."; | 215 << " Reason: " << static_cast<int>(code) << "."; |
| 216 async_builder_.CancelBuildingBlob(uuid, code, context); | 216 async_builder_.CancelBuildingBlob(uuid, code, context); |
| 217 } | 217 } |
| 218 | 218 |
| 219 void BlobDispatcherHost::OnIncrementBlobRefCount(const std::string& uuid) { | 219 void BlobDispatcherHost::OnIncrementBlobRefCount(const std::string& uuid) { |
| 220 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 220 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 221 BlobStorageContext* context = this->context(); | 221 BlobStorageContext* context = this->context(); |
| 222 if (uuid.empty() || !context->registry().HasEntry(uuid)) { | 222 if (uuid.empty()) { |
| 223 bad_message::ReceivedBadMessage( |
| 224 this, bad_message::BDH_INVALID_REFCOUNT_OPERATION); |
| 225 return; |
| 226 } |
| 227 if (!context->registry().HasEntry(uuid)) { |
| 223 UMA_HISTOGRAM_ENUMERATION("Storage.Blob.InvalidReference", BDH_INCREMENT, | 228 UMA_HISTOGRAM_ENUMERATION("Storage.Blob.InvalidReference", BDH_INCREMENT, |
| 224 BDH_TRACING_ENUM_LAST); | 229 BDH_TRACING_ENUM_LAST); |
| 225 bad_message::ReceivedBadMessage( | |
| 226 this, bad_message::BDH_INVALID_REFCOUNT_OPERATION); | |
| 227 return; | 230 return; |
| 228 } | 231 } |
| 229 context->IncrementBlobRefCount(uuid); | 232 context->IncrementBlobRefCount(uuid); |
| 230 blobs_inuse_map_[uuid] += 1; | 233 blobs_inuse_map_[uuid] += 1; |
| 231 } | 234 } |
| 232 | 235 |
| 233 void BlobDispatcherHost::OnDecrementBlobRefCount(const std::string& uuid) { | 236 void BlobDispatcherHost::OnDecrementBlobRefCount(const std::string& uuid) { |
| 234 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 237 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 235 if (uuid.empty() || !IsInUseInHost(uuid)) { | 238 if (uuid.empty()) { |
| 239 bad_message::ReceivedBadMessage( |
| 240 this, bad_message::BDH_INVALID_REFCOUNT_OPERATION); |
| 241 return; |
| 242 } |
| 243 if (!IsInUseInHost(uuid)) { |
| 236 UMA_HISTOGRAM_ENUMERATION("Storage.Blob.InvalidReference", BDH_DECREMENT, | 244 UMA_HISTOGRAM_ENUMERATION("Storage.Blob.InvalidReference", BDH_DECREMENT, |
| 237 BDH_TRACING_ENUM_LAST); | 245 BDH_TRACING_ENUM_LAST); |
| 238 bad_message::ReceivedBadMessage( | |
| 239 this, bad_message::BDH_INVALID_REFCOUNT_OPERATION); | |
| 240 return; | 246 return; |
| 241 } | 247 } |
| 242 BlobStorageContext* context = this->context(); | 248 BlobStorageContext* context = this->context(); |
| 243 context->DecrementBlobRefCount(uuid); | 249 context->DecrementBlobRefCount(uuid); |
| 244 blobs_inuse_map_[uuid] -= 1; | 250 blobs_inuse_map_[uuid] -= 1; |
| 245 if (blobs_inuse_map_[uuid] == 0) { | 251 if (blobs_inuse_map_[uuid] == 0) { |
| 246 blobs_inuse_map_.erase(uuid); | 252 blobs_inuse_map_.erase(uuid); |
| 247 // If the blob has been deleted in the context and we're still building it, | 253 // If the blob has been deleted in the context and we're still building it, |
| 248 // this means we have no references waiting to read it. Clear the building | 254 // this means we have no references waiting to read it. Clear the building |
| 249 // state and send a cancel message to the renderer. | 255 // state and send a cancel message to the renderer. |
| 250 if (async_builder_.IsBeingBuilt(uuid) && | 256 if (async_builder_.IsBeingBuilt(uuid) && |
| 251 !context->registry().HasEntry(uuid)) { | 257 !context->registry().HasEntry(uuid)) { |
| 252 async_builder_.CancelBuildingBlob( | 258 async_builder_.CancelBuildingBlob( |
| 253 uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING, | 259 uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING, |
| 254 context); | 260 context); |
| 255 Send(new BlobStorageMsg_CancelBuildingBlob( | 261 Send(new BlobStorageMsg_CancelBuildingBlob( |
| 256 uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING)); | 262 uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING)); |
| 257 } | 263 } |
| 258 } | 264 } |
| 259 } | 265 } |
| 260 | 266 |
| 261 void BlobDispatcherHost::OnRegisterPublicBlobURL(const GURL& public_url, | 267 void BlobDispatcherHost::OnRegisterPublicBlobURL(const GURL& public_url, |
| 262 const std::string& uuid) { | 268 const std::string& uuid) { |
| 263 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 269 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 264 BlobStorageContext* context = this->context(); | 270 BlobStorageContext* context = this->context(); |
| 265 if (uuid.empty() || !IsInUseInHost(uuid) || | 271 if (uuid.empty()) { |
| 266 context->registry().IsURLMapped(public_url)) { | 272 bad_message::ReceivedBadMessage(this, |
| 273 bad_message::BDH_INVALID_URL_OPERATION); |
| 274 return; |
| 275 } |
| 276 if (!IsInUseInHost(uuid) || context->registry().IsURLMapped(public_url)) { |
| 267 UMA_HISTOGRAM_ENUMERATION("Storage.Blob.InvalidURLRegister", BDH_INCREMENT, | 277 UMA_HISTOGRAM_ENUMERATION("Storage.Blob.InvalidURLRegister", BDH_INCREMENT, |
| 268 BDH_TRACING_ENUM_LAST); | 278 BDH_TRACING_ENUM_LAST); |
| 269 bad_message::ReceivedBadMessage(this, | |
| 270 bad_message::BDH_INVALID_URL_OPERATION); | |
| 271 return; | 279 return; |
| 272 } | 280 } |
| 273 context->RegisterPublicBlobURL(public_url, uuid); | 281 context->RegisterPublicBlobURL(public_url, uuid); |
| 274 public_blob_urls_.insert(public_url); | 282 public_blob_urls_.insert(public_url); |
| 275 } | 283 } |
| 276 | 284 |
| 277 void BlobDispatcherHost::OnRevokePublicBlobURL(const GURL& public_url) { | 285 void BlobDispatcherHost::OnRevokePublicBlobURL(const GURL& public_url) { |
| 278 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 286 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 279 if (!IsUrlRegisteredInHost(public_url)) { | 287 if (!public_url.is_valid()) { |
| 280 UMA_HISTOGRAM_ENUMERATION("Storage.Blob.InvalidURLRegister", BDH_DECREMENT, | |
| 281 BDH_TRACING_ENUM_LAST); | |
| 282 bad_message::ReceivedBadMessage(this, | 288 bad_message::ReceivedBadMessage(this, |
| 283 bad_message::BDH_INVALID_URL_OPERATION); | 289 bad_message::BDH_INVALID_URL_OPERATION); |
| 284 return; | 290 return; |
| 285 } | 291 } |
| 292 if (!IsUrlRegisteredInHost(public_url)) { |
| 293 UMA_HISTOGRAM_ENUMERATION("Storage.Blob.InvalidURLRegister", BDH_DECREMENT, |
| 294 BDH_TRACING_ENUM_LAST); |
| 295 return; |
| 296 } |
| 286 context()->RevokePublicBlobURL(public_url); | 297 context()->RevokePublicBlobURL(public_url); |
| 287 public_blob_urls_.erase(public_url); | 298 public_blob_urls_.erase(public_url); |
| 288 } | 299 } |
| 289 | 300 |
| 290 storage::BlobStorageContext* BlobDispatcherHost::context() { | 301 storage::BlobStorageContext* BlobDispatcherHost::context() { |
| 291 return blob_storage_context_->context(); | 302 return blob_storage_context_->context(); |
| 292 } | 303 } |
| 293 | 304 |
| 294 void BlobDispatcherHost::SendMemoryRequest( | 305 void BlobDispatcherHost::SendMemoryRequest( |
| 295 const std::string& uuid, | 306 const std::string& uuid, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 context->RevokePublicBlobURL(url); | 361 context->RevokePublicBlobURL(url); |
| 351 } | 362 } |
| 352 for (const auto& uuid_refnum_pair : blobs_inuse_map_) { | 363 for (const auto& uuid_refnum_pair : blobs_inuse_map_) { |
| 353 for (int i = 0; i < uuid_refnum_pair.second; ++i) | 364 for (int i = 0; i < uuid_refnum_pair.second; ++i) |
| 354 context->DecrementBlobRefCount(uuid_refnum_pair.first); | 365 context->DecrementBlobRefCount(uuid_refnum_pair.first); |
| 355 } | 366 } |
| 356 async_builder_.CancelAll(context); | 367 async_builder_.CancelAll(context); |
| 357 } | 368 } |
| 358 | 369 |
| 359 } // namespace content | 370 } // namespace content |
| OLD | NEW |