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; | 27 out.min_period = in->min_period_ms; |
28 out.power_state = static_cast<SyncPowerState>(in->power_state); | |
29 out.network_state = static_cast<SyncNetworkState>(in->network_state); | 28 out.network_state = static_cast<SyncNetworkState>(in->network_state); |
30 out.periodicity = static_cast<SyncPeriodicity>(in->periodicity); | 29 out.periodicity = static_cast<SyncPeriodicity>(in->periodicity); |
31 return out; | 30 return out; |
32 } | 31 } |
33 | 32 |
34 SyncRegistrationPtr ToMojoRegistration( | 33 SyncRegistrationPtr ToMojoRegistration( |
35 const BackgroundSyncRegistrationHandle& in) { | 34 const BackgroundSyncRegistrationHandle& in) { |
36 SyncRegistrationPtr out(content::SyncRegistration::New()); | 35 SyncRegistrationPtr out(content::SyncRegistration::New()); |
37 out->handle_id = in.handle_id(); | 36 out->handle_id = in.handle_id(); |
38 out->tag = in.options()->tag; | 37 out->tag = in.options()->tag; |
39 out->min_period_ms = in.options()->min_period; | 38 out->min_period_ms = in.options()->min_period; |
40 out->periodicity = static_cast<content::BackgroundSyncPeriodicity>( | 39 out->periodicity = static_cast<content::BackgroundSyncPeriodicity>( |
41 in.options()->periodicity); | 40 in.options()->periodicity); |
42 out->power_state = | |
43 static_cast<content::BackgroundSyncPowerState>(in.options()->power_state); | |
44 out->network_state = static_cast<content::BackgroundSyncNetworkState>( | 41 out->network_state = static_cast<content::BackgroundSyncNetworkState>( |
45 in.options()->network_state); | 42 in.options()->network_state); |
46 return out; | 43 return out; |
47 } | 44 } |
48 | 45 |
49 } // namespace | 46 } // namespace |
50 | 47 |
51 #define COMPILE_ASSERT_MATCHING_ENUM(mojo_name, manager_name) \ | 48 #define COMPILE_ASSERT_MATCHING_ENUM(mojo_name, manager_name) \ |
52 static_assert(static_cast<int>(content::mojo_name) == \ | 49 static_assert(static_cast<int>(content::mojo_name) == \ |
53 static_cast<int>(content::manager_name), \ | 50 static_cast<int>(content::manager_name), \ |
(...skipping 15 matching lines...) Expand all Loading... |
69 | 66 |
70 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncNetworkState::ANY, | 67 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncNetworkState::ANY, |
71 SyncNetworkState::NETWORK_STATE_ANY); | 68 SyncNetworkState::NETWORK_STATE_ANY); |
72 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncNetworkState::AVOID_CELLULAR, | 69 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncNetworkState::AVOID_CELLULAR, |
73 SyncNetworkState::NETWORK_STATE_AVOID_CELLULAR); | 70 SyncNetworkState::NETWORK_STATE_AVOID_CELLULAR); |
74 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncNetworkState::ONLINE, | 71 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncNetworkState::ONLINE, |
75 SyncNetworkState::NETWORK_STATE_ONLINE); | 72 SyncNetworkState::NETWORK_STATE_ONLINE); |
76 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncNetworkState::MAX, | 73 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncNetworkState::MAX, |
77 SyncNetworkState::NETWORK_STATE_ONLINE); | 74 SyncNetworkState::NETWORK_STATE_ONLINE); |
78 | 75 |
79 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncPowerState::AUTO, | |
80 SyncPowerState::POWER_STATE_AUTO); | |
81 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncPowerState::AVOID_DRAINING, | |
82 SyncPowerState::POWER_STATE_AVOID_DRAINING); | |
83 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncPowerState::MAX, | |
84 SyncPowerState::POWER_STATE_AVOID_DRAINING); | |
85 | |
86 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncPeriodicity::PERIODIC, | 76 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncPeriodicity::PERIODIC, |
87 SyncPeriodicity::SYNC_PERIODIC); | 77 SyncPeriodicity::SYNC_PERIODIC); |
88 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncPeriodicity::ONE_SHOT, | 78 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncPeriodicity::ONE_SHOT, |
89 SyncPeriodicity::SYNC_ONE_SHOT); | 79 SyncPeriodicity::SYNC_ONE_SHOT); |
90 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncPeriodicity::MAX, | 80 COMPILE_ASSERT_MATCHING_ENUM(BackgroundSyncPeriodicity::MAX, |
91 SyncPeriodicity::SYNC_ONE_SHOT); | 81 SyncPeriodicity::SYNC_ONE_SHOT); |
92 | 82 |
93 BackgroundSyncServiceImpl::~BackgroundSyncServiceImpl() { | 83 BackgroundSyncServiceImpl::~BackgroundSyncServiceImpl() { |
94 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 84 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
95 DCHECK(background_sync_context_->background_sync_manager()); | 85 DCHECK(background_sync_context_->background_sync_manager()); |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 | 283 |
294 void BackgroundSyncServiceImpl::OnNotifyWhenFinishedResult( | 284 void BackgroundSyncServiceImpl::OnNotifyWhenFinishedResult( |
295 const NotifyWhenFinishedCallback& callback, | 285 const NotifyWhenFinishedCallback& callback, |
296 BackgroundSyncStatus status, | 286 BackgroundSyncStatus status, |
297 BackgroundSyncState sync_state) { | 287 BackgroundSyncState sync_state) { |
298 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 288 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
299 callback.Run(static_cast<content::BackgroundSyncError>(status), sync_state); | 289 callback.Run(static_cast<content::BackgroundSyncError>(status), sync_state); |
300 } | 290 } |
301 | 291 |
302 } // namespace content | 292 } // namespace content |
OLD | NEW |