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 21 matching lines...) Expand all Loading... |
32 #ifndef SyncCallbackHelper_h | 32 #ifndef SyncCallbackHelper_h |
33 #define SyncCallbackHelper_h | 33 #define SyncCallbackHelper_h |
34 | 34 |
35 #include "bindings/core/v8/ExceptionState.h" | 35 #include "bindings/core/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/EntriesCallback.h" | 39 #include "modules/filesystem/EntriesCallback.h" |
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" | |
43 #include "modules/filesystem/FileEntry.h" | 42 #include "modules/filesystem/FileEntry.h" |
44 #include "modules/filesystem/FileSystemCallback.h" | 43 #include "modules/filesystem/FileSystemCallback.h" |
| 44 #include "modules/filesystem/FileSystemCallbacks.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 // A helper template for FileSystemSync implementation. | 50 // A helper template for FileSystemSync implementation. |
51 template <typename SuccessCallback, typename CallbackArg, typename ResultType> | 51 template <typename SuccessCallback, typename CallbackArg, typename ResultType> |
52 class SyncCallbackHelper final : public GarbageCollected<SyncCallbackHelper<Succ
essCallback, CallbackArg, ResultType>> { | 52 class SyncCallbackHelper final : public GarbageCollected<SyncCallbackHelper<Succ
essCallback, CallbackArg, ResultType>> { |
53 public: | 53 public: |
54 typedef SyncCallbackHelper<SuccessCallback, CallbackArg, ResultType> HelperT
ype; | 54 typedef SyncCallbackHelper<SuccessCallback, CallbackArg, ResultType> HelperT
ype; |
55 | 55 |
56 static HelperType* create() | 56 static HelperType* create() |
57 { | 57 { |
58 return new SyncCallbackHelper(); | 58 return new SyncCallbackHelper(); |
59 } | 59 } |
60 | 60 |
61 ResultType* getResult(ExceptionState& exceptionState) | 61 ResultType* getResult(ExceptionState& exceptionState) |
62 { | 62 { |
63 if (m_errorCode) | 63 if (m_errorCode) |
64 FileError::throwDOMException(exceptionState, m_errorCode); | 64 FileError::throwDOMException(exceptionState, m_errorCode); |
65 | 65 |
66 return m_result; | 66 return m_result; |
67 } | 67 } |
68 | 68 |
69 SuccessCallback* getSuccessCallback() { return SuccessCallbackImpl::create(t
his); } | 69 SuccessCallback* getSuccessCallback() { return SuccessCallbackImpl::create(t
his); } |
70 ErrorCallback* getErrorCallback() { return ErrorCallbackImpl::create(this);
} | 70 ErrorCallbackBase* getErrorCallback() { return ErrorCallbackImpl::create(thi
s); } |
71 | 71 |
72 DEFINE_INLINE_TRACE() | 72 DEFINE_INLINE_TRACE() |
73 { | 73 { |
74 visitor->trace(m_result); | 74 visitor->trace(m_result); |
75 } | 75 } |
76 | 76 |
77 private: | 77 private: |
78 SyncCallbackHelper() | 78 SyncCallbackHelper() |
79 : m_errorCode(FileError::OK) | 79 : m_errorCode(FileError::OK) |
80 , m_completed(false) | 80 , m_completed(false) |
(...skipping 24 matching lines...) Expand all Loading... |
105 } | 105 } |
106 | 106 |
107 private: | 107 private: |
108 explicit SuccessCallbackImpl(HelperType* helper) | 108 explicit SuccessCallbackImpl(HelperType* helper) |
109 : m_helper(helper) | 109 : m_helper(helper) |
110 { | 110 { |
111 } | 111 } |
112 Member<HelperType> m_helper; | 112 Member<HelperType> m_helper; |
113 }; | 113 }; |
114 | 114 |
115 class ErrorCallbackImpl final : public ErrorCallback { | 115 class ErrorCallbackImpl final : public ErrorCallbackBase { |
116 public: | 116 public: |
117 static ErrorCallbackImpl* create(HelperType* helper) | 117 static ErrorCallbackImpl* create(HelperType* helper) |
118 { | 118 { |
119 return new ErrorCallbackImpl(helper); | 119 return new ErrorCallbackImpl(helper); |
120 } | 120 } |
121 | 121 |
122 void handleEvent(FileError* error) override | 122 void invoke(FileError::ErrorCode error) override |
123 { | 123 { |
124 ASSERT(error); | 124 m_helper->setError(error); |
125 m_helper->setError(error->code()); | |
126 } | 125 } |
127 | 126 |
128 DEFINE_INLINE_TRACE() | 127 DEFINE_INLINE_TRACE() |
129 { | 128 { |
130 visitor->trace(m_helper); | 129 visitor->trace(m_helper); |
131 ErrorCallback::trace(visitor); | 130 ErrorCallbackBase::trace(visitor); |
132 } | 131 } |
133 | 132 |
134 private: | 133 private: |
135 explicit ErrorCallbackImpl(HelperType* helper) | 134 explicit ErrorCallbackImpl(HelperType* helper) |
136 : m_helper(helper) | 135 : m_helper(helper) |
137 { | 136 { |
138 } | 137 } |
139 Member<HelperType> m_helper; | 138 Member<HelperType> m_helper; |
140 }; | 139 }; |
141 | 140 |
142 void setError(FileError::ErrorCode code) | 141 void setError(FileError::ErrorCode error) |
143 { | 142 { |
144 m_errorCode = code; | 143 m_errorCode = error; |
145 m_completed = true; | 144 m_completed = true; |
146 } | 145 } |
147 | 146 |
148 void setResult(CallbackArg result) | 147 void setResult(CallbackArg result) |
149 { | 148 { |
150 m_result = ResultType::create(result); | 149 m_result = ResultType::create(result); |
151 m_completed = true; | 150 m_completed = true; |
152 } | 151 } |
153 | 152 |
154 Member<ResultType> m_result; | 153 Member<ResultType> m_result; |
(...skipping 11 matching lines...) Expand all Loading... |
166 }; | 165 }; |
167 | 166 |
168 typedef SyncCallbackHelper<EntryCallback, Entry*, EntrySync> EntrySyncCallbackHe
lper; | 167 typedef SyncCallbackHelper<EntryCallback, Entry*, EntrySync> EntrySyncCallbackHe
lper; |
169 typedef SyncCallbackHelper<MetadataCallback, Metadata*, Metadata> MetadataSyncCa
llbackHelper; | 168 typedef SyncCallbackHelper<MetadataCallback, Metadata*, Metadata> MetadataSyncCa
llbackHelper; |
170 typedef SyncCallbackHelper<VoidCallback, EmptyType*, EmptyType> VoidSyncCallback
Helper; | 169 typedef SyncCallbackHelper<VoidCallback, EmptyType*, EmptyType> VoidSyncCallback
Helper; |
171 typedef SyncCallbackHelper<FileSystemCallback, DOMFileSystem*, DOMFileSystemSync
> FileSystemSyncCallbackHelper; | 170 typedef SyncCallbackHelper<FileSystemCallback, DOMFileSystem*, DOMFileSystemSync
> FileSystemSyncCallbackHelper; |
172 | 171 |
173 } // namespace blink | 172 } // namespace blink |
174 | 173 |
175 #endif // SyncCallbackHelper_h | 174 #endif // SyncCallbackHelper_h |
OLD | NEW |