| 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 // TODO(iclelland): Remove the body of this method once it is implemented in
all subclasses. | 32 // TODO(iclelland): Remove the body of this method once it is implemented in
all subclasses. |
| 100 virtual void registerBackgroundSync(const WebSyncRegistration* options, WebS
erviceWorkerRegistration* serviceWorkerRegistration, bool requestedFromServiceWo
rker, WebSyncRegistrationCallbacks* callbacks) | 33 virtual void registerBackgroundSync(const WebSyncRegistration* options, WebS
erviceWorkerRegistration* serviceWorkerRegistration, bool requestedFromServiceWo
rker, WebSyncRegistrationCallbacks* callbacks) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 virtual void releaseRegistration(int64_t syncId) | 72 virtual void releaseRegistration(int64_t syncId) |
| 140 { | 73 { |
| 141 // TODO(jkarlin): After landing both legs of the releaseRegistration CLs
, make this a pure virtual function. | 74 // TODO(jkarlin): After landing both legs of the releaseRegistration CLs
, make this a pure virtual function. |
| 142 return; | 75 return; |
| 143 } | 76 } |
| 144 }; | 77 }; |
| 145 | 78 |
| 146 } // namespace blink | 79 } // namespace blink |
| 147 | 80 |
| 148 #endif // WebSyncProvider_h | 81 #endif // WebSyncProvider_h |
| OLD | NEW |