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/WebString.h" | 11 #include "public/platform/WebString.h" |
11 #include "public/platform/WebVector.h" | 12 #include "public/platform/WebVector.h" |
12 #include "public/platform/modules/background_sync/WebSyncError.h" | 13 #include "public/platform/modules/background_sync/WebSyncError.h" |
13 #include "public/platform/modules/background_sync/WebSyncPermissionStatus.h" | 14 #include "public/platform/modules/background_sync/WebSyncPermissionStatus.h" |
14 #include "public/platform/modules/background_sync/WebSyncRegistration.h" | 15 #include "public/platform/modules/background_sync/WebSyncRegistration.h" |
15 | 16 |
16 namespace blink { | 17 namespace blink { |
17 | 18 |
18 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&>; | |
19 | 34 |
20 using WebSyncRegistrationCallbacks = WebCallbacks<WebSyncRegistration*, WebSyncE rror*>; | 35 template <> |
21 using WebSyncNotifyWhenDoneCallbacks = WebCallbacks<bool*, WebSyncError*>; | 36 class WebCallbacks<bool, const WebSyncError&> { |
22 using WebSyncUnregistrationCallbacks = WebCallbacks<bool*, WebSyncError*>; | 37 public: |
23 using WebSyncGetRegistrationsCallbacks = WebCallbacks<WebVector<WebSyncRegistrat ion*>*, WebSyncError*>; | 38 virtual ~WebCallbacks() {} |
24 using WebSyncGetPermissionStatusCallbacks = WebCallbacks<WebSyncPermissionStatus *, WebSyncError*>; | 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&>; | |
53 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&>; | |
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&>; | |
25 | 92 |
26 class WebSyncProvider { | 93 class WebSyncProvider { |
27 public: | 94 public: |
28 virtual ~WebSyncProvider() { } | 95 virtual ~WebSyncProvider() { } |
29 | 96 |
30 // Takes ownership of the WebSyncRegistrationCallbacks. | 97 // Takes ownership of the WebSyncRegistrationCallbacks. |
31 // Does not take ownership of the WebServiceWorkerRegistration. | 98 // Does not take ownership of the WebServiceWorkerRegistration. |
32 virtual void registerBackgroundSync(const WebSyncRegistration*, WebServiceWo rkerRegistration*, WebSyncRegistrationCallbacks*) = 0; | 99 virtual void registerBackgroundSync(const WebSyncRegistration*, WebServiceWo rkerRegistration*, WebSyncRegistrationCallbacks*) = 0; |
33 | 100 |
34 // Takes ownership of the WebSyncUnregistrationCallbacks. | 101 // Takes ownership of the WebSyncUnregistrationCallbacks. |
35 // Does not take ownership of the WebServiceWorkerRegistration. | 102 // Does not take ownership of the WebServiceWorkerRegistration. |
36 virtual void unregisterBackgroundSync(blink::WebSyncRegistration::Periodicit y, int64_t, const WebString&, WebServiceWorkerRegistration*, WebSyncUnregistrati onCallbacks*) = 0; | 103 virtual void unregisterBackgroundSync(blink::WebSyncRegistration::Periodicit y, int64_t, const WebString&, WebServiceWorkerRegistration*, WebSyncUnregistrati onCallbacks*) = 0; |
37 | 104 |
38 // Takes ownership of the WebSyncRegistrationCallbacks. | 105 // Takes ownership of the WebSyncRegistrationCallbacks. |
39 // Does not take ownership of the WebServiceWorkerRegistration. | 106 // Does not take ownership of the WebServiceWorkerRegistration. |
40 virtual void getRegistration(blink::WebSyncRegistration::Periodicity, const WebString&, WebServiceWorkerRegistration*, WebSyncRegistrationCallbacks*) = 0; | 107 virtual void getRegistration(blink::WebSyncRegistration::Periodicity, const WebString&, WebServiceWorkerRegistration*, WebSyncRegistrationCallbacks*) = 0; |
41 | 108 |
42 // Takes ownership of the WebSyncGetRegistrationsCallbacks. | 109 // Takes ownership of the WebSyncGetRegistrationsCallbacks. |
43 // Does not take ownership of the WebServiceWorkerRegistration. | 110 // Does not take ownership of the WebServiceWorkerRegistration. |
44 virtual void getRegistrations(blink::WebSyncRegistration::Periodicity, WebSe rviceWorkerRegistration*, WebSyncGetRegistrationsCallbacks*) = 0; | 111 virtual void getRegistrations(blink::WebSyncRegistration::Periodicity, WebSe rviceWorkerRegistration*, WebSyncGetRegistrationsCallbacks*) = 0; |
45 | 112 |
46 // Takes ownership of the WebSyncGetPermissionStatusCallbacks. | 113 // Takes ownership of the WebSyncGetPermissionStatusCallbacks. |
47 // Does not take ownership of the WebServiceWorkerRegistration. | 114 // Does not take ownership of the WebServiceWorkerRegistration. |
48 virtual void getPermissionStatus(blink::WebSyncRegistration::Periodicity, We bServiceWorkerRegistration*, WebSyncGetPermissionStatusCallbacks*) = 0; | 115 virtual void getPermissionStatus(blink::WebSyncRegistration::Periodicity, We bServiceWorkerRegistration*, WebSyncGetPermissionStatusCallbacks*) = 0; |
49 | 116 |
50 // Takes ownership of the WebSyncNotifyWhenDoneCallbacks. | 117 // Takes ownership of the WebSyncNotifyWhenDoneCallbacks. |
51 virtual void notifyWhenDone(int64_t syncId, WebSyncNotifyWhenDoneCallbacks* callbacks) | 118 virtual void notifyWhenDone(int64_t syncId, WebSyncNotifyWhenDoneCallbacks* callbacks) |
52 { | 119 { |
53 // TODO(jkarlin): After landing both legs of the notifyWhenDone CLs, mak e this a pure virtual function. | 120 // TODO(jkarlin): After landing both legs of the notifyWhenDone CLs, mak e this a pure virtual function. |
54 callbacks->onError(new WebSyncError(WebSyncError::ErrorTypeAbort, "Funct ion not implemented.")); | 121 callbacks->onError(new WebSyncError(WebSyncError::ErrorTypeAbort, "Funct ion not implemented.")); |
jkarlin
2015/08/26 13:21:16
Won't this fail because of the WebSyncError*?
yhirano
2015/08/27 02:21:52
Technically it's OK because onError(WebSyncError*)
yhirano
2015/08/27 02:23:59
"From code simplicity viewpoint", I mean.
| |
55 delete callbacks; | 122 delete callbacks; |
56 } | 123 } |
57 | 124 |
58 // Takes ownership of the WebServiceWorkerRegistration. | 125 // Takes ownership of the WebServiceWorkerRegistration. |
59 virtual void trackRegistration(WebSyncRegistration* registration) | 126 virtual void trackRegistration(WebSyncRegistration* registration) |
60 { | 127 { |
61 // TODO(jkarlin): After landing both legs of the releaseRegistration CLs , make this a pure virtual function. | 128 // TODO(jkarlin): After landing both legs of the releaseRegistration CLs , make this a pure virtual function. |
62 return; | 129 return; |
63 } | 130 } |
64 | 131 |
65 virtual void releaseRegistration(int64_t syncId) | 132 virtual void releaseRegistration(int64_t syncId) |
66 { | 133 { |
67 // TODO(jkarlin): After landing both legs of the releaseRegistration CLs , make this a pure virtual function. | 134 // TODO(jkarlin): After landing both legs of the releaseRegistration CLs , make this a pure virtual function. |
68 return; | 135 return; |
69 } | 136 } |
70 }; | 137 }; |
71 | 138 |
72 } // namespace blink | 139 } // namespace blink |
73 | 140 |
74 #endif // WebSyncProvider_h | 141 #endif // WebSyncProvider_h |
OLD | NEW |