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

Unified Diff: extensions/browser/blob_holder.cc

Issue 280393003: Blobs: Catching browser-process created Blobs in extension code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: run git cl format Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/browser/blob_holder.h ('k') | extensions/browser/extension_function.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/browser/blob_holder.cc
diff --git a/extensions/browser/blob_holder.cc b/extensions/browser/blob_holder.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7b44374be37476093df40ee47aca055ed85cfec1
--- /dev/null
+++ b/extensions/browser/blob_holder.cc
@@ -0,0 +1,87 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "extensions/browser/blob_holder.h"
+
+#include "base/logging.h"
+#include "content/public/browser/blob_handle.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/render_process_host.h"
+
+namespace extensions {
+
+namespace {
+
+// Address to this variable used as the user data key.
+const int kBlobHolderUserDataKey = 0;
+}
+
+// static
+BlobHolder* BlobHolder::FromRenderProcessHost(
+ content::RenderProcessHost* render_process_host) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ DCHECK(render_process_host);
+ BlobHolder* existing = static_cast<BlobHolder*>(
+ render_process_host->GetUserData(&kBlobHolderUserDataKey));
+
+ if (existing)
+ return existing;
+
+ BlobHolder* new_instance = new BlobHolder(render_process_host);
+ render_process_host->SetUserData(&kBlobHolderUserDataKey, new_instance);
+ return new_instance;
+}
+
+BlobHolder::~BlobHolder() {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+}
+
+void BlobHolder::HoldBlobReference(scoped_ptr<content::BlobHandle> blob) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ DCHECK(!ContainsBlobHandle(blob.get()));
michaeln 2014/05/23 17:31:36 might be able to simplify DCHECK_EQ(held_blobs_.e
tommycli 2014/05/23 18:48:39 Was possible. No longer possible since I switched
+ held_blobs_.push_back(blob.release());
+}
+
+BlobHolder::BlobHolder(content::RenderProcessHost* render_process_host)
+ : render_process_host_(render_process_host) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+}
+
+bool BlobHolder::ContainsBlobHandle(content::BlobHandle* handle) const {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ for (BlobHandleVector::const_iterator it = held_blobs_.begin();
+ it != held_blobs_.end();
+ ++it) {
+ if (*it == handle)
+ return true;
+ }
+
+ return false;
+}
+
+void BlobHolder::DropBlobs(const std::vector<std::string>& blob_uuids) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ for (std::vector<std::string>::const_iterator uuid_it = blob_uuids.begin();
michaeln 2014/05/23 17:31:36 this n*n loop is probably not so bad because these
tommycli 2014/05/23 18:48:39 Yeah you're right this is a little hard to underst
+ uuid_it != blob_uuids.end();
+ ++uuid_it) {
+ bool found = false;
+ for (BlobHandleVector::iterator blob_handle_it = held_blobs_.begin();
+ blob_handle_it != held_blobs_.end();
+ ++blob_handle_it) {
+ if ((*blob_handle_it)->GetUUID() == *uuid_it) {
+ held_blobs_.erase(blob_handle_it);
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ DLOG(ERROR) << "Tried to release a Blob we don't have ownership to."
+ << "UUID: " << *uuid_it;
+ render_process_host_->ReceivedBadMessage();
+ }
+ }
+}
+
+} // namespace extensions
« no previous file with comments | « extensions/browser/blob_holder.h ('k') | extensions/browser/extension_function.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698