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_
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"
16 class SequencedTaskRunner;
22 class BlobStorageContext;
24 // A scoper object for use in chrome's main browser process, ensures
25 // the underlying BlobData and its uuid remain in BlobStorageContext's
26 // collection for the duration. This object has delete semantics and
27 // maybe deleted on any thread.
28 class STORAGE_EXPORT BlobDataHandle
29 : public base::SupportsUserData::Data {
31 BlobDataHandle(const BlobDataHandle& other); // May be copied on any thread.
32 virtual ~BlobDataHandle(); // Maybe be deleted on any thread.
33 BlobData* data() const; // May only be accessed on the IO thread.
35 std::string uuid() const; // May be accessed on any thread.
38 class BlobDataHandleShared
39 : public base::RefCountedThreadSafe<BlobDataHandleShared> {
41 BlobDataHandleShared(BlobData* blob_data,
42 BlobStorageContext* context,
43 base::SequencedTaskRunner* task_runner);
45 BlobData* data() const;
46 const std::string& uuid() const;
49 friend class base::DeleteHelper<BlobDataHandleShared>;
50 friend class base::RefCountedThreadSafe<BlobDataHandleShared>;
51 friend class BlobDataHandle;
53 virtual ~BlobDataHandleShared();
55 scoped_refptr<BlobData> blob_data_;
56 base::WeakPtr<BlobStorageContext> context_;
58 DISALLOW_COPY_AND_ASSIGN(BlobDataHandleShared);
61 friend class BlobStorageContext;
62 BlobDataHandle(BlobData* blob_data, BlobStorageContext* context,
63 base::SequencedTaskRunner* task_runner);
65 scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
66 scoped_refptr<BlobDataHandleShared> shared_;
69 } // namespace storage
71 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_HANDLE_H_