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 29 matching lines...) Expand all Loading... |
40 #include "modules/filesystem/EntryCallback.h" | 40 #include "modules/filesystem/EntryCallback.h" |
41 #include "modules/filesystem/EntrySync.h" | 41 #include "modules/filesystem/EntrySync.h" |
42 #include "modules/filesystem/ErrorCallback.h" | 42 #include "modules/filesystem/ErrorCallback.h" |
43 #include "modules/filesystem/FileEntry.h" | 43 #include "modules/filesystem/FileEntry.h" |
44 #include "modules/filesystem/FileSystemCallback.h" | 44 #include "modules/filesystem/FileSystemCallback.h" |
45 #include "modules/filesystem/MetadataCallback.h" | 45 #include "modules/filesystem/MetadataCallback.h" |
46 #include "platform/heap/Handle.h" | 46 #include "platform/heap/Handle.h" |
47 | 47 |
48 namespace blink { | 48 namespace blink { |
49 | 49 |
50 template <typename ResultType, typename CallbackArg> | |
51 struct HelperResultType { | |
52 DISALLOW_NEW(); | |
53 public: | |
54 typedef ResultType* ReturnType; | |
55 typedef Member<ResultType> StorageType; | |
56 | |
57 static ReturnType createFromCallbackArg(CallbackArg argument) | |
58 { | |
59 return ResultType::create(argument); | |
60 } | |
61 }; | |
62 | |
63 // A helper template for FileSystemSync implementation. | 50 // A helper template for FileSystemSync implementation. |
64 template <typename SuccessCallback, typename CallbackArg, typename ResultType> | 51 template <typename SuccessCallback, typename CallbackArg, typename ResultType> |
65 class SyncCallbackHelper final : public GarbageCollected<SyncCallbackHelper<Succ
essCallback, CallbackArg, ResultType>> { | 52 class SyncCallbackHelper final : public GarbageCollected<SyncCallbackHelper<Succ
essCallback, CallbackArg, ResultType>> { |
66 public: | 53 public: |
67 typedef SyncCallbackHelper<SuccessCallback, CallbackArg, ResultType> HelperT
ype; | 54 typedef SyncCallbackHelper<SuccessCallback, CallbackArg, ResultType> HelperT
ype; |
68 typedef HelperResultType<ResultType, CallbackArg> ResultTypeTrait; | |
69 typedef typename ResultTypeTrait::StorageType ResultStorageType; | |
70 typedef typename ResultTypeTrait::ReturnType ResultReturnType; | |
71 | 55 |
72 static HelperType* create() | 56 static HelperType* create() |
73 { | 57 { |
74 return new SyncCallbackHelper(); | 58 return new SyncCallbackHelper(); |
75 } | 59 } |
76 | 60 |
77 ResultReturnType getResult(ExceptionState& exceptionState) | 61 ResultType* getResult(ExceptionState& exceptionState) |
78 { | 62 { |
79 if (m_errorCode) | 63 if (m_errorCode) |
80 FileError::throwDOMException(exceptionState, m_errorCode); | 64 FileError::throwDOMException(exceptionState, m_errorCode); |
81 | 65 |
82 return m_result; | 66 return m_result; |
83 } | 67 } |
84 | 68 |
85 SuccessCallback* getSuccessCallback() { return SuccessCallbackImpl::create(t
his); } | 69 SuccessCallback* getSuccessCallback() { return SuccessCallbackImpl::create(t
his); } |
86 ErrorCallback* getErrorCallback() { return ErrorCallbackImpl::create(this);
} | 70 ErrorCallback* getErrorCallback() { return ErrorCallbackImpl::create(this);
} |
87 | 71 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 }; | 140 }; |
157 | 141 |
158 void setError(FileError::ErrorCode code) | 142 void setError(FileError::ErrorCode code) |
159 { | 143 { |
160 m_errorCode = code; | 144 m_errorCode = code; |
161 m_completed = true; | 145 m_completed = true; |
162 } | 146 } |
163 | 147 |
164 void setResult(CallbackArg result) | 148 void setResult(CallbackArg result) |
165 { | 149 { |
166 m_result = ResultTypeTrait::createFromCallbackArg(result); | 150 m_result = ResultType::create(result); |
167 m_completed = true; | 151 m_completed = true; |
168 } | 152 } |
169 | 153 |
170 ResultStorageType m_result; | 154 Member<ResultType> m_result; |
171 FileError::ErrorCode m_errorCode; | 155 FileError::ErrorCode m_errorCode; |
172 bool m_completed; | 156 bool m_completed; |
173 }; | 157 }; |
174 | 158 |
175 struct EmptyType : public GarbageCollected<EmptyType> { | 159 struct EmptyType : public GarbageCollected<EmptyType> { |
176 static EmptyType* create(EmptyType*) | 160 static EmptyType* create(EmptyType*) |
177 { | 161 { |
178 return 0; | 162 return 0; |
179 } | 163 } |
180 | 164 |
181 DEFINE_INLINE_TRACE() { } | 165 DEFINE_INLINE_TRACE() { } |
182 }; | 166 }; |
183 | 167 |
184 typedef SyncCallbackHelper<EntryCallback, Entry*, EntrySync> EntrySyncCallbackHe
lper; | 168 typedef SyncCallbackHelper<EntryCallback, Entry*, EntrySync> EntrySyncCallbackHe
lper; |
185 typedef SyncCallbackHelper<MetadataCallback, Metadata*, Metadata> MetadataSyncCa
llbackHelper; | 169 typedef SyncCallbackHelper<MetadataCallback, Metadata*, Metadata> MetadataSyncCa
llbackHelper; |
186 typedef SyncCallbackHelper<VoidCallback, EmptyType*, EmptyType> VoidSyncCallback
Helper; | 170 typedef SyncCallbackHelper<VoidCallback, EmptyType*, EmptyType> VoidSyncCallback
Helper; |
187 typedef SyncCallbackHelper<FileSystemCallback, DOMFileSystem*, DOMFileSystemSync
> FileSystemSyncCallbackHelper; | 171 typedef SyncCallbackHelper<FileSystemCallback, DOMFileSystem*, DOMFileSystemSync
> FileSystemSyncCallbackHelper; |
188 | 172 |
189 } // namespace blink | 173 } // namespace blink |
190 | 174 |
191 #endif // SyncCallbackHelper_h | 175 #endif // SyncCallbackHelper_h |
OLD | NEW |