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/browser/background_sync/background_sync_service_impl.h" | 5 #include "content/browser/background_sync/background_sync_service_impl.h" |
6 | 6 |
7 #include "background_sync_registration_handle.h" | 7 #include "background_sync_registration_handle.h" |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "content/browser/background_sync/background_sync_context_impl.h" | 10 #include "content/browser/background_sync/background_sync_context_impl.h" |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 BackgroundSyncRegistrationHandle::HandleId handle_id) { | 220 BackgroundSyncRegistrationHandle::HandleId handle_id) { |
221 if (!active_handles_.Lookup(handle_id)) { | 221 if (!active_handles_.Lookup(handle_id)) { |
222 // TODO(jkarlin): Abort client. | 222 // TODO(jkarlin): Abort client. |
223 LOG(WARNING) << "Client attempted to release non-existing registration"; | 223 LOG(WARNING) << "Client attempted to release non-existing registration"; |
224 return; | 224 return; |
225 } | 225 } |
226 | 226 |
227 active_handles_.Remove(handle_id); | 227 active_handles_.Remove(handle_id); |
228 } | 228 } |
229 | 229 |
| 230 void BackgroundSyncServiceImpl::NotifyWhenDone( |
| 231 BackgroundSyncRegistrationHandle::HandleId handle_id, |
| 232 const NotifyWhenDoneCallback& callback) { |
| 233 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 234 BackgroundSyncRegistrationHandle* registration = |
| 235 active_handles_.Lookup(handle_id); |
| 236 if (!registration) { |
| 237 callback.Run(BACKGROUND_SYNC_ERROR_NOT_ALLOWED, |
| 238 BACKGROUND_SYNC_STATE_FAILED); |
| 239 return; |
| 240 } |
| 241 |
| 242 registration->NotifyWhenDone( |
| 243 base::Bind(&BackgroundSyncServiceImpl::OnNotifyWhenDoneResult, |
| 244 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 245 } |
| 246 |
230 void BackgroundSyncServiceImpl::OnRegisterResult( | 247 void BackgroundSyncServiceImpl::OnRegisterResult( |
231 const RegisterCallback& callback, | 248 const RegisterCallback& callback, |
232 BackgroundSyncStatus status, | 249 BackgroundSyncStatus status, |
233 scoped_ptr<BackgroundSyncRegistrationHandle> result) { | 250 scoped_ptr<BackgroundSyncRegistrationHandle> result) { |
234 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 251 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
235 BackgroundSyncRegistrationHandle* result_ptr = result.get(); | 252 BackgroundSyncRegistrationHandle* result_ptr = result.get(); |
236 | 253 |
237 if (status != BACKGROUND_SYNC_STATUS_OK) { | 254 if (status != BACKGROUND_SYNC_STATUS_OK) { |
238 callback.Run(static_cast<content::BackgroundSyncError>(status), | 255 callback.Run(static_cast<content::BackgroundSyncError>(status), |
239 SyncRegistrationPtr(content::SyncRegistration::New())); | 256 SyncRegistrationPtr(content::SyncRegistration::New())); |
(...skipping 24 matching lines...) Expand all Loading... |
264 active_handles_.AddWithID(registration, registration->handle_id()); | 281 active_handles_.AddWithID(registration, registration->handle_id()); |
265 mojo_registrations.push_back(ToMojoRegistration(*registration)); | 282 mojo_registrations.push_back(ToMojoRegistration(*registration)); |
266 } | 283 } |
267 | 284 |
268 result_registrations->weak_clear(); | 285 result_registrations->weak_clear(); |
269 | 286 |
270 callback.Run(static_cast<content::BackgroundSyncError>(status), | 287 callback.Run(static_cast<content::BackgroundSyncError>(status), |
271 mojo_registrations.Pass()); | 288 mojo_registrations.Pass()); |
272 } | 289 } |
273 | 290 |
| 291 void BackgroundSyncServiceImpl::OnNotifyWhenDoneResult( |
| 292 const NotifyWhenDoneCallback& callback, |
| 293 BackgroundSyncStatus status, |
| 294 BackgroundSyncState sync_state) { |
| 295 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 296 callback.Run(static_cast<content::BackgroundSyncError>(status), sync_state); |
| 297 } |
| 298 |
274 } // namespace content | 299 } // namespace content |
OLD | NEW |