| 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 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, | 53 void Write(const GURL& path, const std::string& id, int64 offset, |
| 68 const WriteCallback& write_callback, | 54 const WriteCallback& write_callback, |
| 69 const StatusCallback& error_callback) { | 55 const StatusCallback& error_callback) { |
| 70 write_callback_ = write_callback; | 56 write_callback_ = write_callback; |
| 71 status_callback_ = error_callback; | 57 status_callback_ = error_callback; |
| 72 if (!GetFileSystemDispatcher()) | 58 if (!GetFileSystemDispatcher()) |
| 73 return; | 59 return; |
| 74 ChildThread::current()->file_system_dispatcher()->Write( | 60 ChildThread::current()->file_system_dispatcher()->Write( |
| 75 path, id, offset, &request_id_, | 61 path, id, offset, &request_id_, |
| 76 base::Bind(&WriterBridge::DidWrite, this), | 62 base::Bind(&WriterBridge::DidWrite, this), |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 | 132 |
| 147 WebFileWriterImpl::~WebFileWriterImpl() { | 133 WebFileWriterImpl::~WebFileWriterImpl() { |
| 148 } | 134 } |
| 149 | 135 |
| 150 void WebFileWriterImpl::DoTruncate(const GURL& path, int64 offset) { | 136 void WebFileWriterImpl::DoTruncate(const GURL& path, int64 offset) { |
| 151 RunOnMainThread(base::Bind(&WriterBridge::Truncate, bridge_, | 137 RunOnMainThread(base::Bind(&WriterBridge::Truncate, bridge_, |
| 152 path, offset, | 138 path, offset, |
| 153 base::Bind(&WebFileWriterImpl::DidFinish, AsWeakPtr()))); | 139 base::Bind(&WebFileWriterImpl::DidFinish, AsWeakPtr()))); |
| 154 } | 140 } |
| 155 | 141 |
| 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 | |
| 164 void WebFileWriterImpl::DoWrite( | 142 void WebFileWriterImpl::DoWrite( |
| 165 const GURL& path, const std::string& blob_id, int64 offset) { | 143 const GURL& path, const std::string& blob_id, int64 offset) { |
| 166 RunOnMainThread(base::Bind(&WriterBridge::Write, bridge_, | 144 RunOnMainThread(base::Bind(&WriterBridge::Write, bridge_, |
| 167 path, blob_id, offset, | 145 path, blob_id, offset, |
| 168 base::Bind(&WebFileWriterImpl::DidWrite, AsWeakPtr()), | 146 base::Bind(&WebFileWriterImpl::DidWrite, AsWeakPtr()), |
| 169 base::Bind(&WebFileWriterImpl::DidFinish, AsWeakPtr()))); | 147 base::Bind(&WebFileWriterImpl::DidFinish, AsWeakPtr()))); |
| 170 } | 148 } |
| 171 | 149 |
| 172 void WebFileWriterImpl::DoCancel() { | 150 void WebFileWriterImpl::DoCancel() { |
| 173 RunOnMainThread(base::Bind(&WriterBridge::Cancel, bridge_, | 151 RunOnMainThread(base::Bind(&WriterBridge::Cancel, bridge_, |
| 174 base::Bind(&WebFileWriterImpl::DidFinish, AsWeakPtr()))); | 152 base::Bind(&WebFileWriterImpl::DidFinish, AsWeakPtr()))); |
| 175 } | 153 } |
| 176 | 154 |
| 177 void WebFileWriterImpl::RunOnMainThread(const base::Closure& closure) { | 155 void WebFileWriterImpl::RunOnMainThread(const base::Closure& closure) { |
| 178 if (main_thread_loop_->RunsTasksOnCurrentThread()) { | 156 if (main_thread_loop_->RunsTasksOnCurrentThread()) { |
| 179 DCHECK(!bridge_->waitable_event()); | 157 DCHECK(!bridge_->waitable_event()); |
| 180 closure.Run(); | 158 closure.Run(); |
| 181 return; | 159 return; |
| 182 } | 160 } |
| 183 main_thread_loop_->PostTask(FROM_HERE, closure); | 161 main_thread_loop_->PostTask(FROM_HERE, closure); |
| 184 if (bridge_->waitable_event()) | 162 if (bridge_->waitable_event()) |
| 185 bridge_->WaitAndRun(); | 163 bridge_->WaitAndRun(); |
| 186 } | 164 } |
| 187 | 165 |
| 188 } // namespace content | 166 } // namespace content |
| OLD | NEW |