| 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..fd8cfbbe8eb282ebab4064e943aac67d96aca638
|
| --- /dev/null
|
| +++ b/chrome/browser/extensions/blob_holder.cc
|
| @@ -0,0 +1,70 @@
|
| +// 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_handle.h"
|
| +#include "extensions/common/extension_messages.h"
|
| +
|
| +DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::BlobHolder);
|
| +
|
| +namespace extensions {
|
| +
|
| +struct BlobHolder::BlobHolderData {
|
| + // Takes ownership of |blob_handle|.
|
| + BlobHolderData(content::RenderViewHost* render_view_host,
|
| + content::BlobHandle* blob_handle)
|
| + : render_view_host(render_view_host),
|
| + blob_handle(blob_handle) {
|
| + }
|
| +
|
| + content::RenderViewHost* render_view_host;
|
| + scoped_ptr<content::BlobHandle> blob_handle;
|
| +};
|
| +
|
| +BlobHolder::~BlobHolder() {
|
| +}
|
| +
|
| +void BlobHolder::HoldBlobReference(content::RenderViewHost* render_view_host,
|
| + scoped_ptr<content::BlobHandle> blob) {
|
| + held_blobs_.push_back(new BlobHolderData(render_view_host, blob.release()));
|
| +}
|
| +
|
| +BlobHolder::BlobHolder(content::WebContents* web_contents)
|
| + : content::WebContentsObserver(web_contents) {
|
| +}
|
| +
|
| +void BlobHolder::RenderViewDeleted(content::RenderViewHost* render_view_host) {
|
| + for (ScopedVector<BlobHolderData>::iterator it = held_blobs_.begin();
|
| + it != held_blobs_.end(); ++it) {
|
| + if ((*it)->render_view_host == render_view_host)
|
| + it = held_blobs_.erase(it);
|
| + }
|
| +}
|
| +
|
| +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<BlobHolderData>::iterator it = held_blobs_.begin();
|
| + it != held_blobs_.end(); ++it) {
|
| + if ((*it)->blob_handle->GetUUID() == uuid) {
|
| + it = held_blobs_.erase(it);
|
| + return;
|
| + }
|
| + }
|
| +
|
| + DLOG(ERROR) << "Tried to release a Blob we don't have ownership to. UUID: "
|
| + << uuid;
|
| +}
|
| +
|
| +} // namespace extensions
|
|
|