| 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> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "background_sync_registration_handle.h" | 9 #include "background_sync_registration_handle.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 } | 47 } |
| 48 | 48 |
| 49 } // namespace | 49 } // namespace |
| 50 | 50 |
| 51 #define COMPILE_ASSERT_MATCHING_ENUM(mojo_name, manager_name) \ | 51 #define COMPILE_ASSERT_MATCHING_ENUM(mojo_name, manager_name) \ |
| 52 static_assert(static_cast<int>(content::mojo_name) == \ | 52 static_assert(static_cast<int>(content::mojo_name) == \ |
| 53 static_cast<int>(content::manager_name), \ | 53 static_cast<int>(content::manager_name), \ |
| 54 "mojo and manager enums must match") | 54 "mojo and manager enums must match") |
| 55 | 55 |
| 56 // TODO(iclelland): Move these tests somewhere else | 56 // TODO(iclelland): Move these tests somewhere else |
| 57 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_ERROR_NONE, | 57 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncError::NONE, |
| 58 BACKGROUND_SYNC_STATUS_OK); | 58 BACKGROUND_SYNC_STATUS_OK); |
| 59 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_ERROR_STORAGE, | 59 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncError::STORAGE, |
| 60 BACKGROUND_SYNC_STATUS_STORAGE_ERROR); | 60 BACKGROUND_SYNC_STATUS_STORAGE_ERROR); |
| 61 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_ERROR_NOT_FOUND, | 61 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncError::NOT_FOUND, |
| 62 BACKGROUND_SYNC_STATUS_NOT_FOUND); | 62 BACKGROUND_SYNC_STATUS_NOT_FOUND); |
| 63 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_ERROR_NO_SERVICE_WORKER, | 63 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncError::NO_SERVICE_WORKER, |
| 64 BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER); | 64 BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER); |
| 65 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_ERROR_NOT_ALLOWED, | 65 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncError::NOT_ALLOWED, |
| 66 BACKGROUND_SYNC_STATUS_NOT_ALLOWED); | 66 BACKGROUND_SYNC_STATUS_NOT_ALLOWED); |
| 67 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_ERROR_MAX, | 67 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncError::MAX, |
| 68 BACKGROUND_SYNC_STATUS_NOT_ALLOWED); | 68 BACKGROUND_SYNC_STATUS_NOT_ALLOWED); |
| 69 | 69 |
| 70 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_NETWORK_STATE_ANY, | 70 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncNetworkState::ANY, |
| 71 SyncNetworkState::NETWORK_STATE_ANY); | 71 SyncNetworkState::NETWORK_STATE_ANY); |
| 72 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_NETWORK_STATE_AVOID_CELLULAR, | 72 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncNetworkState::AVOID_CELLULAR, |
| 73 SyncNetworkState::NETWORK_STATE_AVOID_CELLULAR); | 73 SyncNetworkState::NETWORK_STATE_AVOID_CELLULAR); |
| 74 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_NETWORK_STATE_ONLINE, | 74 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncNetworkState::ONLINE, |
| 75 SyncNetworkState::NETWORK_STATE_ONLINE); | 75 SyncNetworkState::NETWORK_STATE_ONLINE); |
| 76 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_NETWORK_STATE_MAX, | 76 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncNetworkState::MAX, |
| 77 SyncNetworkState::NETWORK_STATE_ONLINE); | 77 SyncNetworkState::NETWORK_STATE_ONLINE); |
| 78 | 78 |
| 79 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_POWER_STATE_AUTO, | 79 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncPowerState::AUTO, |
| 80 SyncPowerState::POWER_STATE_AUTO); | 80 SyncPowerState::POWER_STATE_AUTO); |
| 81 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_POWER_STATE_AVOID_DRAINING, | 81 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncPowerState::AVOID_DRAINING, |
| 82 SyncPowerState::POWER_STATE_AVOID_DRAINING); | 82 SyncPowerState::POWER_STATE_AVOID_DRAINING); |
| 83 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_POWER_STATE_MAX, | 83 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncPowerState::MAX, |
| 84 SyncPowerState::POWER_STATE_AVOID_DRAINING); | 84 SyncPowerState::POWER_STATE_AVOID_DRAINING); |
| 85 | 85 |
| 86 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_PERIODICITY_PERIODIC, | 86 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncPeriodicity::PERIODIC, |
| 87 SyncPeriodicity::SYNC_PERIODIC); | 87 SyncPeriodicity::SYNC_PERIODIC); |
| 88 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_PERIODICITY_ONE_SHOT, | 88 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncPeriodicity::ONE_SHOT, |
| 89 SyncPeriodicity::SYNC_ONE_SHOT); | 89 SyncPeriodicity::SYNC_ONE_SHOT); |
| 90 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_PERIODICITY_MAX, | 90 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncPeriodicity::MAX, |
| 91 SyncPeriodicity::SYNC_ONE_SHOT); | 91 SyncPeriodicity::SYNC_ONE_SHOT); |
| 92 | 92 |
| 93 BackgroundSyncServiceImpl::~BackgroundSyncServiceImpl() { | 93 BackgroundSyncServiceImpl::~BackgroundSyncServiceImpl() { |
| 94 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 94 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 95 DCHECK(background_sync_context_->background_sync_manager()); | 95 DCHECK(background_sync_context_->background_sync_manager()); |
| 96 } | 96 } |
| 97 | 97 |
| 98 BackgroundSyncServiceImpl::BackgroundSyncServiceImpl( | 98 BackgroundSyncServiceImpl::BackgroundSyncServiceImpl( |
| 99 BackgroundSyncContextImpl* background_sync_context, | 99 BackgroundSyncContextImpl* background_sync_context, |
| 100 mojo::InterfaceRequest<BackgroundSyncService> request) | 100 mojo::InterfaceRequest<BackgroundSyncService> request) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 134 |
| 135 void BackgroundSyncServiceImpl::Unregister( | 135 void BackgroundSyncServiceImpl::Unregister( |
| 136 BackgroundSyncRegistrationHandle::HandleId handle_id, | 136 BackgroundSyncRegistrationHandle::HandleId handle_id, |
| 137 int64_t sw_registration_id, | 137 int64_t sw_registration_id, |
| 138 const UnregisterCallback& callback) { | 138 const UnregisterCallback& callback) { |
| 139 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 139 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 140 | 140 |
| 141 BackgroundSyncRegistrationHandle* registration = | 141 BackgroundSyncRegistrationHandle* registration = |
| 142 active_handles_.Lookup(handle_id); | 142 active_handles_.Lookup(handle_id); |
| 143 if (!registration) { | 143 if (!registration) { |
| 144 callback.Run(BACKGROUND_SYNC_ERROR_NOT_ALLOWED); | 144 callback.Run(BackgroundSyncError::NOT_ALLOWED); |
| 145 return; | 145 return; |
| 146 } | 146 } |
| 147 | 147 |
| 148 registration->Unregister( | 148 registration->Unregister( |
| 149 sw_registration_id, | 149 sw_registration_id, |
| 150 base::Bind(&BackgroundSyncServiceImpl::OnUnregisterResult, | 150 base::Bind(&BackgroundSyncServiceImpl::OnUnregisterResult, |
| 151 weak_ptr_factory_.GetWeakPtr(), callback)); | 151 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void BackgroundSyncServiceImpl::GetRegistration( | 154 void BackgroundSyncServiceImpl::GetRegistration( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 182 | 182 |
| 183 void BackgroundSyncServiceImpl::GetPermissionStatus( | 183 void BackgroundSyncServiceImpl::GetPermissionStatus( |
| 184 BackgroundSyncPeriodicity periodicity, | 184 BackgroundSyncPeriodicity periodicity, |
| 185 int64_t sw_registration_id, | 185 int64_t sw_registration_id, |
| 186 const GetPermissionStatusCallback& callback) { | 186 const GetPermissionStatusCallback& callback) { |
| 187 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 187 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 188 | 188 |
| 189 // TODO(iclelland): Implement a real policy. This is a stub implementation. | 189 // TODO(iclelland): Implement a real policy. This is a stub implementation. |
| 190 // OneShot: crbug.com/482091 | 190 // OneShot: crbug.com/482091 |
| 191 // Periodic: crbug.com/482093 | 191 // Periodic: crbug.com/482093 |
| 192 callback.Run(BACKGROUND_SYNC_ERROR_NONE, PERMISSION_STATUS_GRANTED); | 192 callback.Run(BackgroundSyncError::NONE, PermissionStatus::GRANTED); |
| 193 } | 193 } |
| 194 | 194 |
| 195 void BackgroundSyncServiceImpl::DuplicateRegistrationHandle( | 195 void BackgroundSyncServiceImpl::DuplicateRegistrationHandle( |
| 196 BackgroundSyncRegistrationHandle::HandleId handle_id, | 196 BackgroundSyncRegistrationHandle::HandleId handle_id, |
| 197 const DuplicateRegistrationHandleCallback& callback) { | 197 const DuplicateRegistrationHandleCallback& callback) { |
| 198 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 198 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 199 BackgroundSyncManager* background_sync_manager = | 199 BackgroundSyncManager* background_sync_manager = |
| 200 background_sync_context_->background_sync_manager(); | 200 background_sync_context_->background_sync_manager(); |
| 201 DCHECK(background_sync_manager); | 201 DCHECK(background_sync_manager); |
| 202 | 202 |
| 203 scoped_ptr<BackgroundSyncRegistrationHandle> registration_handle = | 203 scoped_ptr<BackgroundSyncRegistrationHandle> registration_handle = |
| 204 background_sync_manager->DuplicateRegistrationHandle(handle_id); | 204 background_sync_manager->DuplicateRegistrationHandle(handle_id); |
| 205 | 205 |
| 206 BackgroundSyncRegistrationHandle* handle_ptr = registration_handle.get(); | 206 BackgroundSyncRegistrationHandle* handle_ptr = registration_handle.get(); |
| 207 | 207 |
| 208 if (!registration_handle) { | 208 if (!registration_handle) { |
| 209 callback.Run(BACKGROUND_SYNC_ERROR_NOT_FOUND, | 209 callback.Run(BackgroundSyncError::NOT_FOUND, |
| 210 SyncRegistrationPtr(content::SyncRegistration::New())); | 210 SyncRegistrationPtr(content::SyncRegistration::New())); |
| 211 return; | 211 return; |
| 212 } | 212 } |
| 213 | 213 |
| 214 active_handles_.AddWithID(registration_handle.release(), | 214 active_handles_.AddWithID(registration_handle.release(), |
| 215 handle_ptr->handle_id()); | 215 handle_ptr->handle_id()); |
| 216 SyncRegistrationPtr mojoResult = ToMojoRegistration(*handle_ptr); | 216 SyncRegistrationPtr mojoResult = ToMojoRegistration(*handle_ptr); |
| 217 callback.Run(BACKGROUND_SYNC_ERROR_NONE, std::move(mojoResult)); | 217 callback.Run(BackgroundSyncError::NONE, std::move(mojoResult)); |
| 218 } | 218 } |
| 219 | 219 |
| 220 void BackgroundSyncServiceImpl::ReleaseRegistration( | 220 void BackgroundSyncServiceImpl::ReleaseRegistration( |
| 221 BackgroundSyncRegistrationHandle::HandleId handle_id) { | 221 BackgroundSyncRegistrationHandle::HandleId handle_id) { |
| 222 if (!active_handles_.Lookup(handle_id)) { | 222 if (!active_handles_.Lookup(handle_id)) { |
| 223 // TODO(jkarlin): Abort client. | 223 // TODO(jkarlin): Abort client. |
| 224 LOG(WARNING) << "Client attempted to release non-existing registration"; | 224 LOG(WARNING) << "Client attempted to release non-existing registration"; |
| 225 return; | 225 return; |
| 226 } | 226 } |
| 227 | 227 |
| 228 active_handles_.Remove(handle_id); | 228 active_handles_.Remove(handle_id); |
| 229 } | 229 } |
| 230 | 230 |
| 231 void BackgroundSyncServiceImpl::NotifyWhenFinished( | 231 void BackgroundSyncServiceImpl::NotifyWhenFinished( |
| 232 BackgroundSyncRegistrationHandle::HandleId handle_id, | 232 BackgroundSyncRegistrationHandle::HandleId handle_id, |
| 233 const NotifyWhenFinishedCallback& callback) { | 233 const NotifyWhenFinishedCallback& callback) { |
| 234 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 234 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 235 BackgroundSyncRegistrationHandle* registration = | 235 BackgroundSyncRegistrationHandle* registration = |
| 236 active_handles_.Lookup(handle_id); | 236 active_handles_.Lookup(handle_id); |
| 237 if (!registration) { | 237 if (!registration) { |
| 238 callback.Run(BACKGROUND_SYNC_ERROR_NOT_ALLOWED, | 238 callback.Run(BackgroundSyncError::NOT_ALLOWED, BackgroundSyncState::FAILED); |
| 239 BACKGROUND_SYNC_STATE_FAILED); | |
| 240 return; | 239 return; |
| 241 } | 240 } |
| 242 | 241 |
| 243 registration->NotifyWhenFinished( | 242 registration->NotifyWhenFinished( |
| 244 base::Bind(&BackgroundSyncServiceImpl::OnNotifyWhenFinishedResult, | 243 base::Bind(&BackgroundSyncServiceImpl::OnNotifyWhenFinishedResult, |
| 245 weak_ptr_factory_.GetWeakPtr(), callback)); | 244 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 246 } | 245 } |
| 247 | 246 |
| 248 void BackgroundSyncServiceImpl::OnRegisterResult( | 247 void BackgroundSyncServiceImpl::OnRegisterResult( |
| 249 const RegisterCallback& callback, | 248 const RegisterCallback& callback, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 | 293 |
| 295 void BackgroundSyncServiceImpl::OnNotifyWhenFinishedResult( | 294 void BackgroundSyncServiceImpl::OnNotifyWhenFinishedResult( |
| 296 const NotifyWhenFinishedCallback& callback, | 295 const NotifyWhenFinishedCallback& callback, |
| 297 BackgroundSyncStatus status, | 296 BackgroundSyncStatus status, |
| 298 BackgroundSyncState sync_state) { | 297 BackgroundSyncState sync_state) { |
| 299 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 298 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 300 callback.Run(static_cast<content::BackgroundSyncError>(status), sync_state); | 299 callback.Run(static_cast<content::BackgroundSyncError>(status), sync_state); |
| 301 } | 300 } |
| 302 | 301 |
| 303 } // namespace content | 302 } // namespace content |
| OLD | NEW |