Delete unused downloads page asset.
[chromium-blink-merge.git] / storage / browser / blob / blob_data_handle.cc
blobe3a4be944fe36eeedaed8cfb16cdf5a159f595c0
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 #include "storage/browser/blob/blob_data_handle.h"
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/logging.h"
10 #include "base/sequenced_task_runner.h"
11 #include "storage/browser/blob/blob_data_snapshot.h"
12 #include "storage/browser/blob/blob_storage_context.h"
14 namespace storage {
16 BlobDataHandle::BlobDataHandleShared::BlobDataHandleShared(
17 const std::string& uuid,
18 BlobStorageContext* context,
19 base::SequencedTaskRunner* task_runner)
20 : uuid_(uuid), context_(context->AsWeakPtr()) {
21 context_->IncrementBlobRefCount(uuid);
24 scoped_ptr<BlobDataSnapshot>
25 BlobDataHandle::BlobDataHandleShared::CreateSnapshot() const {
26 return context_->CreateSnapshot(uuid_).Pass();
29 const std::string& BlobDataHandle::BlobDataHandleShared::uuid() const {
30 return uuid_;
33 BlobDataHandle::BlobDataHandleShared::~BlobDataHandleShared() {
34 if (context_.get())
35 context_->DecrementBlobRefCount(uuid_);
38 BlobDataHandle::BlobDataHandle(const std::string& uuid,
39 BlobStorageContext* context,
40 base::SequencedTaskRunner* task_runner)
41 : io_task_runner_(task_runner),
42 shared_(new BlobDataHandleShared(uuid, context, task_runner)) {
43 DCHECK(io_task_runner_.get());
44 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
47 BlobDataHandle::BlobDataHandle(const BlobDataHandle& other) {
48 io_task_runner_ = other.io_task_runner_;
49 shared_ = other.shared_;
52 BlobDataHandle::~BlobDataHandle() {
53 BlobDataHandleShared* raw = shared_.get();
54 raw->AddRef();
55 shared_ = nullptr;
56 io_task_runner_->ReleaseSoon(FROM_HERE, raw);
59 scoped_ptr<BlobDataSnapshot> BlobDataHandle::CreateSnapshot() const {
60 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
61 return shared_->CreateSnapshot().Pass();
64 const std::string& BlobDataHandle::uuid() const {
65 return shared_->uuid();
68 } // namespace storage