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