OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/extensions/blob_holder.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "extensions/common/extension_messages.h" |
| 9 #include "webkit/browser/blob/blob_data_handle.h" |
| 10 |
| 11 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::BlobHolder); |
| 12 |
| 13 namespace extensions { |
| 14 |
| 15 BlobHolder::~BlobHolder() { |
| 16 } |
| 17 |
| 18 void BlobHolder::HoldBlobReference( |
| 19 scoped_ptr<webkit_blob::BlobDataHandle> blob) { |
| 20 held_blobs_.push_back(blob.release()); |
| 21 } |
| 22 |
| 23 BlobHolder::BlobHolder(content::WebContents* web_contents) |
| 24 : content::WebContentsObserver(web_contents) { |
| 25 } |
| 26 |
| 27 bool BlobHolder::OnMessageReceived(const IPC::Message& message) { |
| 28 bool handled = true; |
| 29 IPC_BEGIN_MESSAGE_MAP(BlobHolder, message) |
| 30 IPC_MESSAGE_HANDLER(ExtensionHostMsg_BlobOwnershipTaken, |
| 31 OnBlobOwnershipTaken) |
| 32 IPC_MESSAGE_UNHANDLED(handled = false) |
| 33 IPC_END_MESSAGE_MAP() |
| 34 return handled; |
| 35 } |
| 36 |
| 37 void BlobHolder::OnBlobOwnershipTaken(const std::string& uuid) { |
| 38 for (ScopedVector<webkit_blob::BlobDataHandle>::iterator it = |
| 39 held_blobs_.begin(); |
| 40 it != held_blobs_.end(); ++it) { |
| 41 if ((*it)->uuid() == uuid) { |
| 42 it = held_blobs_.erase(it); |
| 43 return; |
| 44 } |
| 45 } |
| 46 DLOG(ERROR) << "Tried to release a Blob we don't have ownership to. UUID: " |
| 47 << uuid; |
| 48 } |
| 49 |
| 50 } // namespace extensions |
OLD | NEW |