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_manager.h" | 5 #include "content/browser/background_sync/background_sync_manager.h" |
6 | 6 |
7 #include "base/barrier_closure.h" | 7 #include "base/barrier_closure.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
11 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
12 #include "content/browser/background_sync/background_sync_metrics.h" | 12 #include "content/browser/background_sync/background_sync_metrics.h" |
13 #include "content/browser/background_sync/background_sync_network_observer.h" | 13 #include "content/browser/background_sync/background_sync_network_observer.h" |
14 #include "content/browser/background_sync/background_sync_power_observer.h" | 14 #include "content/browser/background_sync/background_sync_power_observer.h" |
15 #include "content/browser/background_sync/background_sync_registration_handle.h" | 15 #include "content/browser/background_sync/background_sync_registration_handle.h" |
16 #include "content/browser/background_sync/background_sync_registration_options.h
" | 16 #include "content/browser/background_sync/background_sync_registration_options.h
" |
17 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 17 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
18 #include "content/browser/service_worker/service_worker_storage.h" | 18 #include "content/browser/service_worker/service_worker_storage.h" |
19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
20 | 20 |
21 #if defined(OS_ANDROID) | 21 #if defined(OS_ANDROID) |
22 #include "content/browser/android/background_sync_launcher_android.h" | 22 #include "content/browser/android/background_sync_launcher_android.h" |
| 23 #include "content/browser/android/background_sync_network_observer_android.h" |
23 #endif | 24 #endif |
24 | 25 |
25 namespace content { | 26 namespace content { |
26 | 27 |
27 class BackgroundSyncManager::RefCountedRegistration | 28 class BackgroundSyncManager::RefCountedRegistration |
28 : public base::RefCounted<RefCountedRegistration> { | 29 : public base::RefCounted<RefCountedRegistration> { |
29 public: | 30 public: |
30 BackgroundSyncRegistration* value() { return ®istration_; } | 31 BackgroundSyncRegistration* value() { return ®istration_; } |
31 const BackgroundSyncRegistration* value() const { return ®istration_; } | 32 const BackgroundSyncRegistration* value() const { return ®istration_; } |
32 | 33 |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 | 207 |
207 BackgroundSyncManager::BackgroundSyncManager( | 208 BackgroundSyncManager::BackgroundSyncManager( |
208 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context) | 209 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context) |
209 : service_worker_context_(service_worker_context), | 210 : service_worker_context_(service_worker_context), |
210 disabled_(false), | 211 disabled_(false), |
211 weak_ptr_factory_(this) { | 212 weak_ptr_factory_(this) { |
212 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 213 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
213 | 214 |
214 service_worker_context_->AddObserver(this); | 215 service_worker_context_->AddObserver(this); |
215 | 216 |
| 217 #if defined(OS_ANDROID) |
| 218 network_observer_.reset(new BackgroundSyncNetworkObserverAndroid( |
| 219 base::Bind(&BackgroundSyncManager::OnNetworkChanged, |
| 220 weak_ptr_factory_.GetWeakPtr()))); |
| 221 #else |
216 network_observer_.reset(new BackgroundSyncNetworkObserver( | 222 network_observer_.reset(new BackgroundSyncNetworkObserver( |
217 base::Bind(&BackgroundSyncManager::OnNetworkChanged, | 223 base::Bind(&BackgroundSyncManager::OnNetworkChanged, |
218 weak_ptr_factory_.GetWeakPtr()))); | 224 weak_ptr_factory_.GetWeakPtr()))); |
| 225 #endif |
219 power_observer_.reset(new BackgroundSyncPowerObserver(base::Bind( | 226 power_observer_.reset(new BackgroundSyncPowerObserver(base::Bind( |
220 &BackgroundSyncManager::OnPowerChanged, weak_ptr_factory_.GetWeakPtr()))); | 227 &BackgroundSyncManager::OnPowerChanged, weak_ptr_factory_.GetWeakPtr()))); |
221 } | 228 } |
222 | 229 |
223 void BackgroundSyncManager::Init() { | 230 void BackgroundSyncManager::Init() { |
224 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 231 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
225 DCHECK(!op_scheduler_.ScheduledOperations()); | 232 DCHECK(!op_scheduler_.ScheduledOperations()); |
226 DCHECK(!disabled_); | 233 DCHECK(!disabled_); |
227 | 234 |
228 op_scheduler_.ScheduleOperation(base::Bind(&BackgroundSyncManager::InitImpl, | 235 op_scheduler_.ScheduleOperation(base::Bind(&BackgroundSyncManager::InitImpl, |
(...skipping 963 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1192 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) { | 1199 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) { |
1193 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1200 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1194 | 1201 |
1195 return base::Bind( | 1202 return base::Bind( |
1196 &BackgroundSyncManager::CompleteOperationCallback<StatusCallback, | 1203 &BackgroundSyncManager::CompleteOperationCallback<StatusCallback, |
1197 BackgroundSyncStatus>, | 1204 BackgroundSyncStatus>, |
1198 weak_ptr_factory_.GetWeakPtr(), callback); | 1205 weak_ptr_factory_.GetWeakPtr(), callback); |
1199 } | 1206 } |
1200 | 1207 |
1201 } // namespace content | 1208 } // namespace content |
OLD | NEW |