| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef EXTENSIONS_BROWSER_BLOB_HOLDER_H_ | 5 #ifndef EXTENSIONS_BROWSER_BLOB_HOLDER_H_ |
| 6 #define EXTENSIONS_BROWSER_BLOB_HOLDER_H_ | 6 #define EXTENSIONS_BROWSER_BLOB_HOLDER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/linked_ptr.h" | |
| 15 #include "base/supports_user_data.h" | 14 #include "base/supports_user_data.h" |
| 16 | 15 |
| 17 namespace content { | 16 namespace content { |
| 18 class BlobHandle; | 17 class BlobHandle; |
| 19 class RenderProcessHost; | 18 class RenderProcessHost; |
| 20 } | 19 } |
| 21 | 20 |
| 22 namespace extensions { | 21 namespace extensions { |
| 23 | 22 |
| 24 class ExtensionMessageFilter; | 23 class ExtensionMessageFilter; |
| 25 | 24 |
| 26 // Used for holding onto Blobs created into the browser process until a | 25 // Used for holding onto Blobs created into the browser process until a |
| 27 // renderer takes over ownership. This class operates on the UI thread. | 26 // renderer takes over ownership. This class operates on the UI thread. |
| 28 class BlobHolder : public base::SupportsUserData::Data { | 27 class BlobHolder : public base::SupportsUserData::Data { |
| 29 public: | 28 public: |
| 30 // Will create the BlobHolder if it doesn't already exist. | 29 // Will create the BlobHolder if it doesn't already exist. |
| 31 static BlobHolder* FromRenderProcessHost( | 30 static BlobHolder* FromRenderProcessHost( |
| 32 content::RenderProcessHost* render_process_host); | 31 content::RenderProcessHost* render_process_host); |
| 33 | 32 |
| 34 ~BlobHolder() override; | 33 ~BlobHolder() override; |
| 35 | 34 |
| 36 // Causes BlobHolder to take ownership of |blob|. | 35 // Causes BlobHolder to take ownership of |blob|. |
| 37 void HoldBlobReference(std::unique_ptr<content::BlobHandle> blob); | 36 void HoldBlobReference(std::unique_ptr<content::BlobHandle> blob); |
| 38 | 37 |
| 39 private: | 38 private: |
| 40 typedef std::multimap<std::string, linked_ptr<content::BlobHandle> > | 39 using BlobHandleMultimap = |
| 41 BlobHandleMultimap; | 40 std::multimap<std::string, std::unique_ptr<content::BlobHandle>>; |
| 42 | 41 |
| 43 explicit BlobHolder(content::RenderProcessHost* render_process_host); | 42 explicit BlobHolder(content::RenderProcessHost* render_process_host); |
| 44 | 43 |
| 45 // BlobHolder will drop a blob handle for each element in blob_uuids. | 44 // BlobHolder will drop a blob handle for each element in blob_uuids. |
| 46 // If caller wishes to drop multiple references to the same blob, | 45 // If caller wishes to drop multiple references to the same blob, |
| 47 // |blob_uuids| may contain duplicate UUIDs. | 46 // |blob_uuids| may contain duplicate UUIDs. |
| 48 void DropBlobs(const std::vector<std::string>& blob_uuids); | 47 void DropBlobs(const std::vector<std::string>& blob_uuids); |
| 49 friend class ExtensionMessageFilter; | 48 friend class ExtensionMessageFilter; |
| 50 | 49 |
| 51 bool ContainsBlobHandle(content::BlobHandle* handle) const; | 50 bool ContainsBlobHandle(content::BlobHandle* handle) const; |
| 52 | 51 |
| 53 // A reference to the owner of this class. | 52 // A reference to the owner of this class. |
| 54 content::RenderProcessHost* render_process_host_; | 53 content::RenderProcessHost* render_process_host_; |
| 55 | 54 |
| 56 BlobHandleMultimap held_blobs_; | 55 BlobHandleMultimap held_blobs_; |
| 57 | 56 |
| 58 DISALLOW_COPY_AND_ASSIGN(BlobHolder); | 57 DISALLOW_COPY_AND_ASSIGN(BlobHolder); |
| 59 }; | 58 }; |
| 60 | 59 |
| 61 } // namespace extensions | 60 } // namespace extensions |
| 62 | 61 |
| 63 #endif // EXTENSIONS_BROWSER_BLOB_HOLDER_H_ | 62 #endif // EXTENSIONS_BROWSER_BLOB_HOLDER_H_ |
| OLD | NEW |