OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 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 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 namespace WebCore { | 42 namespace WebCore { |
43 | 43 |
44 class DirectoryEntry; | 44 class DirectoryEntry; |
45 class File; | 45 class File; |
46 class FileCallback; | 46 class FileCallback; |
47 class FileEntry; | 47 class FileEntry; |
48 class FileWriterCallback; | 48 class FileWriterCallback; |
49 | 49 |
50 class DOMFileSystem FINAL : public DOMFileSystemBase, public ScriptWrappable, pu
blic ActiveDOMObject { | 50 class DOMFileSystem FINAL : public DOMFileSystemBase, public ScriptWrappable, pu
blic ActiveDOMObject { |
51 public: | 51 public: |
52 static PassRefPtrWillBeRawPtr<DOMFileSystem> create(ExecutionContext*, const
String& name, FileSystemType, const KURL& rootURL); | 52 static DOMFileSystem* create(ExecutionContext*, const String& name, FileSyst
emType, const KURL& rootURL); |
53 | 53 |
54 // Creates a new isolated file system for the given filesystemId. | 54 // Creates a new isolated file system for the given filesystemId. |
55 static PassRefPtrWillBeRawPtr<DOMFileSystem> createIsolatedFileSystem(Execut
ionContext*, const String& filesystemId); | 55 static DOMFileSystem* createIsolatedFileSystem(ExecutionContext*, const Stri
ng& filesystemId); |
56 | 56 |
57 PassRefPtrWillBeRawPtr<DirectoryEntry> root(); | 57 DirectoryEntry* root(); |
58 | 58 |
59 // DOMFileSystemBase overrides. | 59 // DOMFileSystemBase overrides. |
60 virtual void addPendingCallbacks() OVERRIDE; | 60 virtual void addPendingCallbacks() OVERRIDE; |
61 virtual void removePendingCallbacks() OVERRIDE; | 61 virtual void removePendingCallbacks() OVERRIDE; |
62 virtual void reportError(PassOwnPtr<ErrorCallback>, PassRefPtrWillBeRawPtr<F
ileError>) OVERRIDE; | 62 virtual void reportError(PassOwnPtr<ErrorCallback>, PassRefPtrWillBeRawPtr<F
ileError>) OVERRIDE; |
63 | 63 |
64 // ActiveDOMObject overrides. | 64 // ActiveDOMObject overrides. |
65 virtual bool hasPendingActivity() const OVERRIDE; | 65 virtual bool hasPendingActivity() const OVERRIDE; |
66 | 66 |
67 void createWriter(const FileEntry*, PassOwnPtr<FileWriterCallback>, PassOwnP
tr<ErrorCallback>); | 67 void createWriter(const FileEntry*, PassOwnPtr<FileWriterCallback>, PassOwnP
tr<ErrorCallback>); |
68 void createFile(const FileEntry*, PassOwnPtr<FileCallback>, PassOwnPtr<Error
Callback>); | 68 void createFile(const FileEntry*, PassOwnPtr<FileCallback>, PassOwnPtr<Error
Callback>); |
69 | 69 |
70 // Schedule a callback. This should not cross threads (should be called on t
he same context thread). | 70 // Schedule a callback. This should not cross threads (should be called on t
he same context thread). |
71 // FIXME: move this to a more generic place. | 71 // FIXME: move this to a more generic place. |
72 template <typename CB, typename CBArg> | 72 template <typename CB, typename CBArg> |
73 static void scheduleCallback(ExecutionContext*, PassOwnPtr<CB>, PassRefPtrWi
llBeRawPtr<CBArg>); | 73 static void scheduleCallback(ExecutionContext*, PassOwnPtr<CB>, PassRefPtrWi
llBeRawPtr<CBArg>); |
74 | 74 |
75 template <typename CB, typename CBArg> | 75 template <typename CB, typename CBArg> |
| 76 static void scheduleCallback(ExecutionContext*, PassOwnPtr<CB>, CBArg*); |
| 77 |
| 78 template <typename CB, typename CBArg> |
76 static void scheduleCallback(ExecutionContext*, PassOwnPtr<CB>, const HeapVe
ctor<CBArg>&); | 79 static void scheduleCallback(ExecutionContext*, PassOwnPtr<CB>, const HeapVe
ctor<CBArg>&); |
77 | 80 |
78 template <typename CB, typename CBArg> | 81 template <typename CB, typename CBArg> |
79 static void scheduleCallback(ExecutionContext*, PassOwnPtr<CB>, const CBArg&
); | 82 static void scheduleCallback(ExecutionContext*, PassOwnPtr<CB>, const CBArg&
); |
80 | 83 |
81 template <typename CB> | 84 template <typename CB> |
82 static void scheduleCallback(ExecutionContext*, PassOwnPtr<CB>); | 85 static void scheduleCallback(ExecutionContext*, PassOwnPtr<CB>); |
83 | 86 |
84 template <typename CB, typename CBArg> | 87 template <typename CB, typename CBArg> |
85 void scheduleCallback(PassOwnPtr<CB> callback, PassRefPtrWillBeRawPtr<CBArg>
callbackArg) | 88 void scheduleCallback(PassOwnPtr<CB> callback, PassRefPtrWillBeRawPtr<CBArg>
callbackArg) |
86 { | 89 { |
87 scheduleCallback(executionContext(), callback, callbackArg); | 90 scheduleCallback(executionContext(), callback, callbackArg); |
88 } | 91 } |
89 | 92 |
90 template <typename CB, typename CBArg> | 93 template <typename CB, typename CBArg> |
| 94 void scheduleCallback(PassOwnPtr<CB> callback, CBArg* callbackArg) |
| 95 { |
| 96 scheduleCallback(executionContext(), callback, callbackArg); |
| 97 } |
| 98 |
| 99 template <typename CB, typename CBArg> |
91 void scheduleCallback(PassOwnPtr<CB> callback, const CBArg& callbackArg) | 100 void scheduleCallback(PassOwnPtr<CB> callback, const CBArg& callbackArg) |
92 { | 101 { |
93 scheduleCallback(executionContext(), callback, callbackArg); | 102 scheduleCallback(executionContext(), callback, callbackArg); |
94 } | 103 } |
95 | 104 |
96 private: | 105 private: |
97 DOMFileSystem(ExecutionContext*, const String& name, FileSystemType, const K
URL& rootURL); | 106 DOMFileSystem(ExecutionContext*, const String& name, FileSystemType, const K
URL& rootURL); |
98 | 107 |
99 // A helper template to schedule a callback task. | 108 // A helper template to schedule a callback task. |
100 template <typename CB, typename CBArg> | 109 template <typename CB, typename CBArg> |
101 class DispatchCallbacRefPtrArgTask FINAL : public ExecutionContextTask { | 110 class DispatchCallbackRefPtrArgTask FINAL : public ExecutionContextTask { |
102 public: | 111 public: |
103 DispatchCallbacRefPtrArgTask(PassOwnPtr<CB> callback, PassRefPtrWillBeRa
wPtr<CBArg> arg) | 112 DispatchCallbackRefPtrArgTask(PassOwnPtr<CB> callback, PassRefPtrWillBeR
awPtr<CBArg> arg) |
104 : m_callback(callback) | 113 : m_callback(callback) |
105 , m_callbackArg(arg) | 114 , m_callbackArg(arg) |
106 { | 115 { |
107 } | 116 } |
108 | 117 |
109 virtual void performTask(ExecutionContext*) OVERRIDE | 118 virtual void performTask(ExecutionContext*) OVERRIDE |
110 { | 119 { |
111 m_callback->handleEvent(m_callbackArg.get()); | 120 m_callback->handleEvent(m_callbackArg.get()); |
112 } | 121 } |
113 | 122 |
114 private: | 123 private: |
115 OwnPtr<CB> m_callback; | 124 OwnPtr<CB> m_callback; |
116 RefPtrWillBePersistent<CBArg> m_callbackArg; | 125 RefPtrWillBePersistent<CBArg> m_callbackArg; |
117 }; | 126 }; |
118 | 127 |
119 template <typename CB, typename CBArg> | 128 template <typename CB, typename CBArg> |
| 129 class DispatchCallbackPtrArgTask FINAL : public ExecutionContextTask { |
| 130 public: |
| 131 DispatchCallbackPtrArgTask(PassOwnPtr<CB> callback, CBArg* arg) |
| 132 : m_callback(callback) |
| 133 , m_callbackArg(arg) |
| 134 { |
| 135 } |
| 136 |
| 137 virtual void performTask(ExecutionContext*) OVERRIDE |
| 138 { |
| 139 m_callback->handleEvent(m_callbackArg.get()); |
| 140 } |
| 141 |
| 142 private: |
| 143 OwnPtr<CB> m_callback; |
| 144 Persistent<CBArg> m_callbackArg; |
| 145 }; |
| 146 |
| 147 template <typename CB, typename CBArg> |
120 class DispatchCallbackNonPtrArgTask FINAL : public ExecutionContextTask { | 148 class DispatchCallbackNonPtrArgTask FINAL : public ExecutionContextTask { |
121 public: | 149 public: |
122 DispatchCallbackNonPtrArgTask(PassOwnPtr<CB> callback, const CBArg& arg) | 150 DispatchCallbackNonPtrArgTask(PassOwnPtr<CB> callback, const CBArg& arg) |
123 : m_callback(callback) | 151 : m_callback(callback) |
124 , m_callbackArg(arg) | 152 , m_callbackArg(arg) |
125 { | 153 { |
126 } | 154 } |
127 | 155 |
128 virtual void performTask(ExecutionContext*) OVERRIDE | 156 virtual void performTask(ExecutionContext*) OVERRIDE |
129 { | 157 { |
(...skipping 23 matching lines...) Expand all Loading... |
153 }; | 181 }; |
154 | 182 |
155 int m_numberOfPendingCallbacks; | 183 int m_numberOfPendingCallbacks; |
156 }; | 184 }; |
157 | 185 |
158 template <typename CB, typename CBArg> | 186 template <typename CB, typename CBArg> |
159 void DOMFileSystem::scheduleCallback(ExecutionContext* executionContext, PassOwn
Ptr<CB> callback, PassRefPtrWillBeRawPtr<CBArg> arg) | 187 void DOMFileSystem::scheduleCallback(ExecutionContext* executionContext, PassOwn
Ptr<CB> callback, PassRefPtrWillBeRawPtr<CBArg> arg) |
160 { | 188 { |
161 ASSERT(executionContext->isContextThread()); | 189 ASSERT(executionContext->isContextThread()); |
162 if (callback) | 190 if (callback) |
163 executionContext->postTask(adoptPtr(new DispatchCallbacRefPtrArgTask<CB,
CBArg>(callback, arg))); | 191 executionContext->postTask(adoptPtr(new DispatchCallbackRefPtrArgTask<CB
, CBArg>(callback, arg))); |
164 } | 192 } |
165 | 193 |
166 template <typename CB, typename CBArg> | 194 template <typename CB, typename CBArg> |
| 195 void DOMFileSystem::scheduleCallback(ExecutionContext* executionContext, PassOwn
Ptr<CB> callback, CBArg* arg) |
| 196 { |
| 197 ASSERT(executionContext->isContextThread()); |
| 198 if (callback) |
| 199 executionContext->postTask(adoptPtr(new DispatchCallbackPtrArgTask<CB, C
BArg>(callback, arg))); |
| 200 } |
| 201 |
| 202 template <typename CB, typename CBArg> |
167 void DOMFileSystem::scheduleCallback(ExecutionContext* executionContext, PassOwn
Ptr<CB> callback, const HeapVector<CBArg>& arg) | 203 void DOMFileSystem::scheduleCallback(ExecutionContext* executionContext, PassOwn
Ptr<CB> callback, const HeapVector<CBArg>& arg) |
168 { | 204 { |
169 ASSERT(executionContext->isContextThread()); | 205 ASSERT(executionContext->isContextThread()); |
170 if (callback) | 206 if (callback) |
171 executionContext->postTask(adoptPtr(new DispatchCallbackNonPtrArgTask<CB
, PersistentHeapVector<CBArg> >(callback, arg))); | 207 executionContext->postTask(adoptPtr(new DispatchCallbackNonPtrArgTask<CB
, PersistentHeapVector<CBArg> >(callback, arg))); |
172 } | 208 } |
173 | 209 |
174 template <typename CB, typename CBArg> | 210 template <typename CB, typename CBArg> |
175 void DOMFileSystem::scheduleCallback(ExecutionContext* executionContext, PassOwn
Ptr<CB> callback, const CBArg& arg) | 211 void DOMFileSystem::scheduleCallback(ExecutionContext* executionContext, PassOwn
Ptr<CB> callback, const CBArg& arg) |
176 { | 212 { |
177 ASSERT(executionContext->isContextThread()); | 213 ASSERT(executionContext->isContextThread()); |
178 if (callback) | 214 if (callback) |
179 executionContext->postTask(adoptPtr(new DispatchCallbackNonPtrArgTask<CB
, CBArg>(callback, arg))); | 215 executionContext->postTask(adoptPtr(new DispatchCallbackNonPtrArgTask<CB
, CBArg>(callback, arg))); |
180 } | 216 } |
181 | 217 |
182 template <typename CB> | 218 template <typename CB> |
183 void DOMFileSystem::scheduleCallback(ExecutionContext* executionContext, PassOwn
Ptr<CB> callback) | 219 void DOMFileSystem::scheduleCallback(ExecutionContext* executionContext, PassOwn
Ptr<CB> callback) |
184 { | 220 { |
185 ASSERT(executionContext->isContextThread()); | 221 ASSERT(executionContext->isContextThread()); |
186 if (callback) | 222 if (callback) |
187 executionContext->postTask(adoptPtr(new DispatchCallbackNoArgTask<CB>(ca
llback))); | 223 executionContext->postTask(adoptPtr(new DispatchCallbackNoArgTask<CB>(ca
llback))); |
188 } | 224 } |
189 | 225 |
190 } // namespace | 226 } // namespace |
191 | 227 |
192 #endif // DOMFileSystem_h | 228 #endif // DOMFileSystem_h |
OLD | NEW |