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 #include "content/child/background_sync/background_sync_provider.h" | 5 #include "content/child/background_sync/background_sync_provider.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "content/child/background_sync/background_sync_type_converters.h" | 9 #include "content/child/background_sync/background_sync_type_converters.h" |
10 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 10 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 // will wipe its callbacks) before 'this' is deleted. | 111 // will wipe its callbacks) before 'this' is deleted. |
112 GetBackgroundSyncServicePtr()->GetRegistrations( | 112 GetBackgroundSyncServicePtr()->GetRegistrations( |
113 mojo::ConvertTo<BackgroundSyncPeriodicity>(periodicity), | 113 mojo::ConvertTo<BackgroundSyncPeriodicity>(periodicity), |
114 service_worker_registration_id, | 114 service_worker_registration_id, |
115 base::Bind(&BackgroundSyncProvider::GetRegistrationsCallback, | 115 base::Bind(&BackgroundSyncProvider::GetRegistrationsCallback, |
116 base::Unretained(this), base::Passed(callbacksPtr.Pass()))); | 116 base::Unretained(this), base::Passed(callbacksPtr.Pass()))); |
117 } | 117 } |
118 | 118 |
119 void BackgroundSyncProvider::RegisterCallback( | 119 void BackgroundSyncProvider::RegisterCallback( |
120 scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacks, | 120 scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacks, |
121 BackgroundSyncError error, | |
121 const SyncRegistrationPtr& options) { | 122 const SyncRegistrationPtr& options) { |
122 // TODO(iclelland): Pass through the various errors from the manager to here | 123 // TODO(iclelland): Determine the correct error message to return in each case |
123 // and handle them appropriately. | |
124 scoped_ptr<blink::WebSyncRegistration> result; | 124 scoped_ptr<blink::WebSyncRegistration> result; |
125 if (!options.is_null()) | 125 switch (error) { |
126 result = mojo::ConvertTo<scoped_ptr<blink::WebSyncRegistration>>(options); | 126 case BACKGROUND_SYNC_ERROR_NONE: |
127 | 127 if (!options.is_null()) |
128 callbacks->onSuccess(result.release()); | 128 result = |
jkarlin
2015/05/13 11:19:46
Might as well declare result here as it's not used
iclelland
2015/05/13 11:48:36
clang doesn't allow variable declaration from with
jkarlin
2015/05/13 12:01:56
My bad, what you have is fine.
| |
129 mojo::ConvertTo<scoped_ptr<blink::WebSyncRegistration>>(options); | |
130 callbacks->onSuccess(result.release()); | |
131 break; | |
132 case BACKGROUND_SYNC_ERROR_NOT_FOUND: | |
133 callbacks->onSuccess(nullptr); | |
jkarlin
2015/05/13 11:19:46
This should be a NOTREACHED() case
iclelland
2015/05/13 11:48:36
Perhaps I should rename the method instead; the sa
jkarlin
2015/05/13 12:01:56
I see. Yes, I'd split them into different callback
iclelland
2015/05/13 12:18:32
Done.
| |
134 break; | |
135 case BACKGROUND_SYNC_ERROR_STORAGE: | |
136 callbacks->onError( | |
137 new blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown, | |
138 "Background Sync is disabled.")); | |
139 break; | |
140 case BACKGROUND_SYNC_ERROR_NO_SERVICE_WORKER: | |
141 callbacks->onError( | |
142 new blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown, | |
143 "No service worker is active.")); | |
144 break; | |
145 } | |
129 } | 146 } |
130 | 147 |
131 void BackgroundSyncProvider::UnregisterCallback( | 148 void BackgroundSyncProvider::UnregisterCallback( |
132 scoped_ptr<blink::WebSyncUnregistrationCallbacks> callbacks, | 149 scoped_ptr<blink::WebSyncUnregistrationCallbacks> callbacks, |
133 bool success) { | 150 BackgroundSyncError error) { |
134 // TODO(iclelland): Pass through the various errors from the manager to here | 151 // TODO(iclelland): Determine the correct error message to return in each case |
135 // and handle them appropriately. | 152 switch (error) { |
136 if (success) { | 153 case BACKGROUND_SYNC_ERROR_NONE: |
137 callbacks->onSuccess(new bool(success)); | 154 callbacks->onSuccess(new bool(true)); |
138 } else { | 155 break; |
139 callbacks->onError( | 156 case BACKGROUND_SYNC_ERROR_NOT_FOUND: |
140 new blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown, | 157 callbacks->onSuccess(new bool(false)); |
141 "Sync registration does not exist")); | 158 break; |
159 case BACKGROUND_SYNC_ERROR_STORAGE: | |
160 callbacks->onError( | |
161 new blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown, | |
162 "Background Sync is disabled.")); | |
163 break; | |
164 case BACKGROUND_SYNC_ERROR_NO_SERVICE_WORKER: | |
165 callbacks->onError( | |
166 new blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown, | |
167 "No service worker is active.")); | |
168 break; | |
142 } | 169 } |
143 } | 170 } |
144 | 171 |
145 void BackgroundSyncProvider::GetRegistrationsCallback( | 172 void BackgroundSyncProvider::GetRegistrationsCallback( |
146 scoped_ptr<blink::WebSyncGetRegistrationsCallbacks> callbacks, | 173 scoped_ptr<blink::WebSyncGetRegistrationsCallbacks> callbacks, |
174 BackgroundSyncError error, | |
147 const mojo::Array<SyncRegistrationPtr>& registrations) { | 175 const mojo::Array<SyncRegistrationPtr>& registrations) { |
148 // TODO(iclelland): Pass through the various errors from the manager to here | 176 // TODO(iclelland): Determine the correct error message to return in each case |
149 // and handle them appropriately. | 177 blink::WebVector<blink::WebSyncRegistration*>* results; |
150 blink::WebVector<blink::WebSyncRegistration*>* results = | 178 switch (error) { |
151 new blink::WebVector<blink::WebSyncRegistration*>(registrations.size()); | 179 case BACKGROUND_SYNC_ERROR_NONE: |
152 for (size_t i = 0; i < registrations.size(); ++i) { | 180 results = new blink::WebVector<blink::WebSyncRegistration*>( |
153 (*results)[i] = mojo::ConvertTo<scoped_ptr<blink::WebSyncRegistration>>( | 181 registrations.size()); |
jkarlin
2015/05/13 11:19:46
Results should be declared here
jkarlin
2015/05/13 12:01:56
I retract this comment, you can't declare it withi
| |
154 registrations[i]).release(); | 182 for (size_t i = 0; i < registrations.size(); ++i) { |
183 (*results)[i] = mojo::ConvertTo<scoped_ptr<blink::WebSyncRegistration>>( | |
184 registrations[i]).release(); | |
185 } | |
186 callbacks->onSuccess(results); | |
187 case BACKGROUND_SYNC_ERROR_NOT_FOUND: | |
188 // This error should never be returned from | |
189 // BackgroundSyncManager::GetRegistrations | |
190 NOTREACHED(); | |
191 break; | |
192 case BACKGROUND_SYNC_ERROR_STORAGE: | |
193 callbacks->onError( | |
194 new blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown, | |
195 "Background Sync is disabled.")); | |
196 break; | |
197 case BACKGROUND_SYNC_ERROR_NO_SERVICE_WORKER: | |
198 callbacks->onError( | |
199 new blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown, | |
200 "No service worker is active.")); | |
201 break; | |
155 } | 202 } |
156 callbacks->onSuccess(results); | |
157 } | 203 } |
158 | 204 |
159 BackgroundSyncServicePtr& | 205 BackgroundSyncServicePtr& |
160 BackgroundSyncProvider::GetBackgroundSyncServicePtr() { | 206 BackgroundSyncProvider::GetBackgroundSyncServicePtr() { |
161 if (!background_sync_service_.get()) | 207 if (!background_sync_service_.get()) |
162 service_registry_->ConnectToRemoteService(&background_sync_service_); | 208 service_registry_->ConnectToRemoteService(&background_sync_service_); |
163 return background_sync_service_; | 209 return background_sync_service_; |
164 } | 210 } |
165 | 211 |
166 } // namespace content | 212 } // namespace content |
OLD | NEW |