| 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..a05ffad575dc99bf91dc0b395a016b409df03225
|
| --- /dev/null
|
| +++ b/chrome/browser/extensions/blob_holder.cc
|
| @@ -0,0 +1,68 @@
|
| +// 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 "content/public/browser/render_process_host.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) {
|
| + DCHECK(!ContainsBlobHandle(blob.get()));
|
| + held_blobs_.push_back(blob.release());
|
| +}
|
| +
|
| +BlobHolder::BlobHolder(content::WebContents* web_contents)
|
| + : content::WebContentsObserver(web_contents) {
|
| +}
|
| +
|
| +bool BlobHolder::ContainsBlobHandle(content::BlobHandle* handle) const {
|
| + for (BlobHandleVector::const_iterator it = held_blobs_.begin();
|
| + it != held_blobs_.end(); ++it) {
|
| + if (*it == handle)
|
| + return true;
|
| + }
|
| +
|
| + return false;
|
| +}
|
| +
|
| +bool BlobHolder::OnMessageReceived(const IPC::Message& message) {
|
| + bool handled = true;
|
| + IPC_BEGIN_MESSAGE_MAP(BlobHolder, message)
|
| + IPC_MESSAGE_HANDLER(ExtensionHostMsg_TransferBlobsAck, OnTransferBlobsAck)
|
| + IPC_MESSAGE_UNHANDLED(handled = false)
|
| + IPC_END_MESSAGE_MAP()
|
| + return handled;
|
| +}
|
| +
|
| +void BlobHolder::OnTransferBlobsAck(
|
| + const std::vector<std::string>& blob_uuids) {
|
| + for (std::vector<std::string>::const_iterator uuid_it = blob_uuids.begin();
|
| + 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;
|
| + web_contents()->GetRenderProcessHost()->ReceivedBadMessage();
|
| + }
|
| + }
|
| +}
|
| +
|
| +} // namespace extensions
|
|
|