| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2013 Samsung Electronics. All rights reserved. | 3 * Copyright (C) 2013 Samsung Electronics. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 */ | 30 */ |
| 31 | 31 |
| 32 #ifndef SyncCallbackHelper_h | 32 #ifndef SyncCallbackHelper_h |
| 33 #define SyncCallbackHelper_h | 33 #define SyncCallbackHelper_h |
| 34 | 34 |
| 35 #include "bindings/v8/ExceptionState.h" | 35 #include "bindings/v8/ExceptionState.h" |
| 36 #include "core/fileapi/FileError.h" | 36 #include "core/fileapi/FileError.h" |
| 37 #include "core/html/VoidCallback.h" | 37 #include "core/html/VoidCallback.h" |
| 38 #include "modules/filesystem/DirectoryEntry.h" | 38 #include "modules/filesystem/DirectoryEntry.h" |
| 39 #include "modules/filesystem/DirectoryReaderSync.h" | |
| 40 #include "modules/filesystem/EntriesCallback.h" | 39 #include "modules/filesystem/EntriesCallback.h" |
| 41 #include "modules/filesystem/EntryCallback.h" | 40 #include "modules/filesystem/EntryCallback.h" |
| 42 #include "modules/filesystem/EntrySync.h" | 41 #include "modules/filesystem/EntrySync.h" |
| 43 #include "modules/filesystem/ErrorCallback.h" | 42 #include "modules/filesystem/ErrorCallback.h" |
| 44 #include "modules/filesystem/FileEntry.h" | 43 #include "modules/filesystem/FileEntry.h" |
| 45 #include "modules/filesystem/FileSystemCallback.h" | 44 #include "modules/filesystem/FileSystemCallback.h" |
| 46 #include "modules/filesystem/MetadataCallback.h" | 45 #include "modules/filesystem/MetadataCallback.h" |
| 47 #include "wtf/PassRefPtr.h" | 46 #include "wtf/PassRefPtr.h" |
| 48 #include "wtf/RefCounted.h" | 47 #include "wtf/RefCounted.h" |
| 49 | 48 |
| 50 namespace WebCore { | 49 namespace WebCore { |
| 51 | 50 |
| 52 template <typename ResultType, typename CallbackArg> | 51 template <typename ResultType, typename CallbackArg> |
| 53 struct HelperResultType { | 52 struct HelperResultType { |
| 54 typedef PassRefPtr<ResultType> ReturnType; | 53 typedef PassRefPtr<ResultType> ReturnType; |
| 55 typedef RefPtr<ResultType> StorageType; | 54 typedef RefPtr<ResultType> StorageType; |
| 56 | 55 |
| 57 static ReturnType createFromCallbackArg(CallbackArg argument) | 56 static ReturnType createFromCallbackArg(CallbackArg argument) |
| 58 { | 57 { |
| 59 return ResultType::create(argument); | 58 return ResultType::create(argument); |
| 60 } | 59 } |
| 61 }; | 60 }; |
| 62 | 61 |
| 63 template <> | |
| 64 struct HelperResultType<EntrySyncVector, const EntryVector&> { | |
| 65 typedef EntrySyncVector ReturnType; | |
| 66 typedef EntrySyncVector StorageType; | |
| 67 | |
| 68 static EntrySyncVector createFromCallbackArg(const EntryVector& entries) | |
| 69 { | |
| 70 EntrySyncVector result; | |
| 71 size_t entryCount = entries.size(); | |
| 72 result.reserveInitialCapacity(entryCount); | |
| 73 for (size_t i = 0; i < entryCount; ++i) | |
| 74 result.uncheckedAppend(EntrySync::create(entries[i].get())); | |
| 75 return result; | |
| 76 } | |
| 77 }; | |
| 78 | |
| 79 // A helper template for FileSystemSync implementation. | 62 // A helper template for FileSystemSync implementation. |
| 80 template <typename SuccessCallback, typename CallbackArg, typename ResultType> | 63 template <typename SuccessCallback, typename CallbackArg, typename ResultType> |
| 81 class SyncCallbackHelper { | 64 class SyncCallbackHelper { |
| 82 WTF_MAKE_NONCOPYABLE(SyncCallbackHelper); | 65 WTF_MAKE_NONCOPYABLE(SyncCallbackHelper); |
| 83 public: | 66 public: |
| 84 typedef SyncCallbackHelper<SuccessCallback, CallbackArg, ResultType> HelperT
ype; | 67 typedef SyncCallbackHelper<SuccessCallback, CallbackArg, ResultType> HelperT
ype; |
| 85 typedef HelperResultType<ResultType, CallbackArg> ResultTypeTrait; | 68 typedef HelperResultType<ResultType, CallbackArg> ResultTypeTrait; |
| 86 typedef typename ResultTypeTrait::StorageType ResultStorageType; | 69 typedef typename ResultTypeTrait::StorageType ResultStorageType; |
| 87 typedef typename ResultTypeTrait::ReturnType ResultReturnType; | 70 typedef typename ResultTypeTrait::ReturnType ResultReturnType; |
| 88 | 71 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 }; | 151 }; |
| 169 | 152 |
| 170 struct EmptyType : public RefCounted<EmptyType> { | 153 struct EmptyType : public RefCounted<EmptyType> { |
| 171 static PassRefPtr<EmptyType> create(EmptyType*) | 154 static PassRefPtr<EmptyType> create(EmptyType*) |
| 172 { | 155 { |
| 173 return nullptr; | 156 return nullptr; |
| 174 } | 157 } |
| 175 }; | 158 }; |
| 176 | 159 |
| 177 typedef SyncCallbackHelper<EntryCallback, Entry*, EntrySync> EntrySyncCallbackHe
lper; | 160 typedef SyncCallbackHelper<EntryCallback, Entry*, EntrySync> EntrySyncCallbackHe
lper; |
| 178 typedef SyncCallbackHelper<EntriesCallback, const EntryVector&, EntrySyncVector>
EntriesSyncCallbackHelper; | |
| 179 typedef SyncCallbackHelper<MetadataCallback, Metadata*, Metadata> MetadataSyncCa
llbackHelper; | 161 typedef SyncCallbackHelper<MetadataCallback, Metadata*, Metadata> MetadataSyncCa
llbackHelper; |
| 180 typedef SyncCallbackHelper<VoidCallback, EmptyType*, EmptyType> VoidSyncCallback
Helper; | 162 typedef SyncCallbackHelper<VoidCallback, EmptyType*, EmptyType> VoidSyncCallback
Helper; |
| 181 typedef SyncCallbackHelper<FileSystemCallback, DOMFileSystem*, DOMFileSystemSync
> FileSystemSyncCallbackHelper; | 163 typedef SyncCallbackHelper<FileSystemCallback, DOMFileSystem*, DOMFileSystemSync
> FileSystemSyncCallbackHelper; |
| 182 | 164 |
| 183 } // namespace WebCore | 165 } // namespace WebCore |
| 184 | 166 |
| 185 #endif // SyncCallbackHelper_h | 167 #endif // SyncCallbackHelper_h |
| OLD | NEW |