| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/common/file_system/webfilewriter_impl.h" | |
| 6 | |
| 7 #include "content/common/child_thread.h" | |
| 8 #include "content/common/file_system/file_system_dispatcher.h" | |
| 9 | |
| 10 namespace { | |
| 11 | |
| 12 inline FileSystemDispatcher* GetFileSystemDispatcher() { | |
| 13 return ChildThread::current()->file_system_dispatcher(); | |
| 14 } | |
| 15 } | |
| 16 | |
| 17 class WebFileWriterImpl::CallbackDispatcher | |
| 18 : public fileapi::FileSystemCallbackDispatcher { | |
| 19 public: | |
| 20 explicit CallbackDispatcher( | |
| 21 const base::WeakPtr<WebFileWriterImpl>& writer) : writer_(writer) { | |
| 22 } | |
| 23 virtual ~CallbackDispatcher() { | |
| 24 } | |
| 25 | |
| 26 virtual void DidReadMetadata(const base::PlatformFileInfo&, const FilePath&) { | |
| 27 NOTREACHED(); | |
| 28 } | |
| 29 virtual void DidReadDirectory( | |
| 30 const std::vector<base::FileUtilProxy::Entry>& entries, | |
| 31 bool has_more) { | |
| 32 NOTREACHED(); | |
| 33 } | |
| 34 virtual void DidOpenFileSystem(const std::string& name, | |
| 35 const GURL& root) { | |
| 36 NOTREACHED(); | |
| 37 } | |
| 38 virtual void DidSucceed() { | |
| 39 if (writer_) | |
| 40 writer_->DidSucceed(); | |
| 41 } | |
| 42 virtual void DidFail(base::PlatformFileError error_code) { | |
| 43 if (writer_) | |
| 44 writer_->DidFail(error_code); | |
| 45 } | |
| 46 virtual void DidWrite(int64 bytes, bool complete) { | |
| 47 if (writer_) | |
| 48 writer_->DidWrite(bytes, complete); | |
| 49 } | |
| 50 | |
| 51 private: | |
| 52 base::WeakPtr<WebFileWriterImpl> writer_; | |
| 53 }; | |
| 54 | |
| 55 WebFileWriterImpl::WebFileWriterImpl( | |
| 56 const GURL& path, WebKit::WebFileWriterClient* client) | |
| 57 : WebFileWriterBase(path, client), | |
| 58 request_id_(0) { | |
| 59 } | |
| 60 | |
| 61 WebFileWriterImpl::~WebFileWriterImpl() { | |
| 62 } | |
| 63 | |
| 64 void WebFileWriterImpl::DoTruncate(const GURL& path, int64 offset) { | |
| 65 // The FileSystemDispatcher takes ownership of the CallbackDispatcher. | |
| 66 GetFileSystemDispatcher()->Truncate(path, offset, &request_id_, | |
| 67 new CallbackDispatcher(AsWeakPtr())); | |
| 68 } | |
| 69 | |
| 70 void WebFileWriterImpl::DoWrite( | |
| 71 const GURL& path, const GURL& blob_url, int64 offset) { | |
| 72 GetFileSystemDispatcher()->Write( | |
| 73 path, blob_url, offset, &request_id_, | |
| 74 new CallbackDispatcher(AsWeakPtr())); | |
| 75 } | |
| 76 | |
| 77 void WebFileWriterImpl::DoCancel() { | |
| 78 GetFileSystemDispatcher()->Cancel(request_id_, | |
| 79 new CallbackDispatcher(AsWeakPtr())); | |
| 80 } | |
| OLD | NEW |