| 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 "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 76 |
| 77 BackgroundSyncServiceImpl::BackgroundSyncServiceImpl( | 77 BackgroundSyncServiceImpl::BackgroundSyncServiceImpl( |
| 78 BackgroundSyncContext* background_sync_context, | 78 BackgroundSyncContext* background_sync_context, |
| 79 mojo::InterfaceRequest<blink::mojom::BackgroundSyncService> request) | 79 mojo::InterfaceRequest<blink::mojom::BackgroundSyncService> request) |
| 80 : background_sync_context_(background_sync_context), | 80 : background_sync_context_(background_sync_context), |
| 81 binding_(this, std::move(request)), | 81 binding_(this, std::move(request)), |
| 82 weak_ptr_factory_(this) { | 82 weak_ptr_factory_(this) { |
| 83 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 83 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 84 DCHECK(background_sync_context); | 84 DCHECK(background_sync_context); |
| 85 | 85 |
| 86 binding_.set_connection_error_handler( | 86 binding_.set_connection_error_handler(base::BindOnce( |
| 87 base::Bind(&BackgroundSyncServiceImpl::OnConnectionError, | 87 &BackgroundSyncServiceImpl::OnConnectionError, |
| 88 base::Unretained(this) /* the channel is owned by this */)); | 88 base::Unretained(this) /* the channel is owned by this */)); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void BackgroundSyncServiceImpl::OnConnectionError() { | 91 void BackgroundSyncServiceImpl::OnConnectionError() { |
| 92 background_sync_context_->ServiceHadConnectionError(this); | 92 background_sync_context_->ServiceHadConnectionError(this); |
| 93 // |this| is now deleted. | 93 // |this| is now deleted. |
| 94 } | 94 } |
| 95 | 95 |
| 96 void BackgroundSyncServiceImpl::Register( | 96 void BackgroundSyncServiceImpl::Register( |
| 97 blink::mojom::SyncRegistrationPtr options, | 97 blink::mojom::SyncRegistrationPtr options, |
| 98 int64_t sw_registration_id, | 98 int64_t sw_registration_id, |
| 99 RegisterCallback callback) { | 99 RegisterCallback callback) { |
| 100 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 100 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 101 | 101 |
| 102 BackgroundSyncRegistrationOptions manager_options = | 102 BackgroundSyncRegistrationOptions manager_options = |
| 103 ToBackgroundSyncRegistrationOptions(options); | 103 ToBackgroundSyncRegistrationOptions(options); |
| 104 | 104 |
| 105 BackgroundSyncManager* background_sync_manager = | 105 BackgroundSyncManager* background_sync_manager = |
| 106 background_sync_context_->background_sync_manager(); | 106 background_sync_context_->background_sync_manager(); |
| 107 DCHECK(background_sync_manager); | 107 DCHECK(background_sync_manager); |
| 108 background_sync_manager->Register( | 108 background_sync_manager->Register( |
| 109 sw_registration_id, manager_options, | 109 sw_registration_id, manager_options, |
| 110 base::Bind(&BackgroundSyncServiceImpl::OnRegisterResult, | 110 base::BindOnce(&BackgroundSyncServiceImpl::OnRegisterResult, |
| 111 weak_ptr_factory_.GetWeakPtr(), base::Passed(&callback))); | 111 weak_ptr_factory_.GetWeakPtr(), std::move(callback))); |
| 112 } | 112 } |
| 113 | 113 |
| 114 void BackgroundSyncServiceImpl::GetRegistrations( | 114 void BackgroundSyncServiceImpl::GetRegistrations( |
| 115 int64_t sw_registration_id, | 115 int64_t sw_registration_id, |
| 116 GetRegistrationsCallback callback) { | 116 GetRegistrationsCallback callback) { |
| 117 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 117 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 118 BackgroundSyncManager* background_sync_manager = | 118 BackgroundSyncManager* background_sync_manager = |
| 119 background_sync_context_->background_sync_manager(); | 119 background_sync_context_->background_sync_manager(); |
| 120 DCHECK(background_sync_manager); | 120 DCHECK(background_sync_manager); |
| 121 background_sync_manager->GetRegistrations( | 121 background_sync_manager->GetRegistrations( |
| 122 sw_registration_id, | 122 sw_registration_id, |
| 123 base::Bind(&BackgroundSyncServiceImpl::OnGetRegistrationsResult, | 123 base::BindOnce(&BackgroundSyncServiceImpl::OnGetRegistrationsResult, |
| 124 weak_ptr_factory_.GetWeakPtr(), base::Passed(&callback))); | 124 weak_ptr_factory_.GetWeakPtr(), std::move(callback))); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void BackgroundSyncServiceImpl::OnRegisterResult( | 127 void BackgroundSyncServiceImpl::OnRegisterResult( |
| 128 RegisterCallback callback, | 128 RegisterCallback callback, |
| 129 BackgroundSyncStatus status, | 129 BackgroundSyncStatus status, |
| 130 std::unique_ptr<BackgroundSyncRegistration> result) { | 130 std::unique_ptr<BackgroundSyncRegistration> result) { |
| 131 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 131 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 132 | 132 |
| 133 if (status != BACKGROUND_SYNC_STATUS_OK) { | 133 if (status != BACKGROUND_SYNC_STATUS_OK) { |
| 134 std::move(callback).Run( | 134 std::move(callback).Run( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 155 std::vector<blink::mojom::SyncRegistrationPtr> mojo_registrations; | 155 std::vector<blink::mojom::SyncRegistrationPtr> mojo_registrations; |
| 156 for (const auto& registration : result_registrations) | 156 for (const auto& registration : result_registrations) |
| 157 mojo_registrations.push_back(ToMojoRegistration(*registration)); | 157 mojo_registrations.push_back(ToMojoRegistration(*registration)); |
| 158 | 158 |
| 159 std::move(callback).Run( | 159 std::move(callback).Run( |
| 160 static_cast<blink::mojom::BackgroundSyncError>(status), | 160 static_cast<blink::mojom::BackgroundSyncError>(status), |
| 161 std::move(mojo_registrations)); | 161 std::move(mojo_registrations)); |
| 162 } | 162 } |
| 163 | 163 |
| 164 } // namespace content | 164 } // namespace content |
| OLD | NEW |