OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "storage/browser/blob/blob_data_handle.h" | 5 #include "storage/browser/blob/blob_data_handle.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
11 #include "storage/browser/blob/blob_storage_context.h" | 11 #include "storage/browser/blob/blob_storage_context.h" |
12 #include "storage/common/blob/blob_data.h" | 12 #include "storage/common/blob/blob_data.h" |
13 | 13 |
14 namespace storage { | 14 namespace storage { |
15 | 15 |
16 BlobDataHandle::BlobDataHandleShared::BlobDataHandleShared( | 16 BlobDataSnapshotHandle::BlobDataSnapshotHandleShared:: |
17 BlobData* blob_data, | 17 BlobDataSnapshotHandleShared(BlobDataSnapshot* blob_data, |
18 BlobStorageContext* context, | 18 BlobStorageContext* context, |
19 base::SequencedTaskRunner* task_runner) | 19 base::SequencedTaskRunner* task_runner) |
20 : blob_data_(blob_data), | 20 : blob_data_(blob_data), context_(context->AsWeakPtr()) { |
21 context_(context->AsWeakPtr()) { | |
22 context_->IncrementBlobRefCount(blob_data->uuid()); | 21 context_->IncrementBlobRefCount(blob_data->uuid()); |
23 } | 22 } |
24 | 23 |
25 BlobData* BlobDataHandle::BlobDataHandleShared::data() const { | 24 BlobDataSnapshot* BlobDataSnapshotHandle::BlobDataSnapshotHandleShared::data() |
| 25 const { |
26 return blob_data_.get(); | 26 return blob_data_.get(); |
27 } | 27 } |
28 | 28 |
29 const std::string& BlobDataHandle::BlobDataHandleShared::uuid() const { | 29 const std::string& BlobDataSnapshotHandle::BlobDataSnapshotHandleShared::uuid() |
| 30 const { |
30 return blob_data_->uuid(); | 31 return blob_data_->uuid(); |
31 } | 32 } |
32 | 33 |
33 BlobDataHandle::BlobDataHandleShared::~BlobDataHandleShared() { | 34 BlobDataSnapshotHandle::BlobDataSnapshotHandleShared:: |
| 35 ~BlobDataSnapshotHandleShared() { |
34 if (context_.get()) | 36 if (context_.get()) |
35 context_->DecrementBlobRefCount(blob_data_->uuid()); | 37 context_->DecrementBlobRefCount(blob_data_->uuid()); |
36 } | 38 } |
37 | 39 |
38 BlobDataHandle::BlobDataHandle(BlobData* blob_data, | 40 BlobDataSnapshotHandle::BlobDataSnapshotHandle( |
39 BlobStorageContext* context, | 41 BlobDataSnapshot* blob_data, |
40 base::SequencedTaskRunner* task_runner) | 42 BlobStorageContext* context, |
| 43 base::SequencedTaskRunner* task_runner) |
41 : io_task_runner_(task_runner), | 44 : io_task_runner_(task_runner), |
42 shared_(new BlobDataHandleShared(blob_data, context, task_runner)) { | 45 shared_( |
| 46 new BlobDataSnapshotHandleShared(blob_data, context, task_runner)) { |
43 DCHECK(io_task_runner_.get()); | 47 DCHECK(io_task_runner_.get()); |
44 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 48 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
45 } | 49 } |
46 | 50 |
47 BlobDataHandle::BlobDataHandle(const BlobDataHandle& other) { | 51 BlobDataSnapshotHandle::BlobDataSnapshotHandle( |
| 52 const BlobDataSnapshotHandle& other) { |
48 io_task_runner_ = other.io_task_runner_; | 53 io_task_runner_ = other.io_task_runner_; |
49 shared_ = other.shared_; | 54 shared_ = other.shared_; |
50 } | 55 } |
51 | 56 |
52 BlobDataHandle::~BlobDataHandle() { | 57 BlobDataSnapshotHandle::~BlobDataSnapshotHandle() { |
53 BlobDataHandleShared* raw = shared_.get(); | 58 BlobDataSnapshotHandleShared* raw = shared_.get(); |
54 raw->AddRef(); | 59 raw->AddRef(); |
55 shared_ = 0; | 60 shared_ = nullptr; |
56 io_task_runner_->ReleaseSoon(FROM_HERE, raw); | 61 io_task_runner_->ReleaseSoon(FROM_HERE, raw); |
57 } | 62 } |
58 | 63 |
59 BlobData* BlobDataHandle::data() const { | 64 const BlobDataSnapshot* BlobDataSnapshotHandle::data() const { |
60 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 65 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
61 return shared_->data(); | 66 return shared_->data(); |
62 } | 67 } |
63 | 68 |
64 std::string BlobDataHandle::uuid() const { | 69 const std::string& BlobDataSnapshotHandle::uuid() const { |
65 return shared_->uuid(); | 70 return shared_->uuid(); |
66 } | 71 } |
67 | 72 |
68 } // namespace storage | 73 } // namespace storage |
OLD | NEW |