| 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" |
| 11 #include "content/browser/background_sync/background_sync_context.h" | 11 #include "content/browser/background_sync/background_sync_context.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // TODO(iclelland): Move these converters to mojo::TypeConverter template | 18 // TODO(iclelland): Move these converters to mojo::TypeConverter template |
| 19 // specializations. | 19 // specializations. |
| 20 | 20 |
| 21 BackgroundSyncRegistrationOptions ToBackgroundSyncRegistrationOptions( | 21 BackgroundSyncRegistrationOptions ToBackgroundSyncRegistrationOptions( |
| 22 const mojom::SyncRegistrationPtr& in) { | 22 const blink::mojom::SyncRegistrationPtr& in) { |
| 23 BackgroundSyncRegistrationOptions out; | 23 BackgroundSyncRegistrationOptions out; |
| 24 | 24 |
| 25 out.tag = in->tag; | 25 out.tag = in->tag; |
| 26 out.network_state = static_cast<SyncNetworkState>(in->network_state); | 26 out.network_state = static_cast<SyncNetworkState>(in->network_state); |
| 27 return out; | 27 return out; |
| 28 } | 28 } |
| 29 | 29 |
| 30 mojom::SyncRegistrationPtr ToMojoRegistration( | 30 blink::mojom::SyncRegistrationPtr ToMojoRegistration( |
| 31 const BackgroundSyncRegistration& in) { | 31 const BackgroundSyncRegistration& in) { |
| 32 mojom::SyncRegistrationPtr out(content::mojom::SyncRegistration::New()); | 32 blink::mojom::SyncRegistrationPtr out(blink::mojom::SyncRegistration::New()); |
| 33 out->id = in.id(); | 33 out->id = in.id(); |
| 34 out->tag = in.options()->tag; | 34 out->tag = in.options()->tag; |
| 35 out->network_state = static_cast<content::mojom::BackgroundSyncNetworkState>( | 35 out->network_state = static_cast<blink::mojom::BackgroundSyncNetworkState>( |
| 36 in.options()->network_state); | 36 in.options()->network_state); |
| 37 return out; | 37 return out; |
| 38 } | 38 } |
| 39 | 39 |
| 40 } // namespace | 40 } // namespace |
| 41 | 41 |
| 42 #define COMPILE_ASSERT_MATCHING_ENUM(mojo_name, manager_name) \ | 42 #define COMPILE_ASSERT_MATCHING_ENUM(mojo_name, manager_name) \ |
| 43 static_assert(static_cast<int>(content::mojo_name) == \ | 43 static_assert(static_cast<int>(blink::mojo_name) == \ |
| 44 static_cast<int>(content::manager_name), \ | 44 static_cast<int>(content::manager_name), \ |
| 45 "mojo and manager enums must match") | 45 "mojo and manager enums must match") |
| 46 | 46 |
| 47 // TODO(iclelland): Move these tests somewhere else | 47 // TODO(iclelland): Move these tests somewhere else |
| 48 COMPILE_ASSERT_MATCHING_ENUM(mojom::BackgroundSyncError::NONE, | 48 COMPILE_ASSERT_MATCHING_ENUM(mojom::BackgroundSyncError::NONE, |
| 49 BACKGROUND_SYNC_STATUS_OK); | 49 BACKGROUND_SYNC_STATUS_OK); |
| 50 COMPILE_ASSERT_MATCHING_ENUM(mojom::BackgroundSyncError::STORAGE, | 50 COMPILE_ASSERT_MATCHING_ENUM(mojom::BackgroundSyncError::STORAGE, |
| 51 BACKGROUND_SYNC_STATUS_STORAGE_ERROR); | 51 BACKGROUND_SYNC_STATUS_STORAGE_ERROR); |
| 52 COMPILE_ASSERT_MATCHING_ENUM(mojom::BackgroundSyncError::NOT_FOUND, | 52 COMPILE_ASSERT_MATCHING_ENUM(mojom::BackgroundSyncError::NOT_FOUND, |
| 53 BACKGROUND_SYNC_STATUS_NOT_FOUND); | 53 BACKGROUND_SYNC_STATUS_NOT_FOUND); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 69 COMPILE_ASSERT_MATCHING_ENUM(mojom::BackgroundSyncNetworkState::MAX, | 69 COMPILE_ASSERT_MATCHING_ENUM(mojom::BackgroundSyncNetworkState::MAX, |
| 70 SyncNetworkState::NETWORK_STATE_ONLINE); | 70 SyncNetworkState::NETWORK_STATE_ONLINE); |
| 71 | 71 |
| 72 BackgroundSyncServiceImpl::~BackgroundSyncServiceImpl() { | 72 BackgroundSyncServiceImpl::~BackgroundSyncServiceImpl() { |
| 73 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 73 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 74 DCHECK(background_sync_context_->background_sync_manager()); | 74 DCHECK(background_sync_context_->background_sync_manager()); |
| 75 } | 75 } |
| 76 | 76 |
| 77 BackgroundSyncServiceImpl::BackgroundSyncServiceImpl( | 77 BackgroundSyncServiceImpl::BackgroundSyncServiceImpl( |
| 78 BackgroundSyncContext* background_sync_context, | 78 BackgroundSyncContext* background_sync_context, |
| 79 mojo::InterfaceRequest<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( |
| 87 base::Bind(&BackgroundSyncServiceImpl::OnConnectionError, | 87 base::Bind(&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 content::mojom::SyncRegistrationPtr options, | 97 blink::mojom::SyncRegistrationPtr options, |
| 98 int64_t sw_registration_id, | 98 int64_t sw_registration_id, |
| 99 const RegisterCallback& callback) { | 99 const 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); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 124 weak_ptr_factory_.GetWeakPtr(), callback)); | 124 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void BackgroundSyncServiceImpl::OnRegisterResult( | 127 void BackgroundSyncServiceImpl::OnRegisterResult( |
| 128 const RegisterCallback& callback, | 128 const 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 callback.Run( | 134 callback.Run(static_cast<blink::mojom::BackgroundSyncError>(status), |
| 135 static_cast<content::mojom::BackgroundSyncError>(status), | 135 blink::mojom::SyncRegistrationPtr( |
| 136 mojom::SyncRegistrationPtr(content::mojom::SyncRegistration::New())); | 136 blink::mojom::SyncRegistration::New())); |
| 137 return; | 137 return; |
| 138 } | 138 } |
| 139 | 139 |
| 140 DCHECK(result); | 140 DCHECK(result); |
| 141 mojom::SyncRegistrationPtr mojoResult = ToMojoRegistration(*result); | 141 blink::mojom::SyncRegistrationPtr mojoResult = ToMojoRegistration(*result); |
| 142 callback.Run(static_cast<content::mojom::BackgroundSyncError>(status), | 142 callback.Run(static_cast<blink::mojom::BackgroundSyncError>(status), |
| 143 std::move(mojoResult)); | 143 std::move(mojoResult)); |
| 144 } | 144 } |
| 145 | 145 |
| 146 void BackgroundSyncServiceImpl::OnGetRegistrationsResult( | 146 void BackgroundSyncServiceImpl::OnGetRegistrationsResult( |
| 147 const GetRegistrationsCallback& callback, | 147 const GetRegistrationsCallback& callback, |
| 148 BackgroundSyncStatus status, | 148 BackgroundSyncStatus status, |
| 149 std::unique_ptr<ScopedVector<BackgroundSyncRegistration>> | 149 std::unique_ptr<ScopedVector<BackgroundSyncRegistration>> |
| 150 result_registrations) { | 150 result_registrations) { |
| 151 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 151 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 152 DCHECK(result_registrations); | 152 DCHECK(result_registrations); |
| 153 | 153 |
| 154 mojo::Array<content::mojom::SyncRegistrationPtr> mojo_registrations; | 154 mojo::Array<blink::mojom::SyncRegistrationPtr> mojo_registrations; |
| 155 for (const BackgroundSyncRegistration* registration : *result_registrations) | 155 for (const BackgroundSyncRegistration* registration : *result_registrations) |
| 156 mojo_registrations.push_back(ToMojoRegistration(*registration)); | 156 mojo_registrations.push_back(ToMojoRegistration(*registration)); |
| 157 | 157 |
| 158 callback.Run(static_cast<content::mojom::BackgroundSyncError>(status), | 158 callback.Run(static_cast<blink::mojom::BackgroundSyncError>(status), |
| 159 std::move(mojo_registrations)); | 159 std::move(mojo_registrations)); |
| 160 } | 160 } |
| 161 | 161 |
| 162 } // namespace content | 162 } // namespace content |
| OLD | NEW |