| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "content/child/fileapi/webfilewriter_impl.h" | 5 #include "content/child/fileapi/webfilewriter_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/platform_file.h" | 8 #include "base/platform_file.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "content/child/child_thread.h" | 10 #include "content/child/child_thread.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 void Truncate(const GURL& path, int64 offset, | 43 void Truncate(const GURL& path, int64 offset, |
| 44 const StatusCallback& status_callback) { | 44 const StatusCallback& status_callback) { |
| 45 status_callback_ = status_callback; | 45 status_callback_ = status_callback; |
| 46 if (!GetFileSystemDispatcher()) | 46 if (!GetFileSystemDispatcher()) |
| 47 return; | 47 return; |
| 48 ChildThread::current()->file_system_dispatcher()->Truncate( | 48 ChildThread::current()->file_system_dispatcher()->Truncate( |
| 49 path, offset, &request_id_, | 49 path, offset, &request_id_, |
| 50 base::Bind(&WriterBridge::DidFinish, this)); | 50 base::Bind(&WriterBridge::DidFinish, this)); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void Write(const GURL& path, const GURL& blob_url, int64 offset, | 53 void WriteDeprecated( |
| 54 const GURL& path, const GURL& blob_url, int64 offset, |
| 55 const WriteCallback& write_callback, |
| 56 const StatusCallback& error_callback) { |
| 57 write_callback_ = write_callback; |
| 58 status_callback_ = error_callback; |
| 59 if (!GetFileSystemDispatcher()) |
| 60 return; |
| 61 ChildThread::current()->file_system_dispatcher()->WriteDeprecated( |
| 62 path, blob_url, offset, &request_id_, |
| 63 base::Bind(&WriterBridge::DidWrite, this), |
| 64 base::Bind(&WriterBridge::DidFinish, this)); |
| 65 } |
| 66 |
| 67 void Write(const GURL& path, const std::string& id, int64 offset, |
| 54 const WriteCallback& write_callback, | 68 const WriteCallback& write_callback, |
| 55 const StatusCallback& error_callback) { | 69 const StatusCallback& error_callback) { |
| 56 write_callback_ = write_callback; | 70 write_callback_ = write_callback; |
| 57 status_callback_ = error_callback; | 71 status_callback_ = error_callback; |
| 58 if (!GetFileSystemDispatcher()) | 72 if (!GetFileSystemDispatcher()) |
| 59 return; | 73 return; |
| 60 ChildThread::current()->file_system_dispatcher()->Write( | 74 ChildThread::current()->file_system_dispatcher()->Write( |
| 61 path, blob_url, offset, &request_id_, | 75 path, id, offset, &request_id_, |
| 62 base::Bind(&WriterBridge::DidWrite, this), | 76 base::Bind(&WriterBridge::DidWrite, this), |
| 63 base::Bind(&WriterBridge::DidFinish, this)); | 77 base::Bind(&WriterBridge::DidFinish, this)); |
| 64 } | 78 } |
| 65 | 79 |
| 66 void Cancel(const StatusCallback& status_callback) { | 80 void Cancel(const StatusCallback& status_callback) { |
| 67 status_callback_ = status_callback; | 81 status_callback_ = status_callback; |
| 68 if (!GetFileSystemDispatcher()) | 82 if (!GetFileSystemDispatcher()) |
| 69 return; | 83 return; |
| 70 ChildThread::current()->file_system_dispatcher()->Cancel( | 84 ChildThread::current()->file_system_dispatcher()->Cancel( |
| 71 request_id_, | 85 request_id_, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 | 146 |
| 133 WebFileWriterImpl::~WebFileWriterImpl() { | 147 WebFileWriterImpl::~WebFileWriterImpl() { |
| 134 } | 148 } |
| 135 | 149 |
| 136 void WebFileWriterImpl::DoTruncate(const GURL& path, int64 offset) { | 150 void WebFileWriterImpl::DoTruncate(const GURL& path, int64 offset) { |
| 137 RunOnMainThread(base::Bind(&WriterBridge::Truncate, bridge_, | 151 RunOnMainThread(base::Bind(&WriterBridge::Truncate, bridge_, |
| 138 path, offset, | 152 path, offset, |
| 139 base::Bind(&WebFileWriterImpl::DidFinish, AsWeakPtr()))); | 153 base::Bind(&WebFileWriterImpl::DidFinish, AsWeakPtr()))); |
| 140 } | 154 } |
| 141 | 155 |
| 156 void WebFileWriterImpl::DoWriteDeprecated( |
| 157 const GURL& path, const GURL& blob_url, int64 offset) { |
| 158 RunOnMainThread(base::Bind(&WriterBridge::WriteDeprecated, bridge_, |
| 159 path, blob_url, offset, |
| 160 base::Bind(&WebFileWriterImpl::DidWrite, AsWeakPtr()), |
| 161 base::Bind(&WebFileWriterImpl::DidFinish, AsWeakPtr()))); |
| 162 } |
| 163 |
| 142 void WebFileWriterImpl::DoWrite( | 164 void WebFileWriterImpl::DoWrite( |
| 143 const GURL& path, const GURL& blob_url, int64 offset) { | 165 const GURL& path, const std::string& blob_id, int64 offset) { |
| 144 RunOnMainThread(base::Bind(&WriterBridge::Write, bridge_, | 166 RunOnMainThread(base::Bind(&WriterBridge::Write, bridge_, |
| 145 path, blob_url, offset, | 167 path, blob_id, offset, |
| 146 base::Bind(&WebFileWriterImpl::DidWrite, AsWeakPtr()), | 168 base::Bind(&WebFileWriterImpl::DidWrite, AsWeakPtr()), |
| 147 base::Bind(&WebFileWriterImpl::DidFinish, AsWeakPtr()))); | 169 base::Bind(&WebFileWriterImpl::DidFinish, AsWeakPtr()))); |
| 148 } | 170 } |
| 149 | 171 |
| 150 void WebFileWriterImpl::DoCancel() { | 172 void WebFileWriterImpl::DoCancel() { |
| 151 RunOnMainThread(base::Bind(&WriterBridge::Cancel, bridge_, | 173 RunOnMainThread(base::Bind(&WriterBridge::Cancel, bridge_, |
| 152 base::Bind(&WebFileWriterImpl::DidFinish, AsWeakPtr()))); | 174 base::Bind(&WebFileWriterImpl::DidFinish, AsWeakPtr()))); |
| 153 } | 175 } |
| 154 | 176 |
| 155 void WebFileWriterImpl::RunOnMainThread(const base::Closure& closure) { | 177 void WebFileWriterImpl::RunOnMainThread(const base::Closure& closure) { |
| 156 if (main_thread_loop_->RunsTasksOnCurrentThread()) { | 178 if (main_thread_loop_->RunsTasksOnCurrentThread()) { |
| 157 DCHECK(!bridge_->waitable_event()); | 179 DCHECK(!bridge_->waitable_event()); |
| 158 closure.Run(); | 180 closure.Run(); |
| 159 return; | 181 return; |
| 160 } | 182 } |
| 161 main_thread_loop_->PostTask(FROM_HERE, closure); | 183 main_thread_loop_->PostTask(FROM_HERE, closure); |
| 162 if (bridge_->waitable_event()) | 184 if (bridge_->waitable_event()) |
| 163 bridge_->WaitAndRun(); | 185 bridge_->WaitAndRun(); |
| 164 } | 186 } |
| 165 | 187 |
| 166 } // namespace content | 188 } // namespace content |
| OLD | NEW |