| 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/webfilesystem_impl.h" | 5 #include "content/common/fileapi/webfilesystem_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 #include "content/common/fileapi/webfilesystem_callback_dispatcher.h" | 10 #include "content/common/fileapi/webfilesystem_callback_dispatcher.h" |
| 10 #include "content/common/fileapi/webfilewriter_impl.h" | 11 #include "content/common/fileapi/webfilewriter_impl.h" |
| 11 #include "third_party/WebKit/Source/Platform/chromium/public/WebFileInfo.h" | 12 #include "third_party/WebKit/Source/Platform/chromium/public/WebFileInfo.h" |
| 12 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | 13 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
| 13 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" | 14 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallback
s.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallback
s.h" |
| 15 #include "webkit/glue/webkit_glue.h" | 16 #include "webkit/glue/webkit_glue.h" |
| 16 | 17 |
| 17 using WebKit::WebFileInfo; | 18 using WebKit::WebFileInfo; |
| 18 using WebKit::WebFileSystemCallbacks; | 19 using WebKit::WebFileSystemCallbacks; |
| 19 using WebKit::WebFileSystemEntry; | 20 using WebKit::WebFileSystemEntry; |
| 20 using WebKit::WebString; | 21 using WebKit::WebString; |
| 21 using WebKit::WebURL; | 22 using WebKit::WebURL; |
| 22 using WebKit::WebVector; | 23 using WebKit::WebVector; |
| 23 | 24 |
| 24 namespace content { | 25 namespace content { |
| 25 | 26 |
| 27 typedef WebFileSystemCallbackDispatcher CallbackDispatcher; |
| 28 |
| 26 WebFileSystemImpl::WebFileSystemImpl() { | 29 WebFileSystemImpl::WebFileSystemImpl() { |
| 27 } | 30 } |
| 28 | 31 |
| 29 void WebFileSystemImpl::move(const WebURL& src_path, | 32 void WebFileSystemImpl::move(const WebURL& src_path, |
| 30 const WebURL& dest_path, | 33 const WebURL& dest_path, |
| 31 WebFileSystemCallbacks* callbacks) { | 34 WebFileSystemCallbacks* callbacks) { |
| 32 FileSystemDispatcher* dispatcher = | 35 FileSystemDispatcher* dispatcher = |
| 33 ChildThread::current()->file_system_dispatcher(); | 36 ChildThread::current()->file_system_dispatcher(); |
| 34 dispatcher->Move(GURL(src_path), | 37 dispatcher->Move(GURL(src_path), |
| 35 GURL(dest_path), | 38 GURL(dest_path), |
| 36 new WebFileSystemCallbackDispatcher(callbacks)); | 39 base::Bind(&CallbackDispatcher::DidFinish, |
| 40 base::Owned(new CallbackDispatcher(callbacks)))); |
| 37 } | 41 } |
| 38 | 42 |
| 39 void WebFileSystemImpl::copy(const WebURL& src_path, | 43 void WebFileSystemImpl::copy(const WebURL& src_path, |
| 40 const WebURL& dest_path, | 44 const WebURL& dest_path, |
| 41 WebFileSystemCallbacks* callbacks) { | 45 WebFileSystemCallbacks* callbacks) { |
| 42 FileSystemDispatcher* dispatcher = | 46 FileSystemDispatcher* dispatcher = |
| 43 ChildThread::current()->file_system_dispatcher(); | 47 ChildThread::current()->file_system_dispatcher(); |
| 44 dispatcher->Copy(GURL(src_path), | 48 dispatcher->Copy(GURL(src_path), |
| 45 GURL(dest_path), | 49 GURL(dest_path), |
| 46 new WebFileSystemCallbackDispatcher(callbacks)); | 50 base::Bind(&CallbackDispatcher::DidFinish, |
| 51 base::Owned(new CallbackDispatcher(callbacks)))); |
| 47 } | 52 } |
| 48 | 53 |
| 49 void WebFileSystemImpl::remove(const WebURL& path, | 54 void WebFileSystemImpl::remove(const WebURL& path, |
| 50 WebFileSystemCallbacks* callbacks) { | 55 WebFileSystemCallbacks* callbacks) { |
| 51 FileSystemDispatcher* dispatcher = | 56 FileSystemDispatcher* dispatcher = |
| 52 ChildThread::current()->file_system_dispatcher(); | 57 ChildThread::current()->file_system_dispatcher(); |
| 53 dispatcher->Remove(GURL(path), | 58 dispatcher->Remove( |
| 54 false /* recursive */, | 59 GURL(path), |
| 55 new WebFileSystemCallbackDispatcher(callbacks)); | 60 false /* recursive */, |
| 61 base::Bind(&CallbackDispatcher::DidFinish, |
| 62 base::Owned(new CallbackDispatcher(callbacks)))); |
| 56 } | 63 } |
| 57 | 64 |
| 58 void WebFileSystemImpl::removeRecursively(const WebURL& path, | 65 void WebFileSystemImpl::removeRecursively(const WebURL& path, |
| 59 WebFileSystemCallbacks* callbacks) { | 66 WebFileSystemCallbacks* callbacks) { |
| 60 FileSystemDispatcher* dispatcher = | 67 FileSystemDispatcher* dispatcher = |
| 61 ChildThread::current()->file_system_dispatcher(); | 68 ChildThread::current()->file_system_dispatcher(); |
| 62 dispatcher->Remove(GURL(path), | 69 dispatcher->Remove( |
| 63 true /* recursive */, | 70 GURL(path), |
| 64 new WebFileSystemCallbackDispatcher(callbacks)); | 71 true /* recursive */, |
| 72 base::Bind(&CallbackDispatcher::DidFinish, |
| 73 base::Owned(new CallbackDispatcher(callbacks)))); |
| 65 } | 74 } |
| 66 | 75 |
| 67 void WebFileSystemImpl::readMetadata(const WebURL& path, | 76 void WebFileSystemImpl::readMetadata(const WebURL& path, |
| 68 WebFileSystemCallbacks* callbacks) { | 77 WebFileSystemCallbacks* callbacks) { |
| 69 FileSystemDispatcher* dispatcher = | 78 FileSystemDispatcher* dispatcher = |
| 70 ChildThread::current()->file_system_dispatcher(); | 79 ChildThread::current()->file_system_dispatcher(); |
| 71 dispatcher->ReadMetadata(GURL(path), | 80 dispatcher->ReadMetadata( |
| 72 new WebFileSystemCallbackDispatcher(callbacks)); | 81 GURL(path), |
| 82 base::Bind(&CallbackDispatcher::DidReadMetadata, |
| 83 base::Owned(new CallbackDispatcher(callbacks)))); |
| 73 } | 84 } |
| 74 | 85 |
| 75 void WebFileSystemImpl::createFile(const WebURL& path, | 86 void WebFileSystemImpl::createFile(const WebURL& path, |
| 76 bool exclusive, | 87 bool exclusive, |
| 77 WebFileSystemCallbacks* callbacks) { | 88 WebFileSystemCallbacks* callbacks) { |
| 78 FileSystemDispatcher* dispatcher = | 89 FileSystemDispatcher* dispatcher = |
| 79 ChildThread::current()->file_system_dispatcher(); | 90 ChildThread::current()->file_system_dispatcher(); |
| 80 dispatcher->Create(GURL(path), exclusive, false, | 91 dispatcher->Create( |
| 81 false, new WebFileSystemCallbackDispatcher(callbacks)); | 92 GURL(path), exclusive, false /* directory */, false /* recursive */, |
| 93 base::Bind(&CallbackDispatcher::DidFinish, |
| 94 base::Owned(new CallbackDispatcher(callbacks)))); |
| 82 } | 95 } |
| 83 | 96 |
| 84 void WebFileSystemImpl::createDirectory(const WebURL& path, | 97 void WebFileSystemImpl::createDirectory(const WebURL& path, |
| 85 bool exclusive, | 98 bool exclusive, |
| 86 WebFileSystemCallbacks* callbacks) { | 99 WebFileSystemCallbacks* callbacks) { |
| 87 FileSystemDispatcher* dispatcher = | 100 FileSystemDispatcher* dispatcher = |
| 88 ChildThread::current()->file_system_dispatcher(); | 101 ChildThread::current()->file_system_dispatcher(); |
| 89 dispatcher->Create(GURL(path), exclusive, true, | 102 dispatcher->Create( |
| 90 false, new WebFileSystemCallbackDispatcher(callbacks)); | 103 GURL(path), exclusive, true /* directory */, false /* recursive */, |
| 104 base::Bind(&CallbackDispatcher::DidFinish, |
| 105 base::Owned(new CallbackDispatcher(callbacks)))); |
| 91 } | 106 } |
| 92 | 107 |
| 93 void WebFileSystemImpl::fileExists(const WebURL& path, | 108 void WebFileSystemImpl::fileExists(const WebURL& path, |
| 94 WebFileSystemCallbacks* callbacks) { | 109 WebFileSystemCallbacks* callbacks) { |
| 95 FileSystemDispatcher* dispatcher = | 110 FileSystemDispatcher* dispatcher = |
| 96 ChildThread::current()->file_system_dispatcher(); | 111 ChildThread::current()->file_system_dispatcher(); |
| 97 dispatcher->Exists(GURL(path), false, | 112 dispatcher->Exists( |
| 98 new WebFileSystemCallbackDispatcher(callbacks)); | 113 GURL(path), false /* directory */, |
| 114 base::Bind(&CallbackDispatcher::DidFinish, |
| 115 base::Owned(new CallbackDispatcher(callbacks)))); |
| 99 } | 116 } |
| 100 | 117 |
| 101 void WebFileSystemImpl::directoryExists(const WebURL& path, | 118 void WebFileSystemImpl::directoryExists(const WebURL& path, |
| 102 WebFileSystemCallbacks* callbacks) { | 119 WebFileSystemCallbacks* callbacks) { |
| 103 FileSystemDispatcher* dispatcher = | 120 FileSystemDispatcher* dispatcher = |
| 104 ChildThread::current()->file_system_dispatcher(); | 121 ChildThread::current()->file_system_dispatcher(); |
| 105 dispatcher->Exists(GURL(path), true, | 122 dispatcher->Exists( |
| 106 new WebFileSystemCallbackDispatcher(callbacks)); | 123 GURL(path), true /* directory */, |
| 124 base::Bind(&CallbackDispatcher::DidFinish, |
| 125 base::Owned(new CallbackDispatcher(callbacks)))); |
| 107 } | 126 } |
| 108 | 127 |
| 109 void WebFileSystemImpl::readDirectory(const WebURL& path, | 128 void WebFileSystemImpl::readDirectory(const WebURL& path, |
| 110 WebFileSystemCallbacks* callbacks) { | 129 WebFileSystemCallbacks* callbacks) { |
| 111 FileSystemDispatcher* dispatcher = | 130 FileSystemDispatcher* dispatcher = |
| 112 ChildThread::current()->file_system_dispatcher(); | 131 ChildThread::current()->file_system_dispatcher(); |
| 113 dispatcher->ReadDirectory(GURL(path), | 132 dispatcher->ReadDirectory( |
| 114 new WebFileSystemCallbackDispatcher(callbacks)); | 133 GURL(path), |
| 134 base::Bind(&CallbackDispatcher::DidReadDirectory, |
| 135 base::Owned(new CallbackDispatcher(callbacks)))); |
| 115 } | 136 } |
| 116 | 137 |
| 117 WebKit::WebFileWriter* WebFileSystemImpl::createFileWriter( | 138 WebKit::WebFileWriter* WebFileSystemImpl::createFileWriter( |
| 118 const WebURL& path, WebKit::WebFileWriterClient* client) { | 139 const WebURL& path, WebKit::WebFileWriterClient* client) { |
| 119 return new WebFileWriterImpl(GURL(path), client); | 140 return new WebFileWriterImpl(GURL(path), client); |
| 120 } | 141 } |
| 121 | 142 |
| 122 void WebFileSystemImpl::createSnapshotFileAndReadMetadata( | 143 void WebFileSystemImpl::createSnapshotFileAndReadMetadata( |
| 123 const WebKit::WebURL& path, | 144 const WebKit::WebURL& path, |
| 124 WebKit::WebFileSystemCallbacks* callbacks) { | 145 WebKit::WebFileSystemCallbacks* callbacks) { |
| 125 FileSystemDispatcher* dispatcher = | 146 FileSystemDispatcher* dispatcher = |
| 126 ChildThread::current()->file_system_dispatcher(); | 147 ChildThread::current()->file_system_dispatcher(); |
| 127 dispatcher->CreateSnapshotFile( | 148 dispatcher->CreateSnapshotFile( |
| 128 GURL(path), new WebFileSystemCallbackDispatcher(callbacks)); | 149 GURL(path), |
| 150 base::Bind(&CallbackDispatcher::DidCreateSnapshotFile, |
| 151 base::Owned(new CallbackDispatcher(callbacks)))); |
| 129 } | 152 } |
| 130 | 153 |
| 131 } // namespace content | 154 } // namespace content |
| OLD | NEW |