OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef WebSyncProvider_h | 5 #ifndef WebSyncProvider_h |
6 #define WebSyncProvider_h | 6 #define WebSyncProvider_h |
7 | 7 |
8 #include "public/platform/WebCallbacks.h" | 8 #include "public/platform/WebCallbacks.h" |
9 #include "public/platform/WebCommon.h" | 9 #include "public/platform/WebCommon.h" |
10 #include "public/platform/WebPassOwnPtr.h" | 10 #include "public/platform/WebPassOwnPtr.h" |
11 #include "public/platform/WebString.h" | 11 #include "public/platform/WebString.h" |
12 #include "public/platform/WebVector.h" | 12 #include "public/platform/WebVector.h" |
13 #include "public/platform/modules/background_sync/WebSyncError.h" | 13 #include "public/platform/modules/background_sync/WebSyncError.h" |
14 #include "public/platform/modules/background_sync/WebSyncPermissionStatus.h" | 14 #include "public/platform/modules/background_sync/WebSyncPermissionStatus.h" |
15 #include "public/platform/modules/background_sync/WebSyncRegistration.h" | 15 #include "public/platform/modules/background_sync/WebSyncRegistration.h" |
16 | 16 |
17 namespace blink { | 17 namespace blink { |
18 | 18 |
19 class WebServiceWorkerRegistration; | 19 class WebServiceWorkerRegistration; |
20 template <> | |
21 class WebCallbacks<WebPassOwnPtr<WebSyncRegistration>, const WebSyncError&> { | |
22 public: | |
23 virtual ~WebCallbacks() {} | |
24 void onSuccess(WebSyncRegistration* r) { onSuccess(adoptWebPtr(r)); } | |
25 void onError(WebSyncError* e) | |
26 { | |
27 onError(*e); | |
28 delete e; | |
29 } | |
30 virtual void onSuccess(WebPassOwnPtr<WebSyncRegistration>) = 0; | |
31 virtual void onError(const WebSyncError&) = 0; | |
32 }; | |
33 using WebSyncRegistrationCallbacks = WebCallbacks<WebPassOwnPtr<WebSyncRegistrat ion>, const WebSyncError&>; | 20 using WebSyncRegistrationCallbacks = WebCallbacks<WebPassOwnPtr<WebSyncRegistrat ion>, const WebSyncError&>; |
34 | |
35 template <> | |
36 class WebCallbacks<bool, const WebSyncError&> { | |
37 public: | |
38 virtual ~WebCallbacks() {} | |
39 void onSuccess(bool* r) | |
40 { | |
41 onSuccess(*r); | |
42 delete r; | |
43 } | |
44 void onError(WebSyncError* e) | |
45 { | |
46 onError(*e); | |
47 delete e; | |
48 } | |
49 virtual void onSuccess(bool) = 0; | |
50 virtual void onError(const WebSyncError&) = 0; | |
51 }; | |
52 using WebSyncNotifyWhenDoneCallbacks = WebCallbacks<bool, const WebSyncError&>; | 21 using WebSyncNotifyWhenDoneCallbacks = WebCallbacks<bool, const WebSyncError&>; |
53 using WebSyncUnregistrationCallbacks = WebCallbacks<bool, const WebSyncError&>; | 22 using WebSyncUnregistrationCallbacks = WebCallbacks<bool, const WebSyncError&>; |
54 | |
55 template <> | |
56 class WebCallbacks<const WebVector<WebSyncRegistration*>&, const WebSyncError&> { | |
57 public: | |
58 virtual ~WebCallbacks() {} | |
59 void onSuccess(WebVector<WebSyncRegistration*>* r) | |
60 { | |
61 onSuccess(*r); | |
62 delete r; | |
63 } | |
64 void onError(WebSyncError* e) | |
65 { | |
66 onError(*e); | |
67 delete e; | |
68 } | |
69 virtual void onSuccess(const WebVector<WebSyncRegistration*>&) = 0; | |
70 virtual void onError(const WebSyncError&) = 0; | |
71 }; | |
72 using WebSyncGetRegistrationsCallbacks = WebCallbacks<const WebVector<WebSyncReg istration*>&, const WebSyncError&>; | 23 using WebSyncGetRegistrationsCallbacks = WebCallbacks<const WebVector<WebSyncReg istration*>&, const WebSyncError&>; |
73 | |
74 template <> | |
75 class WebCallbacks<WebSyncPermissionStatus, const WebSyncError&> { | |
76 public: | |
77 virtual ~WebCallbacks() {} | |
78 void onSuccess(WebSyncPermissionStatus* r) | |
79 { | |
80 onSuccess(*r); | |
81 delete r; | |
82 } | |
83 void onError(WebSyncError* e) | |
84 { | |
85 onError(*e); | |
86 delete e; | |
87 } | |
88 virtual void onSuccess(WebSyncPermissionStatus) = 0; | |
89 virtual void onError(const WebSyncError&) = 0; | |
90 }; | |
91 using WebSyncGetPermissionStatusCallbacks = WebCallbacks<WebSyncPermissionStatus , const WebSyncError&>; | 24 using WebSyncGetPermissionStatusCallbacks = WebCallbacks<WebSyncPermissionStatus , const WebSyncError&>; |
92 | 25 |
93 class WebSyncProvider { | 26 class WebSyncProvider { |
94 public: | 27 public: |
95 virtual ~WebSyncProvider() { } | 28 virtual ~WebSyncProvider() { } |
96 | 29 |
97 // Takes ownership of the WebSyncRegistrationCallbacks. | 30 // Takes ownership of the WebSyncRegistrationCallbacks. |
98 // Does not take ownership of the WebServiceWorkerRegistration. | 31 // Does not take ownership of the WebServiceWorkerRegistration. |
99 virtual void registerBackgroundSync(const WebSyncRegistration*, WebServiceWo rkerRegistration*, WebSyncRegistrationCallbacks*) = 0; | 32 virtual void registerBackgroundSync(const WebSyncRegistration*, WebServiceWo rkerRegistration*, WebSyncRegistrationCallbacks*) = 0; |
100 | 33 |
(...skipping 10 matching lines...) Expand all Loading... | |
111 virtual void getRegistrations(blink::WebSyncRegistration::Periodicity, WebSe rviceWorkerRegistration*, WebSyncGetRegistrationsCallbacks*) = 0; | 44 virtual void getRegistrations(blink::WebSyncRegistration::Periodicity, WebSe rviceWorkerRegistration*, WebSyncGetRegistrationsCallbacks*) = 0; |
112 | 45 |
113 // Takes ownership of the WebSyncGetPermissionStatusCallbacks. | 46 // Takes ownership of the WebSyncGetPermissionStatusCallbacks. |
114 // Does not take ownership of the WebServiceWorkerRegistration. | 47 // Does not take ownership of the WebServiceWorkerRegistration. |
115 virtual void getPermissionStatus(blink::WebSyncRegistration::Periodicity, We bServiceWorkerRegistration*, WebSyncGetPermissionStatusCallbacks*) = 0; | 48 virtual void getPermissionStatus(blink::WebSyncRegistration::Periodicity, We bServiceWorkerRegistration*, WebSyncGetPermissionStatusCallbacks*) = 0; |
116 | 49 |
117 // Takes ownership of the WebSyncNotifyWhenDoneCallbacks. | 50 // Takes ownership of the WebSyncNotifyWhenDoneCallbacks. |
118 virtual void notifyWhenDone(int64_t syncId, WebSyncNotifyWhenDoneCallbacks* callbacks) | 51 virtual void notifyWhenDone(int64_t syncId, WebSyncNotifyWhenDoneCallbacks* callbacks) |
119 { | 52 { |
120 // TODO(jkarlin): After landing both legs of the notifyWhenDone CLs, mak e this a pure virtual function. | 53 // TODO(jkarlin): After landing both legs of the notifyWhenDone CLs, mak e this a pure virtual function. |
121 callbacks->onError(new WebSyncError(WebSyncError::ErrorTypeAbort, "Funct ion not implemented.")); | 54 callbacks->onError(WebSyncError(WebSyncError::ErrorTypeAbort, "Function not implemented.")); |
jkarlin
2015/08/26 13:21:41
Shouldn't this fix be in the second CL?
yhirano
2015/08/27 02:23:05
Done.
| |
122 delete callbacks; | 55 delete callbacks; |
123 } | 56 } |
124 | 57 |
125 // Takes ownership of the WebServiceWorkerRegistration. | 58 // Takes ownership of the WebServiceWorkerRegistration. |
126 virtual void trackRegistration(WebSyncRegistration* registration) | 59 virtual void trackRegistration(WebSyncRegistration* registration) |
127 { | 60 { |
128 // TODO(jkarlin): After landing both legs of the releaseRegistration CLs , make this a pure virtual function. | 61 // TODO(jkarlin): After landing both legs of the releaseRegistration CLs , make this a pure virtual function. |
129 return; | 62 return; |
130 } | 63 } |
131 | 64 |
132 virtual void releaseRegistration(int64_t syncId) | 65 virtual void releaseRegistration(int64_t syncId) |
133 { | 66 { |
134 // TODO(jkarlin): After landing both legs of the releaseRegistration CLs , make this a pure virtual function. | 67 // TODO(jkarlin): After landing both legs of the releaseRegistration CLs , make this a pure virtual function. |
135 return; | 68 return; |
136 } | 69 } |
137 }; | 70 }; |
138 | 71 |
139 } // namespace blink | 72 } // namespace blink |
140 | 73 |
141 #endif // WebSyncProvider_h | 74 #endif // WebSyncProvider_h |
OLD | NEW |