summaryrefslogtreecommitdiffstats
path: root/webkit/browser/blob/blob_data_handle.h
blob: 62df5702719488c75479465fb801e4a04942d2f9 (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
63
64
65
66
67
68
69
70
71
// Copyright (c) 2013 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 WEBKIT_BROWSER_BLOB_BLOB_DATA_HANDLE_H_
#define WEBKIT_BROWSER_BLOB_BLOB_DATA_HANDLE_H_

#include <string>

#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/supports_user_data.h"
#include "webkit/browser/storage_export.h"

namespace base {
class SequencedTaskRunner;
}

namespace storage {

class BlobData;
class BlobStorageContext;

// A scoper object for use in chrome's main browser process, ensures
// the underlying BlobData and its uuid remain in BlobStorageContext's
// collection for the duration. This object has delete semantics and
// maybe deleted on any thread.
class STORAGE_EXPORT BlobDataHandle
    : public base::SupportsUserData::Data {
 public:
  BlobDataHandle(const BlobDataHandle& other);  // May be copied on any thread.
  virtual ~BlobDataHandle();  // Maybe be deleted on any thread.
  BlobData* data() const;  // May only be accessed on the IO thread.

  std::string uuid() const;  // May be accessed on any thread.

 private:
  class BlobDataHandleShared
      : public base::RefCountedThreadSafe<BlobDataHandleShared> {
   public:
    BlobDataHandleShared(BlobData* blob_data,
                         BlobStorageContext* context,
                         base::SequencedTaskRunner* task_runner);

    BlobData* data() const;
    const std::string& uuid() const;

   private:
    friend class base::DeleteHelper<BlobDataHandleShared>;
    friend class base::RefCountedThreadSafe<BlobDataHandleShared>;
    friend class BlobDataHandle;

    virtual ~BlobDataHandleShared();

    scoped_refptr<BlobData> blob_data_;
    base::WeakPtr<BlobStorageContext> context_;

    DISALLOW_COPY_AND_ASSIGN(BlobDataHandleShared);
  };

  friend class BlobStorageContext;
  BlobDataHandle(BlobData* blob_data, BlobStorageContext* context,
                 base::SequencedTaskRunner* task_runner);

  scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
  scoped_refptr<BlobDataHandleShared> shared_;
};

}  // namespace storage

#endif  // WEBKIT_BROWSER_BLOB_BLOB_DATA_HANDLE_H_