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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 scoped_refptr<FileSystemContext> file_system_context_; | 60 scoped_refptr<FileSystemContext> file_system_context_; |
61 DISALLOW_COPY_AND_ASSIGN(FileStreamReaderProviderImpl); | 61 DISALLOW_COPY_AND_ASSIGN(FileStreamReaderProviderImpl); |
62 }; | 62 }; |
63 | 63 |
64 } // namespace | 64 } // namespace |
65 | 65 |
66 BlobDataHandle::BlobDataHandleShared::BlobDataHandleShared( | 66 BlobDataHandle::BlobDataHandleShared::BlobDataHandleShared( |
67 const std::string& uuid, | 67 const std::string& uuid, |
68 const std::string& content_type, | 68 const std::string& content_type, |
69 const std::string& content_disposition, | 69 const std::string& content_disposition, |
| 70 uint64_t size, |
70 BlobStorageContext* context) | 71 BlobStorageContext* context) |
71 : uuid_(uuid), | 72 : uuid_(uuid), |
72 content_type_(content_type), | 73 content_type_(content_type), |
73 content_disposition_(content_disposition), | 74 content_disposition_(content_disposition), |
| 75 size_(size), |
74 context_(context->AsWeakPtr()) { | 76 context_(context->AsWeakPtr()) { |
75 context_->IncrementBlobRefCount(uuid); | 77 context_->IncrementBlobRefCount(uuid); |
76 } | 78 } |
77 | 79 |
78 std::unique_ptr<BlobReader> BlobDataHandle::CreateReader( | 80 std::unique_ptr<BlobReader> BlobDataHandle::CreateReader( |
79 FileSystemContext* file_system_context, | 81 FileSystemContext* file_system_context, |
80 base::SequencedTaskRunner* file_task_runner) const { | 82 base::SequencedTaskRunner* file_task_runner) const { |
81 return std::unique_ptr<BlobReader>(new BlobReader( | 83 return std::unique_ptr<BlobReader>(new BlobReader( |
82 this, std::unique_ptr<BlobReader::FileStreamReaderProvider>( | 84 this, std::unique_ptr<BlobReader::FileStreamReaderProvider>( |
83 new FileStreamReaderProviderImpl(file_system_context)), | 85 new FileStreamReaderProviderImpl(file_system_context)), |
84 file_task_runner)); | 86 file_task_runner)); |
85 } | 87 } |
86 | 88 |
87 BlobDataHandle::BlobDataHandleShared::~BlobDataHandleShared() { | 89 BlobDataHandle::BlobDataHandleShared::~BlobDataHandleShared() { |
88 if (context_.get()) | 90 if (context_.get()) |
89 context_->DecrementBlobRefCount(uuid_); | 91 context_->DecrementBlobRefCount(uuid_); |
90 } | 92 } |
91 | 93 |
92 BlobDataHandle::BlobDataHandle(const std::string& uuid, | 94 BlobDataHandle::BlobDataHandle(const std::string& uuid, |
93 const std::string& content_type, | 95 const std::string& content_type, |
94 const std::string& content_disposition, | 96 const std::string& content_disposition, |
| 97 uint64_t size, |
95 BlobStorageContext* context, | 98 BlobStorageContext* context, |
96 base::SequencedTaskRunner* io_task_runner) | 99 base::SequencedTaskRunner* io_task_runner) |
97 : io_task_runner_(io_task_runner), | 100 : io_task_runner_(io_task_runner), |
98 shared_(new BlobDataHandleShared(uuid, | 101 shared_(new BlobDataHandleShared(uuid, |
99 content_type, | 102 content_type, |
100 content_disposition, | 103 content_disposition, |
| 104 size, |
101 context)) { | 105 context)) { |
102 DCHECK(io_task_runner_.get()); | 106 DCHECK(io_task_runner_.get()); |
103 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 107 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
104 } | 108 } |
105 | 109 |
106 BlobDataHandle::BlobDataHandle(const BlobDataHandle& other) { | 110 BlobDataHandle::BlobDataHandle(const BlobDataHandle& other) { |
107 io_task_runner_ = other.io_task_runner_; | 111 io_task_runner_ = other.io_task_runner_; |
108 shared_ = other.shared_; | 112 shared_ = other.shared_; |
109 } | 113 } |
110 | 114 |
(...skipping 13 matching lines...) Expand all Loading... |
124 return shared_->context_->IsBeingBuilt(shared_->uuid_); | 128 return shared_->context_->IsBeingBuilt(shared_->uuid_); |
125 } | 129 } |
126 | 130 |
127 bool BlobDataHandle::IsBroken() const { | 131 bool BlobDataHandle::IsBroken() const { |
128 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 132 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
129 if (!shared_->context_) | 133 if (!shared_->context_) |
130 return true; | 134 return true; |
131 return shared_->context_->IsBroken(shared_->uuid_); | 135 return shared_->context_->IsBroken(shared_->uuid_); |
132 } | 136 } |
133 | 137 |
| 138 IPCBlobCreationCancelCode BlobDataHandle::GetBrokenReason() const { |
| 139 return shared_->context_->GetBrokenReason(shared_->uuid_); |
| 140 } |
| 141 |
134 void BlobDataHandle::RunOnConstructionComplete( | 142 void BlobDataHandle::RunOnConstructionComplete( |
135 const BlobConstructedCallback& done) { | 143 const BlobConstructedCallback& done) { |
136 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 144 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
137 if (!shared_->context_.get()) { | 145 if (!shared_->context_.get()) { |
138 done.Run(false, IPCBlobCreationCancelCode::UNKNOWN); | 146 done.Run(false, IPCBlobCreationCancelCode::UNKNOWN); |
139 return; | 147 return; |
140 } | 148 } |
141 shared_->context_->RunOnConstructionComplete(shared_->uuid_, done); | 149 shared_->context_->RunOnConstructionComplete(shared_->uuid_, done); |
142 } | 150 } |
143 | 151 |
144 std::unique_ptr<BlobDataSnapshot> BlobDataHandle::CreateSnapshot() const { | 152 std::unique_ptr<BlobDataSnapshot> BlobDataHandle::CreateSnapshot() const { |
145 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 153 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
146 if (!shared_->context_.get()) | 154 if (!shared_->context_.get()) |
147 return nullptr; | 155 return nullptr; |
148 return shared_->context_->CreateSnapshot(shared_->uuid_); | 156 return shared_->context_->CreateSnapshot(shared_->uuid_); |
149 } | 157 } |
150 | 158 |
151 const std::string& BlobDataHandle::uuid() const { | 159 const std::string& BlobDataHandle::uuid() const { |
152 return shared_->uuid_; | 160 return shared_->uuid_; |
153 } | 161 } |
154 | 162 |
155 const std::string& BlobDataHandle::content_type() const { | 163 const std::string& BlobDataHandle::content_type() const { |
156 return shared_->content_type_; | 164 return shared_->content_type_; |
157 } | 165 } |
158 | 166 |
159 const std::string& BlobDataHandle::content_disposition() const { | 167 const std::string& BlobDataHandle::content_disposition() const { |
160 return shared_->content_disposition_; | 168 return shared_->content_disposition_; |
161 } | 169 } |
162 | 170 |
| 171 uint64_t BlobDataHandle::size() const { |
| 172 return shared_->size_; |
| 173 } |
| 174 |
163 } // namespace storage | 175 } // namespace storage |
OLD | NEW |