OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
30 #include "config.h" | |
31 #include "WebFileSystemCallbacksImpl.h" | |
32 | |
33 #include "AsyncFileSystemChromium.h" | |
34 #include "core/platform/AsyncFileSystemCallbacks.h" | |
35 #include "core/platform/FileMetadata.h" | |
36 #include "public/platform/WebFileInfo.h" | |
37 #include "public/platform/WebFileSystem.h" | |
38 #include "public/platform/WebFileSystemEntry.h" | |
39 #include "public/platform/WebFileWriter.h" | |
40 #include "public/platform/WebString.h" | |
41 #include "wtf/Vector.h" | |
42 | |
43 using namespace WebCore; | |
44 | |
45 namespace WebKit { | |
46 | |
47 WebFileSystemCallbacksImpl::WebFileSystemCallbacksImpl(PassOwnPtr<AsyncFileSyste
mCallbacks> callbacks) | |
48 : m_callbacks(callbacks) | |
49 { | |
50 ASSERT(m_callbacks); | |
51 } | |
52 | |
53 WebFileSystemCallbacksImpl::~WebFileSystemCallbacksImpl() | |
54 { | |
55 } | |
56 | |
57 void WebFileSystemCallbacksImpl::didSucceed() | |
58 { | |
59 m_callbacks->didSucceed(); | |
60 delete this; | |
61 } | |
62 | |
63 void WebFileSystemCallbacksImpl::didReadMetadata(const WebFileInfo& webFileInfo) | |
64 { | |
65 FileMetadata fileMetadata; | |
66 fileMetadata.modificationTime = webFileInfo.modificationTime; | |
67 fileMetadata.length = webFileInfo.length; | |
68 fileMetadata.type = static_cast<FileMetadata::Type>(webFileInfo.type); | |
69 fileMetadata.platformPath = webFileInfo.platformPath; | |
70 m_callbacks->didReadMetadata(fileMetadata); | |
71 delete this; | |
72 } | |
73 | |
74 void WebFileSystemCallbacksImpl::didCreateSnapshotFile(const WebFileInfo& webFil
eInfo) | |
75 { | |
76 // It's important to create a BlobDataHandle that refers to the platform fil
e path prior | |
77 // to return from this method so the underlying file will not be deleted. | |
78 OwnPtr<BlobData> blobData = BlobData::create(); | |
79 blobData->appendFile(webFileInfo.platformPath); | |
80 RefPtr<BlobDataHandle> snapshotBlob = BlobDataHandle::create(blobData.releas
e(), webFileInfo.length); | |
81 didCreateSnapshotFile(webFileInfo, snapshotBlob); | |
82 } | |
83 | |
84 void WebFileSystemCallbacksImpl::didCreateSnapshotFile(const WebFileInfo& webFil
eInfo, PassRefPtr<WebCore::BlobDataHandle> snapshot) | |
85 { | |
86 FileMetadata fileMetadata; | |
87 fileMetadata.modificationTime = webFileInfo.modificationTime; | |
88 fileMetadata.length = webFileInfo.length; | |
89 fileMetadata.type = static_cast<FileMetadata::Type>(webFileInfo.type); | |
90 fileMetadata.platformPath = webFileInfo.platformPath; | |
91 m_callbacks->didCreateSnapshotFile(fileMetadata, snapshot); | |
92 delete this; | |
93 } | |
94 | |
95 void WebFileSystemCallbacksImpl::didReadDirectory(const WebVector<WebFileSystemE
ntry>& entries, bool hasMore) | |
96 { | |
97 for (size_t i = 0; i < entries.size(); ++i) | |
98 m_callbacks->didReadDirectoryEntry(entries[i].name, entries[i].isDirecto
ry); | |
99 m_callbacks->didReadDirectoryEntries(hasMore); | |
100 delete this; | |
101 } | |
102 | |
103 void WebFileSystemCallbacksImpl::didOpenFileSystem(const WebString& name, const
WebURL& rootURL) | |
104 { | |
105 // This object is intended to delete itself on exit. | |
106 OwnPtr<WebFileSystemCallbacksImpl> callbacks = adoptPtr(this); | |
107 m_callbacks->didOpenFileSystem(name, rootURL, AsyncFileSystemChromium::creat
e()); | |
108 } | |
109 | |
110 void WebFileSystemCallbacksImpl::didCreateFileWriter(WebFileWriter* webFileWrite
r, long long length) | |
111 { | |
112 // This object is intended to delete itself on exit. | |
113 OwnPtr<WebFileSystemCallbacksImpl> callbacks = adoptPtr(this); | |
114 | |
115 m_callbacks->didCreateFileWriter(adoptPtr(webFileWriter), length); | |
116 } | |
117 | |
118 void WebFileSystemCallbacksImpl::didFail(WebFileError error) | |
119 { | |
120 m_callbacks->didFail(error); | |
121 delete this; | |
122 } | |
123 | |
124 bool WebFileSystemCallbacksImpl::shouldBlockUntilCompletion() const | |
125 { | |
126 return m_callbacks->shouldBlockUntilCompletion(); | |
127 } | |
128 | |
129 } // namespace WebKit | |
OLD | NEW |