Index: chrome/browser/extensions/blob_holder.cc |
diff --git a/chrome/browser/extensions/blob_holder.cc b/chrome/browser/extensions/blob_holder.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..940a05f029278b9b1ac38648c8a79c5993b8e38f |
--- /dev/null |
+++ b/chrome/browser/extensions/blob_holder.cc |
@@ -0,0 +1,48 @@ |
+// 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 "chrome/browser/extensions/blob_holder.h" |
+ |
+#include "base/logging.h" |
+#include "content/public/browser/blob_context.h" |
+#include "extensions/common/extension_messages.h" |
+ |
+DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::BlobHolder); |
+ |
+namespace extensions { |
+ |
+BlobHolder::~BlobHolder() { |
+} |
+ |
+void BlobHolder::HoldBlobReference(scoped_ptr<content::BlobHandle> blob) { |
+ held_blobs_.push_back(blob.release()); |
+} |
+ |
+BlobHolder::BlobHolder(content::WebContents* web_contents) |
+ : content::WebContentsObserver(web_contents) { |
+} |
+ |
+bool BlobHolder::OnMessageReceived(const IPC::Message& message) { |
+ bool handled = true; |
+ IPC_BEGIN_MESSAGE_MAP(BlobHolder, message) |
+ IPC_MESSAGE_HANDLER(ExtensionHostMsg_BlobOwnershipTaken, |
+ OnBlobOwnershipTaken) |
+ IPC_MESSAGE_UNHANDLED(handled = false) |
+ IPC_END_MESSAGE_MAP() |
+ return handled; |
+} |
+ |
+void BlobHolder::OnBlobOwnershipTaken(const std::string& uuid) { |
+ for (ScopedVector<content::BlobHandle>::iterator it = held_blobs_.begin(); |
+ it != held_blobs_.end(); ++it) { |
+ if ((*it)->uuid() == uuid) { |
+ it = held_blobs_.erase(it); |
+ return; |
+ } |
+ } |
+ DLOG(ERROR) << "Tried to release a Blob we don't have ownership to. UUID: " |
+ << uuid; |
+} |
+ |
+} // namespace extensions |