Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: content/browser/blob_storage/blob_dispatcher_host.cc

Issue 1893293006: [Blob] Added error reporting metrics to invalid message errors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/browser/bad_message.h" 11 #include "content/browser/bad_message.h"
11 #include "content/browser/fileapi/chrome_blob_storage_context.h" 12 #include "content/browser/fileapi/chrome_blob_storage_context.h"
12 #include "content/common/fileapi/webblob_messages.h" 13 #include "content/common/fileapi/webblob_messages.h"
13 #include "ipc/ipc_platform_file.h" 14 #include "ipc/ipc_platform_file.h"
14 #include "storage/browser/blob/blob_storage_context.h" 15 #include "storage/browser/blob/blob_storage_context.h"
15 #include "storage/browser/blob/blob_transport_result.h" 16 #include "storage/browser/blob/blob_transport_result.h"
16 #include "storage/common/blob_storage/blob_item_bytes_request.h" 17 #include "storage/common/blob_storage/blob_item_bytes_request.h"
17 #include "storage/common/blob_storage/blob_item_bytes_response.h" 18 #include "storage/common/blob_storage/blob_item_bytes_response.h"
18 #include "storage/common/data_element.h" 19 #include "storage/common/data_element.h"
19 #include "url/gurl.h" 20 #include "url/gurl.h"
20 21
21 using storage::BlobStorageContext; 22 using storage::BlobStorageContext;
22 using storage::BlobStorageRegistry; 23 using storage::BlobStorageRegistry;
23 using storage::BlobTransportResult; 24 using storage::BlobTransportResult;
24 using storage::IPCBlobCreationCancelCode; 25 using storage::IPCBlobCreationCancelCode;
25 26
26 namespace content { 27 namespace content {
28 namespace {
Mark P 2016/04/20 21:55:02 Add some blank lines in/around this new code.
dmurph 2016/04/20 22:04:51 Done.
29 // These are used for UMA stats, don't change.
30 enum RefcountOperation {
31 BDH_DECREMENT = 0,
32 BDH_INCREMENT,
33 BDH_TRACING_ENUM_LAST
34 };
35 }
27 36
28 BlobDispatcherHost::BlobDispatcherHost( 37 BlobDispatcherHost::BlobDispatcherHost(
29 ChromeBlobStorageContext* blob_storage_context) 38 ChromeBlobStorageContext* blob_storage_context)
30 : BrowserMessageFilter(BlobMsgStart), 39 : BrowserMessageFilter(BlobMsgStart),
31 blob_storage_context_(blob_storage_context) {} 40 blob_storage_context_(blob_storage_context) {}
32 41
33 BlobDispatcherHost::~BlobDispatcherHost() { 42 BlobDispatcherHost::~BlobDispatcherHost() {
34 ClearHostFromBlobStorageContext(); 43 ClearHostFromBlobStorageContext();
35 } 44 }
36 45
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 } 211 }
203 VLOG(1) << "Blob construction of " << uuid << " cancelled by renderer. " 212 VLOG(1) << "Blob construction of " << uuid << " cancelled by renderer. "
204 << " Reason: " << static_cast<int>(code) << "."; 213 << " Reason: " << static_cast<int>(code) << ".";
205 async_builder_.CancelBuildingBlob(uuid, code, context); 214 async_builder_.CancelBuildingBlob(uuid, code, context);
206 } 215 }
207 216
208 void BlobDispatcherHost::OnIncrementBlobRefCount(const std::string& uuid) { 217 void BlobDispatcherHost::OnIncrementBlobRefCount(const std::string& uuid) {
209 DCHECK_CURRENTLY_ON(BrowserThread::IO); 218 DCHECK_CURRENTLY_ON(BrowserThread::IO);
210 BlobStorageContext* context = this->context(); 219 BlobStorageContext* context = this->context();
211 if (uuid.empty() || !context->registry().HasEntry(uuid)) { 220 if (uuid.empty() || !context->registry().HasEntry(uuid)) {
221 UMA_HISTOGRAM_ENUMERATION("Storage.Blob.InvalidReference", BDH_INCREMENT,
222 BDH_TRACING_ENUM_LAST);
212 bad_message::ReceivedBadMessage( 223 bad_message::ReceivedBadMessage(
213 this, bad_message::BDH_INVALID_REFCOUNT_OPERATION); 224 this, bad_message::BDH_INVALID_REFCOUNT_OPERATION);
214 return; 225 return;
215 } 226 }
216 context->IncrementBlobRefCount(uuid); 227 context->IncrementBlobRefCount(uuid);
217 blobs_inuse_map_[uuid] += 1; 228 blobs_inuse_map_[uuid] += 1;
218 } 229 }
219 230
220 void BlobDispatcherHost::OnDecrementBlobRefCount(const std::string& uuid) { 231 void BlobDispatcherHost::OnDecrementBlobRefCount(const std::string& uuid) {
221 DCHECK_CURRENTLY_ON(BrowserThread::IO); 232 DCHECK_CURRENTLY_ON(BrowserThread::IO);
222 if (uuid.empty() || !IsInUseInHost(uuid)) { 233 if (uuid.empty() || !IsInUseInHost(uuid)) {
234 UMA_HISTOGRAM_ENUMERATION("Storage.Blob.InvalidReference", BDH_DECREMENT,
235 BDH_TRACING_ENUM_LAST);
223 bad_message::ReceivedBadMessage( 236 bad_message::ReceivedBadMessage(
224 this, bad_message::BDH_INVALID_REFCOUNT_OPERATION); 237 this, bad_message::BDH_INVALID_REFCOUNT_OPERATION);
225 return; 238 return;
226 } 239 }
227 BlobStorageContext* context = this->context(); 240 BlobStorageContext* context = this->context();
228 context->DecrementBlobRefCount(uuid); 241 context->DecrementBlobRefCount(uuid);
229 blobs_inuse_map_[uuid] -= 1; 242 blobs_inuse_map_[uuid] -= 1;
230 if (blobs_inuse_map_[uuid] == 0) { 243 if (blobs_inuse_map_[uuid] == 0) {
231 blobs_inuse_map_.erase(uuid); 244 blobs_inuse_map_.erase(uuid);
232 // If the blob has been deleted in the context and we're still building it, 245 // If the blob has been deleted in the context and we're still building it,
233 // this means we have no references waiting to read it. Clear the building 246 // this means we have no references waiting to read it. Clear the building
234 // state and send a cancel message to the renderer. 247 // state and send a cancel message to the renderer.
235 if (async_builder_.IsBeingBuilt(uuid) && 248 if (async_builder_.IsBeingBuilt(uuid) &&
236 !context->registry().HasEntry(uuid)) { 249 !context->registry().HasEntry(uuid)) {
237 async_builder_.CancelBuildingBlob( 250 async_builder_.CancelBuildingBlob(
238 uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING, 251 uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING,
239 context); 252 context);
240 Send(new BlobStorageMsg_CancelBuildingBlob( 253 Send(new BlobStorageMsg_CancelBuildingBlob(
241 uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING)); 254 uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING));
242 } 255 }
243 } 256 }
244 } 257 }
245 258
246 void BlobDispatcherHost::OnRegisterPublicBlobURL(const GURL& public_url, 259 void BlobDispatcherHost::OnRegisterPublicBlobURL(const GURL& public_url,
247 const std::string& uuid) { 260 const std::string& uuid) {
248 DCHECK_CURRENTLY_ON(BrowserThread::IO); 261 DCHECK_CURRENTLY_ON(BrowserThread::IO);
249 BlobStorageContext* context = this->context(); 262 BlobStorageContext* context = this->context();
250 if (uuid.empty() || !IsInUseInHost(uuid) || 263 if (uuid.empty() || !IsInUseInHost(uuid) ||
251 context->registry().IsURLMapped(public_url)) { 264 context->registry().IsURLMapped(public_url)) {
265 UMA_HISTOGRAM_ENUMERATION("Storage.Blob.InvalidURLRegister", BDH_INCREMENT,
266 BDH_TRACING_ENUM_LAST);
252 bad_message::ReceivedBadMessage(this, 267 bad_message::ReceivedBadMessage(this,
253 bad_message::BDH_INVALID_URL_OPERATION); 268 bad_message::BDH_INVALID_URL_OPERATION);
254 return; 269 return;
255 } 270 }
256 context->RegisterPublicBlobURL(public_url, uuid); 271 context->RegisterPublicBlobURL(public_url, uuid);
257 public_blob_urls_.insert(public_url); 272 public_blob_urls_.insert(public_url);
258 } 273 }
259 274
260 void BlobDispatcherHost::OnRevokePublicBlobURL(const GURL& public_url) { 275 void BlobDispatcherHost::OnRevokePublicBlobURL(const GURL& public_url) {
261 DCHECK_CURRENTLY_ON(BrowserThread::IO); 276 DCHECK_CURRENTLY_ON(BrowserThread::IO);
262 if (!IsUrlRegisteredInHost(public_url)) { 277 if (!IsUrlRegisteredInHost(public_url)) {
278 UMA_HISTOGRAM_ENUMERATION("Storage.Blob.InvalidURLRegister", BDH_DECREMENT,
279 BDH_TRACING_ENUM_LAST);
263 bad_message::ReceivedBadMessage(this, 280 bad_message::ReceivedBadMessage(this,
264 bad_message::BDH_INVALID_URL_OPERATION); 281 bad_message::BDH_INVALID_URL_OPERATION);
265 return; 282 return;
266 } 283 }
267 context()->RevokePublicBlobURL(public_url); 284 context()->RevokePublicBlobURL(public_url);
268 public_blob_urls_.erase(public_url); 285 public_blob_urls_.erase(public_url);
269 } 286 }
270 287
271 storage::BlobStorageContext* BlobDispatcherHost::context() { 288 storage::BlobStorageContext* BlobDispatcherHost::context() {
272 return blob_storage_context_->context(); 289 return blob_storage_context_->context();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 context->RevokePublicBlobURL(url); 348 context->RevokePublicBlobURL(url);
332 } 349 }
333 for (const auto& uuid_refnum_pair : blobs_inuse_map_) { 350 for (const auto& uuid_refnum_pair : blobs_inuse_map_) {
334 for (int i = 0; i < uuid_refnum_pair.second; ++i) 351 for (int i = 0; i < uuid_refnum_pair.second; ++i)
335 context->DecrementBlobRefCount(uuid_refnum_pair.first); 352 context->DecrementBlobRefCount(uuid_refnum_pair.first);
336 } 353 }
337 async_builder_.CancelAll(context); 354 async_builder_.CancelAll(context);
338 } 355 }
339 356
340 } // namespace content 357 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698