summaryrefslogtreecommitdiff
path: root/chromium/extensions/browser/blob_holder.h
blob: 37c1bfe7f3a4d54fd4d8d3f3b3ab5317cd9f9f4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// 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.

#ifndef EXTENSIONS_BROWSER_BLOB_HOLDER_H_
#define EXTENSIONS_BROWSER_BLOB_HOLDER_H_

#include <map>
#include <memory>
#include <string>
#include <vector>

#include "base/macros.h"
#include "base/supports_user_data.h"

namespace content {
class BlobHandle;
class RenderProcessHost;
}

class ExtensionFunction;

namespace extensions {

// Used for holding onto Blobs created into the browser process until a
// renderer takes over ownership. This class operates on the UI thread.
class BlobHolder : public base::SupportsUserData::Data {
 public:
  // Will create the BlobHolder if it doesn't already exist.
  static BlobHolder* FromRenderProcessHost(
      content::RenderProcessHost* render_process_host);

  ~BlobHolder() override;

  // Causes BlobHolder to take ownership of |blob|.
  void HoldBlobReference(std::unique_ptr<content::BlobHandle> blob);

 private:
  using BlobHandleMultimap =
      std::multimap<std::string, std::unique_ptr<content::BlobHandle>>;

  explicit BlobHolder(content::RenderProcessHost* render_process_host);

  // BlobHolder will drop a blob handle for each element in blob_uuids.
  // If caller wishes to drop multiple references to the same blob,
  // |blob_uuids| may contain duplicate UUIDs.
  void DropBlobs(const std::vector<std::string>& blob_uuids);
  friend class ::ExtensionFunction;

  bool ContainsBlobHandle(content::BlobHandle* handle) const;

  // A reference to the owner of this class.
  content::RenderProcessHost* render_process_host_;

  BlobHandleMultimap held_blobs_;

  DISALLOW_COPY_AND_ASSIGN(BlobHolder);
};

}  // namespace extensions

#endif  // EXTENSIONS_BROWSER_BLOB_HOLDER_H_