Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: storage/browser/blob/blob_data_handle.cc

Issue 1234813004: [BlobAsync] Asynchronous Blob Construction Final Patch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blob-protocol-change
Patch Set: comments Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h"
10 #include "base/location.h" 11 #include "base/location.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/sequenced_task_runner.h" 14 #include "base/sequenced_task_runner.h"
14 #include "base/task_runner.h" 15 #include "base/task_runner.h"
15 #include "base/time/time.h" 16 #include "base/time/time.h"
16 #include "storage/browser/blob/blob_data_snapshot.h" 17 #include "storage/browser/blob/blob_data_snapshot.h"
17 #include "storage/browser/blob/blob_reader.h" 18 #include "storage/browser/blob/blob_reader.h"
18 #include "storage/browser/blob/blob_storage_context.h" 19 #include "storage/browser/blob/blob_storage_context.h"
19 #include "storage/browser/fileapi/file_stream_reader.h" 20 #include "storage/browser/fileapi/file_stream_reader.h"
20 #include "storage/browser/fileapi/file_system_context.h" 21 #include "storage/browser/fileapi/file_system_context.h"
21 #include "storage/browser/fileapi/file_system_url.h" 22 #include "storage/browser/fileapi/file_system_url.h"
22 #include "url/gurl.h" 23 #include "url/gurl.h"
23 24
24 namespace storage { 25 namespace storage {
26 using BlobState = BlobStorageRegistry::BlobState;
25 27
26 namespace { 28 namespace {
27 29
28 class FileStreamReaderProviderImpl 30 class FileStreamReaderProviderImpl
29 : public BlobReader::FileStreamReaderProvider { 31 : public BlobReader::FileStreamReaderProvider {
30 public: 32 public:
31 FileStreamReaderProviderImpl(FileSystemContext* file_system_context) 33 explicit FileStreamReaderProviderImpl(FileSystemContext* file_system_context)
32 : file_system_context_(file_system_context) {} 34 : file_system_context_(file_system_context) {}
33 ~FileStreamReaderProviderImpl() override {} 35 ~FileStreamReaderProviderImpl() override {}
34 36
35 scoped_ptr<FileStreamReader> CreateForLocalFile( 37 scoped_ptr<FileStreamReader> CreateForLocalFile(
36 base::TaskRunner* task_runner, 38 base::TaskRunner* task_runner,
37 const base::FilePath& file_path, 39 const base::FilePath& file_path,
38 int64_t initial_offset, 40 int64_t initial_offset,
39 const base::Time& expected_modification_time) override { 41 const base::Time& expected_modification_time) override {
40 return make_scoped_ptr(FileStreamReader::CreateForLocalFile( 42 return make_scoped_ptr(FileStreamReader::CreateForLocalFile(
41 task_runner, file_path, initial_offset, expected_modification_time)); 43 task_runner, file_path, initial_offset, expected_modification_time));
(...skipping 21 matching lines...) Expand all
63 const std::string& content_type, 65 const std::string& content_type,
64 const std::string& content_disposition, 66 const std::string& content_disposition,
65 BlobStorageContext* context) 67 BlobStorageContext* context)
66 : uuid_(uuid), 68 : uuid_(uuid),
67 content_type_(content_type), 69 content_type_(content_type),
68 content_disposition_(content_disposition), 70 content_disposition_(content_disposition),
69 context_(context->AsWeakPtr()) { 71 context_(context->AsWeakPtr()) {
70 context_->IncrementBlobRefCount(uuid); 72 context_->IncrementBlobRefCount(uuid);
71 } 73 }
72 74
75 void BlobDataHandle::BlobDataHandleShared::RunOnConstructionComplete(
76 const base::Callback<void(bool)>& done) {
77 if (!context_.get()) {
78 done.Run(false);
79 return;
80 }
81 context_->RunOnConstructionComplete(uuid_, done);
82 }
83
73 scoped_ptr<BlobReader> BlobDataHandle::CreateReader( 84 scoped_ptr<BlobReader> BlobDataHandle::CreateReader(
74 FileSystemContext* file_system_context, 85 FileSystemContext* file_system_context,
75 base::SequencedTaskRunner* file_task_runner) const { 86 base::SequencedTaskRunner* file_task_runner) const {
76 return scoped_ptr<BlobReader>(new BlobReader( 87 return scoped_ptr<BlobReader>(new BlobReader(
77 this, scoped_ptr<BlobReader::FileStreamReaderProvider>( 88 this, scoped_ptr<BlobReader::FileStreamReaderProvider>(
78 new FileStreamReaderProviderImpl(file_system_context)), 89 new FileStreamReaderProviderImpl(file_system_context)),
79 file_task_runner)); 90 file_task_runner));
80 } 91 }
81 92
82 scoped_ptr<BlobDataSnapshot> 93 scoped_ptr<BlobDataSnapshot>
83 BlobDataHandle::BlobDataHandleShared::CreateSnapshot() const { 94 BlobDataHandle::BlobDataHandleShared::CreateSnapshot() const {
95 if (!context_.get())
96 return nullptr;
84 return context_->CreateSnapshot(uuid_); 97 return context_->CreateSnapshot(uuid_);
85 } 98 }
86 99
87 BlobDataHandle::BlobDataHandleShared::~BlobDataHandleShared() { 100 BlobDataHandle::BlobDataHandleShared::~BlobDataHandleShared() {
88 if (context_.get()) 101 if (context_.get())
89 context_->DecrementBlobRefCount(uuid_); 102 context_->DecrementBlobRefCount(uuid_);
90 } 103 }
91 104
92 BlobDataHandle::BlobDataHandle(const std::string& uuid, 105 BlobDataHandle::BlobDataHandle(const std::string& uuid,
93 const std::string& content_type, 106 const std::string& content_type,
(...skipping 16 matching lines...) Expand all
110 123
111 BlobDataHandle::~BlobDataHandle() { 124 BlobDataHandle::~BlobDataHandle() {
112 if (!io_task_runner_->RunsTasksOnCurrentThread()) { 125 if (!io_task_runner_->RunsTasksOnCurrentThread()) {
113 BlobDataHandleShared* raw = shared_.get(); 126 BlobDataHandleShared* raw = shared_.get();
114 raw->AddRef(); 127 raw->AddRef();
115 shared_ = nullptr; 128 shared_ = nullptr;
116 io_task_runner_->ReleaseSoon(FROM_HERE, raw); 129 io_task_runner_->ReleaseSoon(FROM_HERE, raw);
117 } 130 }
118 } 131 }
119 132
133 bool BlobDataHandle::IsBeingBuilt() const {
134 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
135 if (!shared_->context_)
136 return false;
137 return shared_->context_->IsBeingBuilt(shared_->uuid_);
138 }
139
140 bool BlobDataHandle::IsBroken() const {
141 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
142 if (!shared_->context_)
143 return true;
144 return shared_->context_->IsBroken(shared_->uuid_);
145 }
146
147 void BlobDataHandle::RunOnConstructionComplete(
148 const base::Callback<void(bool)>& done) {
149 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
150 shared_->RunOnConstructionComplete(done);
151 }
152
120 scoped_ptr<BlobDataSnapshot> BlobDataHandle::CreateSnapshot() const { 153 scoped_ptr<BlobDataSnapshot> BlobDataHandle::CreateSnapshot() const {
121 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 154 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
122 return shared_->CreateSnapshot(); 155 return shared_->CreateSnapshot();
123 } 156 }
124 157
125 const std::string& BlobDataHandle::uuid() const { 158 const std::string& BlobDataHandle::uuid() const {
126 return shared_->uuid_; 159 return shared_->uuid_;
127 } 160 }
128 161
129 const std::string& BlobDataHandle::content_type() const { 162 const std::string& BlobDataHandle::content_type() const {
130 return shared_->content_type_; 163 return shared_->content_type_;
131 } 164 }
132 165
133 const std::string& BlobDataHandle::content_disposition() const { 166 const std::string& BlobDataHandle::content_disposition() const {
134 return shared_->content_disposition_; 167 return shared_->content_disposition_;
135 } 168 }
136 169
137 } // namespace storage 170 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698