Revert "Omit calls to set composing region when pasting image."
[chromium-blink-merge.git] / storage / browser / blob / blob_data_handle.h
blob30412415f76e68fb019f81a29b99743b51f8dd47
1 // Copyright (c) 2013 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.
5 #ifndef STORAGE_BROWSER_BLOB_BLOB_DATA_HANDLE_H_
6 #define STORAGE_BROWSER_BLOB_BLOB_DATA_HANDLE_H_
8 #include <string>
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/supports_user_data.h"
13 #include "storage/browser/storage_browser_export.h"
15 namespace base {
16 class SequencedTaskRunner;
19 namespace storage {
21 class BlobDataSnapshot;
22 class BlobStorageContext;
24 // BlobDataHandle ensures that the underlying blob (keyed by the uuid) remains
25 // in the BlobStorageContext's collection while this object is alive. Anything
26 // that needs to keep a blob alive needs to store this handle.
27 // When the blob data itself is needed, clients must call the CreateSnapshot()
28 // method on the IO thread to create a snapshot of the blob data. This snapshot
29 // is not intended to be persisted, and serves to ensure that the backing
30 // resources remain around for the duration of reading the blob. This snapshot
31 // can be read on any thread, but it must be destructed on the IO thread.
32 // This object has delete semantics and may be deleted on any thread.
33 class STORAGE_EXPORT BlobDataHandle
34 : public base::SupportsUserData::Data {
35 public:
36 BlobDataHandle(const BlobDataHandle& other); // May be copied on any thread.
37 ~BlobDataHandle() override; // May be deleted on any thread.
39 // A BlobDataSnapshot is used to read the data from the blob. This object is
40 // intended to be transient and should not be stored for any extended period
41 // of time.
42 // This call and the destruction of the returned snapshot must be called
43 // on the IO thread.
44 scoped_ptr<BlobDataSnapshot> CreateSnapshot() const;
46 const std::string& uuid() const; // May be accessed on any thread.
48 private:
49 // Internal class whose destructor is guarenteed to be called on the IO
50 // thread.
51 class BlobDataHandleShared
52 : public base::RefCountedThreadSafe<BlobDataHandleShared> {
53 public:
54 BlobDataHandleShared(const std::string& uuid,
55 BlobStorageContext* context,
56 base::SequencedTaskRunner* task_runner);
58 scoped_ptr<BlobDataSnapshot> CreateSnapshot() const;
59 const std::string& uuid() const;
61 private:
62 friend class base::DeleteHelper<BlobDataHandleShared>;
63 friend class base::RefCountedThreadSafe<BlobDataHandleShared>;
64 friend class BlobDataHandle;
66 virtual ~BlobDataHandleShared();
68 const std::string uuid_;
69 base::WeakPtr<BlobStorageContext> context_;
71 DISALLOW_COPY_AND_ASSIGN(BlobDataHandleShared);
74 friend class BlobStorageContext;
75 BlobDataHandle(const std::string& uuid,
76 BlobStorageContext* context,
77 base::SequencedTaskRunner* task_runner);
79 scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
80 scoped_refptr<BlobDataHandleShared> shared_;
83 } // namespace storage
85 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_HANDLE_H_