| 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..817d61a854435c301c184fe4337a9f913d855fa0
|
| --- /dev/null
|
| +++ b/chrome/browser/extensions/blob_holder.cc
|
| @@ -0,0 +1,50 @@
|
| +// 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 "extensions/common/extension_messages.h"
|
| +#include "webkit/browser/blob/blob_data_handle.h"
|
| +
|
| +DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::BlobHolder);
|
| +
|
| +namespace extensions {
|
| +
|
| +BlobHolder::~BlobHolder() {
|
| +}
|
| +
|
| +void BlobHolder::HoldBlobReference(
|
| + scoped_ptr<webkit_blob::BlobDataHandle> 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<webkit_blob::BlobDataHandle>::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
|
|
|