blob: 1120bdf54d2dbbf9ef482ab9b012565b174c5255 [file] [log] [blame]
// 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.
#include <string>
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/supports_user_data.h"
#include "storage/browser/storage_browser_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 {
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.
class BlobDataHandleShared
: public base::RefCountedThreadSafe<BlobDataHandleShared> {
BlobDataHandleShared(BlobData* blob_data,
BlobStorageContext* context,
base::SequencedTaskRunner* task_runner);
BlobData* data() const;
const std::string& uuid() const;
friend class base::DeleteHelper<BlobDataHandleShared>;
friend class base::RefCountedThreadSafe<BlobDataHandleShared>;
friend class BlobDataHandle;
virtual ~BlobDataHandleShared();
scoped_refptr<BlobData> blob_data_;
base::WeakPtr<BlobStorageContext> context_;
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