| 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 "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
| 8 #include "content/browser/background_sync/background_sync_context_impl.h" | 8 #include "content/browser/background_sync/background_sync_context_impl.h" |
| 9 #include "content/browser/background_sync/background_sync_registration.h" | 9 #include "content/browser/background_sync/background_sync_registration.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_POWER_STATE_MAX, | 79 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_POWER_STATE_MAX, |
| 80 SyncPowerState::POWER_STATE_AVOID_DRAINING); | 80 SyncPowerState::POWER_STATE_AVOID_DRAINING); |
| 81 | 81 |
| 82 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_PERIODICITY_PERIODIC, | 82 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_PERIODICITY_PERIODIC, |
| 83 SyncPeriodicity::SYNC_PERIODIC); | 83 SyncPeriodicity::SYNC_PERIODIC); |
| 84 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_PERIODICITY_ONE_SHOT, | 84 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_PERIODICITY_ONE_SHOT, |
| 85 SyncPeriodicity::SYNC_ONE_SHOT); | 85 SyncPeriodicity::SYNC_ONE_SHOT); |
| 86 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_PERIODICITY_MAX, | 86 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_PERIODICITY_MAX, |
| 87 SyncPeriodicity::SYNC_ONE_SHOT); | 87 SyncPeriodicity::SYNC_ONE_SHOT); |
| 88 | 88 |
| 89 // static | |
| 90 void BackgroundSyncServiceImpl::Create( | |
| 91 const scoped_refptr<BackgroundSyncContextImpl>& background_sync_context, | |
| 92 mojo::InterfaceRequest<BackgroundSyncService> request) { | |
| 93 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 94 BrowserThread::PostTask( | |
| 95 BrowserThread::IO, FROM_HERE, | |
| 96 base::Bind(&BackgroundSyncServiceImpl::CreateOnIOThread, | |
| 97 background_sync_context, base::Passed(&request))); | |
| 98 } | |
| 99 | |
| 100 BackgroundSyncServiceImpl::~BackgroundSyncServiceImpl() { | 89 BackgroundSyncServiceImpl::~BackgroundSyncServiceImpl() { |
| 101 // Should always be destroyed on the IO thread, but can't check that with | |
| 102 // DCHECK_CURRENTLY_ON because this class could be destroyed during thread | |
| 103 // shutdown, at which point that check doesn't work. | |
| 104 } | |
| 105 | |
| 106 // static | |
| 107 void BackgroundSyncServiceImpl::CreateOnIOThread( | |
| 108 const scoped_refptr<BackgroundSyncContextImpl>& background_sync_context, | |
| 109 mojo::InterfaceRequest<BackgroundSyncService> request) { | |
| 110 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 90 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 111 new BackgroundSyncServiceImpl(background_sync_context, request.Pass()); | |
| 112 } | 91 } |
| 113 | 92 |
| 114 BackgroundSyncServiceImpl::BackgroundSyncServiceImpl( | 93 BackgroundSyncServiceImpl::BackgroundSyncServiceImpl( |
| 115 const scoped_refptr<BackgroundSyncContextImpl>& background_sync_context, | 94 const scoped_refptr<BackgroundSyncContextImpl>& background_sync_context, |
| 116 mojo::InterfaceRequest<BackgroundSyncService> request) | 95 mojo::InterfaceRequest<BackgroundSyncService> request) |
| 117 : background_sync_context_(background_sync_context), | 96 : background_sync_context_(background_sync_context), |
| 118 binding_(this, request.Pass()), | 97 binding_(this, request.Pass()), |
| 119 weak_ptr_factory_(this) { | 98 weak_ptr_factory_(this) { |
| 120 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 99 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 100 |
| 101 binding_.set_connection_error_handler( |
| 102 base::Bind(&BackgroundSyncServiceImpl::OnConnectionError, |
| 103 base::Unretained(this) /* the channel is owned by this */)); |
| 104 } |
| 105 |
| 106 void BackgroundSyncServiceImpl::OnConnectionError() { |
| 107 background_sync_context_->ServiceHadConnectionError(this); |
| 108 // |this| is now deleted. |
| 121 } | 109 } |
| 122 | 110 |
| 123 void BackgroundSyncServiceImpl::Register(content::SyncRegistrationPtr options, | 111 void BackgroundSyncServiceImpl::Register(content::SyncRegistrationPtr options, |
| 124 int64_t sw_registration_id, | 112 int64_t sw_registration_id, |
| 125 const RegisterCallback& callback) { | 113 const RegisterCallback& callback) { |
| 126 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 114 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 127 | 115 |
| 128 BackgroundSyncRegistrationOptions mgr_options = | 116 BackgroundSyncRegistrationOptions mgr_options = |
| 129 ToBackgroundSyncRegistrationOptions(options); | 117 ToBackgroundSyncRegistrationOptions(options); |
| 130 | 118 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 const std::vector<BackgroundSyncRegistration>& result_registrations) { | 205 const std::vector<BackgroundSyncRegistration>& result_registrations) { |
| 218 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 206 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 219 mojo::Array<content::SyncRegistrationPtr> mojo_registrations(0); | 207 mojo::Array<content::SyncRegistrationPtr> mojo_registrations(0); |
| 220 for (const auto& registration : result_registrations) | 208 for (const auto& registration : result_registrations) |
| 221 mojo_registrations.push_back(ToMojoRegistration(registration)); | 209 mojo_registrations.push_back(ToMojoRegistration(registration)); |
| 222 callback.Run(static_cast<content::BackgroundSyncError>(status), | 210 callback.Run(static_cast<content::BackgroundSyncError>(status), |
| 223 mojo_registrations.Pass()); | 211 mojo_registrations.Pass()); |
| 224 } | 212 } |
| 225 | 213 |
| 226 } // namespace content | 214 } // namespace content |
| OLD | NEW |