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
3 // found in the LICENSE file.
5 #include "content/common/fileapi/webfilesystem_impl.h"
7 #include "content/common/child_thread.h"
8 #include "content/common/fileapi/file_system_dispatcher.h"
9 #include "content/common/fileapi/webfilesystem_callback_dispatcher.h"
10 #include "content/common/fileapi/webfilewriter_impl.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileInfo.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
15 #include "webkit/glue/webkit_glue.h"
17 using WebKit::WebFileInfo
;
18 using WebKit::WebFileSystemCallbacks
;
19 using WebKit::WebFileSystemEntry
;
20 using WebKit::WebString
;
22 using WebKit::WebVector
;
26 WebFileSystemImpl::WebFileSystemImpl() {
29 void WebFileSystemImpl::move(const WebURL
& src_path
,
30 const WebURL
& dest_path
,
31 WebFileSystemCallbacks
* callbacks
) {
32 FileSystemDispatcher
* dispatcher
=
33 ChildThread::current()->file_system_dispatcher();
34 dispatcher
->Move(GURL(src_path
),
36 new WebFileSystemCallbackDispatcher(callbacks
));
39 void WebFileSystemImpl::copy(const WebURL
& src_path
,
40 const WebURL
& dest_path
,
41 WebFileSystemCallbacks
* callbacks
) {
42 FileSystemDispatcher
* dispatcher
=
43 ChildThread::current()->file_system_dispatcher();
44 dispatcher
->Copy(GURL(src_path
),
46 new WebFileSystemCallbackDispatcher(callbacks
));
49 void WebFileSystemImpl::remove(const WebURL
& path
,
50 WebFileSystemCallbacks
* callbacks
) {
51 FileSystemDispatcher
* dispatcher
=
52 ChildThread::current()->file_system_dispatcher();
53 dispatcher
->Remove(GURL(path
),
54 false /* recursive */,
55 new WebFileSystemCallbackDispatcher(callbacks
));
58 void WebFileSystemImpl::removeRecursively(const WebURL
& path
,
59 WebFileSystemCallbacks
* callbacks
) {
60 FileSystemDispatcher
* dispatcher
=
61 ChildThread::current()->file_system_dispatcher();
62 dispatcher
->Remove(GURL(path
),
64 new WebFileSystemCallbackDispatcher(callbacks
));
67 void WebFileSystemImpl::readMetadata(const WebURL
& path
,
68 WebFileSystemCallbacks
* callbacks
) {
69 FileSystemDispatcher
* dispatcher
=
70 ChildThread::current()->file_system_dispatcher();
71 dispatcher
->ReadMetadata(GURL(path
),
72 new WebFileSystemCallbackDispatcher(callbacks
));
75 void WebFileSystemImpl::createFile(const WebURL
& path
,
77 WebFileSystemCallbacks
* callbacks
) {
78 FileSystemDispatcher
* dispatcher
=
79 ChildThread::current()->file_system_dispatcher();
80 dispatcher
->Create(GURL(path
), exclusive
, false,
81 false, new WebFileSystemCallbackDispatcher(callbacks
));
84 void WebFileSystemImpl::createDirectory(const WebURL
& path
,
86 WebFileSystemCallbacks
* callbacks
) {
87 FileSystemDispatcher
* dispatcher
=
88 ChildThread::current()->file_system_dispatcher();
89 dispatcher
->Create(GURL(path
), exclusive
, true,
90 false, new WebFileSystemCallbackDispatcher(callbacks
));
93 void WebFileSystemImpl::fileExists(const WebURL
& path
,
94 WebFileSystemCallbacks
* callbacks
) {
95 FileSystemDispatcher
* dispatcher
=
96 ChildThread::current()->file_system_dispatcher();
97 dispatcher
->Exists(GURL(path
), false,
98 new WebFileSystemCallbackDispatcher(callbacks
));
101 void WebFileSystemImpl::directoryExists(const WebURL
& path
,
102 WebFileSystemCallbacks
* callbacks
) {
103 FileSystemDispatcher
* dispatcher
=
104 ChildThread::current()->file_system_dispatcher();
105 dispatcher
->Exists(GURL(path
), true,
106 new WebFileSystemCallbackDispatcher(callbacks
));
109 void WebFileSystemImpl::readDirectory(const WebURL
& path
,
110 WebFileSystemCallbacks
* callbacks
) {
111 FileSystemDispatcher
* dispatcher
=
112 ChildThread::current()->file_system_dispatcher();
113 dispatcher
->ReadDirectory(GURL(path
),
114 new WebFileSystemCallbackDispatcher(callbacks
));
117 WebKit::WebFileWriter
* WebFileSystemImpl::createFileWriter(
118 const WebURL
& path
, WebKit::WebFileWriterClient
* client
) {
119 return new WebFileWriterImpl(GURL(path
), client
);
122 void WebFileSystemImpl::createSnapshotFileAndReadMetadata(
123 const WebKit::WebURL
& blobURL
,
124 const WebKit::WebURL
& path
,
125 WebKit::WebFileSystemCallbacks
* callbacks
) {
126 FileSystemDispatcher
* dispatcher
=
127 ChildThread::current()->file_system_dispatcher();
128 dispatcher
->CreateSnapshotFile(
129 GURL(blobURL
), GURL(path
),
130 new WebFileSystemCallbackDispatcher(callbacks
));
133 } // namespace content