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 <utility> |
| 8 |
7 #include "background_sync_registration_handle.h" | 9 #include "background_sync_registration_handle.h" |
8 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
9 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
10 #include "content/browser/background_sync/background_sync_context_impl.h" | 12 #include "content/browser/background_sync/background_sync_context_impl.h" |
11 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
12 | 14 |
13 namespace content { | 15 namespace content { |
14 | 16 |
15 namespace { | 17 namespace { |
16 | 18 |
(...skipping 17 matching lines...) Expand all Loading... |
34 SyncRegistrationPtr out(content::SyncRegistration::New()); | 36 SyncRegistrationPtr out(content::SyncRegistration::New()); |
35 out->handle_id = in.handle_id(); | 37 out->handle_id = in.handle_id(); |
36 out->tag = in.options()->tag; | 38 out->tag = in.options()->tag; |
37 out->min_period_ms = in.options()->min_period; | 39 out->min_period_ms = in.options()->min_period; |
38 out->periodicity = static_cast<content::BackgroundSyncPeriodicity>( | 40 out->periodicity = static_cast<content::BackgroundSyncPeriodicity>( |
39 in.options()->periodicity); | 41 in.options()->periodicity); |
40 out->power_state = | 42 out->power_state = |
41 static_cast<content::BackgroundSyncPowerState>(in.options()->power_state); | 43 static_cast<content::BackgroundSyncPowerState>(in.options()->power_state); |
42 out->network_state = static_cast<content::BackgroundSyncNetworkState>( | 44 out->network_state = static_cast<content::BackgroundSyncNetworkState>( |
43 in.options()->network_state); | 45 in.options()->network_state); |
44 return out.Pass(); | 46 return out; |
45 } | 47 } |
46 | 48 |
47 } // namespace | 49 } // namespace |
48 | 50 |
49 #define COMPILE_ASSERT_MATCHING_ENUM(mojo_name, manager_name) \ | 51 #define COMPILE_ASSERT_MATCHING_ENUM(mojo_name, manager_name) \ |
50 static_assert(static_cast<int>(content::mojo_name) == \ | 52 static_assert(static_cast<int>(content::mojo_name) == \ |
51 static_cast<int>(content::manager_name), \ | 53 static_cast<int>(content::manager_name), \ |
52 "mojo and manager enums must match") | 54 "mojo and manager enums must match") |
53 | 55 |
54 // TODO(iclelland): Move these tests somewhere else | 56 // TODO(iclelland): Move these tests somewhere else |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 92 |
91 BackgroundSyncServiceImpl::~BackgroundSyncServiceImpl() { | 93 BackgroundSyncServiceImpl::~BackgroundSyncServiceImpl() { |
92 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 94 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
93 DCHECK(background_sync_context_->background_sync_manager()); | 95 DCHECK(background_sync_context_->background_sync_manager()); |
94 } | 96 } |
95 | 97 |
96 BackgroundSyncServiceImpl::BackgroundSyncServiceImpl( | 98 BackgroundSyncServiceImpl::BackgroundSyncServiceImpl( |
97 BackgroundSyncContextImpl* background_sync_context, | 99 BackgroundSyncContextImpl* background_sync_context, |
98 mojo::InterfaceRequest<BackgroundSyncService> request) | 100 mojo::InterfaceRequest<BackgroundSyncService> request) |
99 : background_sync_context_(background_sync_context), | 101 : background_sync_context_(background_sync_context), |
100 binding_(this, request.Pass()), | 102 binding_(this, std::move(request)), |
101 weak_ptr_factory_(this) { | 103 weak_ptr_factory_(this) { |
102 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 104 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
103 DCHECK(background_sync_context); | 105 DCHECK(background_sync_context); |
104 | 106 |
105 binding_.set_connection_error_handler( | 107 binding_.set_connection_error_handler( |
106 base::Bind(&BackgroundSyncServiceImpl::OnConnectionError, | 108 base::Bind(&BackgroundSyncServiceImpl::OnConnectionError, |
107 base::Unretained(this) /* the channel is owned by this */)); | 109 base::Unretained(this) /* the channel is owned by this */)); |
108 } | 110 } |
109 | 111 |
110 void BackgroundSyncServiceImpl::OnConnectionError() { | 112 void BackgroundSyncServiceImpl::OnConnectionError() { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 | 207 |
206 if (!registration_handle) { | 208 if (!registration_handle) { |
207 callback.Run(BACKGROUND_SYNC_ERROR_NOT_FOUND, | 209 callback.Run(BACKGROUND_SYNC_ERROR_NOT_FOUND, |
208 SyncRegistrationPtr(content::SyncRegistration::New())); | 210 SyncRegistrationPtr(content::SyncRegistration::New())); |
209 return; | 211 return; |
210 } | 212 } |
211 | 213 |
212 active_handles_.AddWithID(registration_handle.release(), | 214 active_handles_.AddWithID(registration_handle.release(), |
213 handle_ptr->handle_id()); | 215 handle_ptr->handle_id()); |
214 SyncRegistrationPtr mojoResult = ToMojoRegistration(*handle_ptr); | 216 SyncRegistrationPtr mojoResult = ToMojoRegistration(*handle_ptr); |
215 callback.Run(BACKGROUND_SYNC_ERROR_NONE, mojoResult.Pass()); | 217 callback.Run(BACKGROUND_SYNC_ERROR_NONE, std::move(mojoResult)); |
216 } | 218 } |
217 | 219 |
218 void BackgroundSyncServiceImpl::ReleaseRegistration( | 220 void BackgroundSyncServiceImpl::ReleaseRegistration( |
219 BackgroundSyncRegistrationHandle::HandleId handle_id) { | 221 BackgroundSyncRegistrationHandle::HandleId handle_id) { |
220 if (!active_handles_.Lookup(handle_id)) { | 222 if (!active_handles_.Lookup(handle_id)) { |
221 // TODO(jkarlin): Abort client. | 223 // TODO(jkarlin): Abort client. |
222 LOG(WARNING) << "Client attempted to release non-existing registration"; | 224 LOG(WARNING) << "Client attempted to release non-existing registration"; |
223 return; | 225 return; |
224 } | 226 } |
225 | 227 |
(...skipping 27 matching lines...) Expand all Loading... |
253 if (status != BACKGROUND_SYNC_STATUS_OK) { | 255 if (status != BACKGROUND_SYNC_STATUS_OK) { |
254 callback.Run(static_cast<content::BackgroundSyncError>(status), | 256 callback.Run(static_cast<content::BackgroundSyncError>(status), |
255 SyncRegistrationPtr(content::SyncRegistration::New())); | 257 SyncRegistrationPtr(content::SyncRegistration::New())); |
256 return; | 258 return; |
257 } | 259 } |
258 | 260 |
259 DCHECK(result); | 261 DCHECK(result); |
260 active_handles_.AddWithID(result.release(), result_ptr->handle_id()); | 262 active_handles_.AddWithID(result.release(), result_ptr->handle_id()); |
261 SyncRegistrationPtr mojoResult = ToMojoRegistration(*result_ptr); | 263 SyncRegistrationPtr mojoResult = ToMojoRegistration(*result_ptr); |
262 callback.Run(static_cast<content::BackgroundSyncError>(status), | 264 callback.Run(static_cast<content::BackgroundSyncError>(status), |
263 mojoResult.Pass()); | 265 std::move(mojoResult)); |
264 } | 266 } |
265 | 267 |
266 void BackgroundSyncServiceImpl::OnUnregisterResult( | 268 void BackgroundSyncServiceImpl::OnUnregisterResult( |
267 const UnregisterCallback& callback, | 269 const UnregisterCallback& callback, |
268 BackgroundSyncStatus status) { | 270 BackgroundSyncStatus status) { |
269 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 271 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
270 callback.Run(static_cast<content::BackgroundSyncError>(status)); | 272 callback.Run(static_cast<content::BackgroundSyncError>(status)); |
271 } | 273 } |
272 | 274 |
273 void BackgroundSyncServiceImpl::OnGetRegistrationsResult( | 275 void BackgroundSyncServiceImpl::OnGetRegistrationsResult( |
274 const GetRegistrationsCallback& callback, | 276 const GetRegistrationsCallback& callback, |
275 BackgroundSyncStatus status, | 277 BackgroundSyncStatus status, |
276 scoped_ptr<ScopedVector<BackgroundSyncRegistrationHandle>> | 278 scoped_ptr<ScopedVector<BackgroundSyncRegistrationHandle>> |
277 result_registrations) { | 279 result_registrations) { |
278 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 280 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
279 DCHECK(result_registrations); | 281 DCHECK(result_registrations); |
280 | 282 |
281 mojo::Array<content::SyncRegistrationPtr> mojo_registrations(0); | 283 mojo::Array<content::SyncRegistrationPtr> mojo_registrations(0); |
282 for (BackgroundSyncRegistrationHandle* registration : *result_registrations) { | 284 for (BackgroundSyncRegistrationHandle* registration : *result_registrations) { |
283 active_handles_.AddWithID(registration, registration->handle_id()); | 285 active_handles_.AddWithID(registration, registration->handle_id()); |
284 mojo_registrations.push_back(ToMojoRegistration(*registration)); | 286 mojo_registrations.push_back(ToMojoRegistration(*registration)); |
285 } | 287 } |
286 | 288 |
287 result_registrations->weak_clear(); | 289 result_registrations->weak_clear(); |
288 | 290 |
289 callback.Run(static_cast<content::BackgroundSyncError>(status), | 291 callback.Run(static_cast<content::BackgroundSyncError>(status), |
290 mojo_registrations.Pass()); | 292 std::move(mojo_registrations)); |
291 } | 293 } |
292 | 294 |
293 void BackgroundSyncServiceImpl::OnNotifyWhenFinishedResult( | 295 void BackgroundSyncServiceImpl::OnNotifyWhenFinishedResult( |
294 const NotifyWhenFinishedCallback& callback, | 296 const NotifyWhenFinishedCallback& callback, |
295 BackgroundSyncStatus status, | 297 BackgroundSyncStatus status, |
296 BackgroundSyncState sync_state) { | 298 BackgroundSyncState sync_state) { |
297 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 299 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
298 callback.Run(static_cast<content::BackgroundSyncError>(status), sync_state); | 300 callback.Run(static_cast<content::BackgroundSyncError>(status), sync_state); |
299 } | 301 } |
300 | 302 |
301 } // namespace content | 303 } // namespace content |
OLD | NEW |