Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/common/fileapi/webfilewriter_impl.h" | 5 #include "content/common/fileapi/webfilewriter_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | |
| 7 #include "content/common/child_thread.h" | 8 #include "content/common/child_thread.h" |
| 8 #include "content/common/fileapi/file_system_dispatcher.h" | 9 #include "content/common/fileapi/file_system_dispatcher.h" |
| 9 | 10 |
| 10 namespace content { | 11 namespace content { |
| 12 | |
| 11 namespace { | 13 namespace { |
| 12 | 14 |
| 13 inline FileSystemDispatcher* GetFileSystemDispatcher() { | 15 inline FileSystemDispatcher* GetFileSystemDispatcher() { |
| 14 return ChildThread::current()->file_system_dispatcher(); | 16 return ChildThread::current()->file_system_dispatcher(); |
| 15 } | 17 } |
| 16 } | |
| 17 | 18 |
| 18 class WebFileWriterImpl::CallbackDispatcher | 19 } // namespace |
| 19 : public fileapi::FileSystemCallbackDispatcher { | |
| 20 public: | |
| 21 explicit CallbackDispatcher( | |
| 22 const base::WeakPtr<WebFileWriterImpl>& writer) : writer_(writer) { | |
| 23 } | |
| 24 virtual ~CallbackDispatcher() { | |
| 25 } | |
| 26 virtual void DidReadMetadata( | |
| 27 const base::PlatformFileInfo&, | |
| 28 const base::FilePath&) OVERRIDE { | |
| 29 NOTREACHED(); | |
| 30 } | |
| 31 virtual void DidCreateSnapshotFile( | |
| 32 const base::PlatformFileInfo&, | |
| 33 const base::FilePath&) OVERRIDE { | |
| 34 NOTREACHED(); | |
| 35 } | |
| 36 virtual void DidReadDirectory( | |
| 37 const std::vector<base::FileUtilProxy::Entry>& entries, | |
| 38 bool has_more) OVERRIDE { | |
| 39 NOTREACHED(); | |
| 40 } | |
| 41 virtual void DidOpenFileSystem(const std::string& name, | |
| 42 const GURL& root) OVERRIDE { | |
| 43 NOTREACHED(); | |
| 44 } | |
| 45 virtual void DidSucceed() OVERRIDE { | |
| 46 if (writer_) | |
| 47 writer_->DidSucceed(); | |
| 48 } | |
| 49 virtual void DidFail(base::PlatformFileError error_code) OVERRIDE { | |
| 50 if (writer_) | |
| 51 writer_->DidFail(error_code); | |
| 52 } | |
| 53 virtual void DidWrite(int64 bytes, bool complete) OVERRIDE { | |
| 54 if (writer_) | |
| 55 writer_->DidWrite(bytes, complete); | |
| 56 } | |
| 57 | |
| 58 private: | |
| 59 base::WeakPtr<WebFileWriterImpl> writer_; | |
| 60 }; | |
| 61 | 20 |
| 62 WebFileWriterImpl::WebFileWriterImpl( | 21 WebFileWriterImpl::WebFileWriterImpl( |
| 63 const GURL& path, WebKit::WebFileWriterClient* client) | 22 const GURL& path, WebKit::WebFileWriterClient* client) |
| 64 : WebFileWriterBase(path, client), | 23 : WebFileWriterBase(path, client), |
| 65 request_id_(0) { | 24 request_id_(0) { |
| 66 } | 25 } |
| 67 | 26 |
| 68 WebFileWriterImpl::~WebFileWriterImpl() { | 27 WebFileWriterImpl::~WebFileWriterImpl() { |
| 69 } | 28 } |
| 70 | 29 |
| 71 void WebFileWriterImpl::DoTruncate(const GURL& path, int64 offset) { | 30 void WebFileWriterImpl::DoTruncate(const GURL& path, int64 offset) { |
| 72 // The FileSystemDispatcher takes ownership of the CallbackDispatcher. | 31 // The FileSystemDispatcher takes ownership of the CallbackDispatcher. |
| 73 GetFileSystemDispatcher()->Truncate(path, offset, &request_id_, | 32 GetFileSystemDispatcher()->Truncate( |
| 74 new CallbackDispatcher(AsWeakPtr())); | 33 path, offset, &request_id_, |
| 34 base::Bind(&WebFileWriterImpl::DidFinish, AsWeakPtr())); | |
| 75 } | 35 } |
| 76 | 36 |
| 77 void WebFileWriterImpl::DoWrite( | 37 void WebFileWriterImpl::DoWrite( |
| 78 const GURL& path, const GURL& blob_url, int64 offset) { | 38 const GURL& path, const GURL& blob_url, int64 offset) { |
| 79 GetFileSystemDispatcher()->Write( | 39 GetFileSystemDispatcher()->Write( |
| 80 path, blob_url, offset, &request_id_, | 40 path, blob_url, offset, &request_id_, |
| 81 new CallbackDispatcher(AsWeakPtr())); | 41 base::Bind(&WebFileWriterImpl::DidWrite, AsWeakPtr()), |
| 42 base::Bind(&WebFileWriterImpl::DidFinish, AsWeakPtr())); | |
|
michaeln
2013/05/15 20:18:26
since this is a subclass, shouldn't need to be pub
kinuko
2013/05/16 09:29:38
Done.
| |
| 82 } | 43 } |
| 83 | 44 |
| 84 void WebFileWriterImpl::DoCancel() { | 45 void WebFileWriterImpl::DoCancel() { |
| 85 GetFileSystemDispatcher()->Cancel(request_id_, | 46 GetFileSystemDispatcher()->Cancel( |
| 86 new CallbackDispatcher(AsWeakPtr())); | 47 request_id_, |
| 48 base::Bind(&WebFileWriterImpl::DidFinish, AsWeakPtr())); | |
| 87 } | 49 } |
| 88 | 50 |
| 89 } // namespace content | 51 } // namespace content |
| OLD | NEW |