Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: public/platform/modules/background_sync/WebSyncProvider.h

Issue 1311053002: [BackgroundSync] Use appopriate type parameters for WebCallbacks (2/4) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.
(...skipping 30 matching lines...) Expand all
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698