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" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "content/browser/background_sync/background_sync_context_impl.h" | 12 #include "content/browser/background_sync/background_sync_context_impl.h" |
13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
14 | 14 |
15 namespace content { | 15 namespace content { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 // TODO(iclelland): Move these converters to mojo::TypeConverter template | 19 // TODO(iclelland): Move these converters to mojo::TypeConverter template |
20 // specializations. | 20 // specializations. |
21 | 21 |
22 BackgroundSyncRegistrationOptions ToBackgroundSyncRegistrationOptions( | 22 BackgroundSyncRegistrationOptions ToBackgroundSyncRegistrationOptions( |
23 const SyncRegistrationPtr& in) { | 23 const SyncRegistrationPtr& in) { |
24 BackgroundSyncRegistrationOptions out; | 24 BackgroundSyncRegistrationOptions out; |
25 | 25 |
26 out.tag = in->tag; | 26 out.tag = in->tag; |
27 out.min_period = in->min_period_ms; | |
28 out.network_state = static_cast<SyncNetworkState>(in->network_state); | 27 out.network_state = static_cast<SyncNetworkState>(in->network_state); |
29 out.periodicity = static_cast<SyncPeriodicity>(in->periodicity); | |
30 return out; | 28 return out; |
31 } | 29 } |
32 | 30 |
33 SyncRegistrationPtr ToMojoRegistration( | 31 SyncRegistrationPtr ToMojoRegistration( |
34 const BackgroundSyncRegistrationHandle& in) { | 32 const BackgroundSyncRegistrationHandle& in) { |
35 SyncRegistrationPtr out(content::SyncRegistration::New()); | 33 SyncRegistrationPtr out(content::SyncRegistration::New()); |
36 out->handle_id = in.handle_id(); | 34 out->handle_id = in.handle_id(); |
37 out->tag = in.options()->tag; | 35 out->tag = in.options()->tag; |
38 out->min_period_ms = in.options()->min_period; | |
39 out->periodicity = static_cast<content::BackgroundSyncPeriodicity>( | |
40 in.options()->periodicity); | |
41 out->network_state = static_cast<content::BackgroundSyncNetworkState>( | 36 out->network_state = static_cast<content::BackgroundSyncNetworkState>( |
42 in.options()->network_state); | 37 in.options()->network_state); |
43 return out; | 38 return out; |
44 } | 39 } |
45 | 40 |
46 } // namespace | 41 } // namespace |
47 | 42 |
48 #define COMPILE_ASSERT_MATCHING_ENUM(mojo_name, manager_name) \ | 43 #define COMPILE_ASSERT_MATCHING_ENUM(mojo_name, manager_name) \ |
49 static_assert(static_cast<int>(content::mojo_name) == \ | 44 static_assert(static_cast<int>(content::mojo_name) == \ |
50 static_cast<int>(content::manager_name), \ | 45 static_cast<int>(content::manager_name), \ |
(...skipping 15 matching lines...) Expand all Loading... |
66 | 61 |
67 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncNetworkState::ANY, | 62 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncNetworkState::ANY, |
68 SyncNetworkState::NETWORK_STATE_ANY); | 63 SyncNetworkState::NETWORK_STATE_ANY); |
69 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncNetworkState::AVOID_CELLULAR, | 64 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncNetworkState::AVOID_CELLULAR, |
70 SyncNetworkState::NETWORK_STATE_AVOID_CELLULAR); | 65 SyncNetworkState::NETWORK_STATE_AVOID_CELLULAR); |
71 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncNetworkState::ONLINE, | 66 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncNetworkState::ONLINE, |
72 SyncNetworkState::NETWORK_STATE_ONLINE); | 67 SyncNetworkState::NETWORK_STATE_ONLINE); |
73 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncNetworkState::MAX, | 68 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncNetworkState::MAX, |
74 SyncNetworkState::NETWORK_STATE_ONLINE); | 69 SyncNetworkState::NETWORK_STATE_ONLINE); |
75 | 70 |
76 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncPeriodicity::PERIODIC, | |
77 SyncPeriodicity::SYNC_PERIODIC); | |
78 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncPeriodicity::ONE_SHOT, | |
79 SyncPeriodicity::SYNC_ONE_SHOT); | |
80 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncPeriodicity::MAX, | |
81 SyncPeriodicity::SYNC_ONE_SHOT); | |
82 | |
83 BackgroundSyncServiceImpl::~BackgroundSyncServiceImpl() { | 71 BackgroundSyncServiceImpl::~BackgroundSyncServiceImpl() { |
84 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 72 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
85 DCHECK(background_sync_context_->background_sync_manager()); | 73 DCHECK(background_sync_context_->background_sync_manager()); |
86 } | 74 } |
87 | 75 |
88 BackgroundSyncServiceImpl::BackgroundSyncServiceImpl( | 76 BackgroundSyncServiceImpl::BackgroundSyncServiceImpl( |
89 BackgroundSyncContextImpl* background_sync_context, | 77 BackgroundSyncContextImpl* background_sync_context, |
90 mojo::InterfaceRequest<BackgroundSyncService> request) | 78 mojo::InterfaceRequest<BackgroundSyncService> request) |
91 : background_sync_context_(background_sync_context), | 79 : background_sync_context_(background_sync_context), |
92 binding_(this, std::move(request)), | 80 binding_(this, std::move(request)), |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 return; | 123 return; |
136 } | 124 } |
137 | 125 |
138 registration->Unregister( | 126 registration->Unregister( |
139 sw_registration_id, | 127 sw_registration_id, |
140 base::Bind(&BackgroundSyncServiceImpl::OnUnregisterResult, | 128 base::Bind(&BackgroundSyncServiceImpl::OnUnregisterResult, |
141 weak_ptr_factory_.GetWeakPtr(), callback)); | 129 weak_ptr_factory_.GetWeakPtr(), callback)); |
142 } | 130 } |
143 | 131 |
144 void BackgroundSyncServiceImpl::GetRegistration( | 132 void BackgroundSyncServiceImpl::GetRegistration( |
145 BackgroundSyncPeriodicity periodicity, | |
146 const mojo::String& tag, | 133 const mojo::String& tag, |
147 int64_t sw_registration_id, | 134 int64_t sw_registration_id, |
148 const GetRegistrationCallback& callback) { | 135 const GetRegistrationCallback& callback) { |
149 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 136 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
150 BackgroundSyncManager* background_sync_manager = | 137 BackgroundSyncManager* background_sync_manager = |
151 background_sync_context_->background_sync_manager(); | 138 background_sync_context_->background_sync_manager(); |
152 DCHECK(background_sync_manager); | 139 DCHECK(background_sync_manager); |
153 background_sync_manager->GetRegistration( | 140 background_sync_manager->GetRegistration( |
154 sw_registration_id, tag.get(), static_cast<SyncPeriodicity>(periodicity), | 141 sw_registration_id, tag.get(), |
155 base::Bind(&BackgroundSyncServiceImpl::OnRegisterResult, | 142 base::Bind(&BackgroundSyncServiceImpl::OnRegisterResult, |
156 weak_ptr_factory_.GetWeakPtr(), callback)); | 143 weak_ptr_factory_.GetWeakPtr(), callback)); |
157 } | 144 } |
158 | 145 |
159 void BackgroundSyncServiceImpl::GetRegistrations( | 146 void BackgroundSyncServiceImpl::GetRegistrations( |
160 BackgroundSyncPeriodicity periodicity, | |
161 int64_t sw_registration_id, | 147 int64_t sw_registration_id, |
162 const GetRegistrationsCallback& callback) { | 148 const GetRegistrationsCallback& callback) { |
163 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 149 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
164 BackgroundSyncManager* background_sync_manager = | 150 BackgroundSyncManager* background_sync_manager = |
165 background_sync_context_->background_sync_manager(); | 151 background_sync_context_->background_sync_manager(); |
166 DCHECK(background_sync_manager); | 152 DCHECK(background_sync_manager); |
167 background_sync_manager->GetRegistrations( | 153 background_sync_manager->GetRegistrations( |
168 sw_registration_id, static_cast<SyncPeriodicity>(periodicity), | 154 sw_registration_id, |
169 base::Bind(&BackgroundSyncServiceImpl::OnGetRegistrationsResult, | 155 base::Bind(&BackgroundSyncServiceImpl::OnGetRegistrationsResult, |
170 weak_ptr_factory_.GetWeakPtr(), callback)); | 156 weak_ptr_factory_.GetWeakPtr(), callback)); |
171 } | 157 } |
172 | 158 |
173 void BackgroundSyncServiceImpl::GetPermissionStatus( | 159 void BackgroundSyncServiceImpl::GetPermissionStatus( |
174 BackgroundSyncPeriodicity periodicity, | |
175 int64_t sw_registration_id, | 160 int64_t sw_registration_id, |
176 const GetPermissionStatusCallback& callback) { | 161 const GetPermissionStatusCallback& callback) { |
177 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 162 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
178 | 163 |
179 // TODO(iclelland): Implement a real policy. This is a stub implementation. | 164 // TODO(iclelland): Implement a real policy. This is a stub implementation. |
180 // OneShot: crbug.com/482091 | 165 // OneShot: crbug.com/482091 |
181 // Periodic: crbug.com/482093 | |
182 callback.Run(BackgroundSyncError::NONE, PermissionStatus::GRANTED); | 166 callback.Run(BackgroundSyncError::NONE, PermissionStatus::GRANTED); |
183 } | 167 } |
184 | 168 |
185 void BackgroundSyncServiceImpl::DuplicateRegistrationHandle( | 169 void BackgroundSyncServiceImpl::DuplicateRegistrationHandle( |
186 BackgroundSyncRegistrationHandle::HandleId handle_id, | 170 BackgroundSyncRegistrationHandle::HandleId handle_id, |
187 const DuplicateRegistrationHandleCallback& callback) { | 171 const DuplicateRegistrationHandleCallback& callback) { |
188 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 172 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
189 BackgroundSyncManager* background_sync_manager = | 173 BackgroundSyncManager* background_sync_manager = |
190 background_sync_context_->background_sync_manager(); | 174 background_sync_context_->background_sync_manager(); |
191 DCHECK(background_sync_manager); | 175 DCHECK(background_sync_manager); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 | 267 |
284 void BackgroundSyncServiceImpl::OnNotifyWhenFinishedResult( | 268 void BackgroundSyncServiceImpl::OnNotifyWhenFinishedResult( |
285 const NotifyWhenFinishedCallback& callback, | 269 const NotifyWhenFinishedCallback& callback, |
286 BackgroundSyncStatus status, | 270 BackgroundSyncStatus status, |
287 BackgroundSyncState sync_state) { | 271 BackgroundSyncState sync_state) { |
288 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 272 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
289 callback.Run(static_cast<content::BackgroundSyncError>(status), sync_state); | 273 callback.Run(static_cast<content::BackgroundSyncError>(status), sync_state); |
290 } | 274 } |
291 | 275 |
292 } // namespace content | 276 } // namespace content |
OLD | NEW |