| 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" | |
| 24 #endif | 23 #endif |
| 25 | 24 |
| 26 namespace content { | 25 namespace content { |
| 27 | 26 |
| 28 class BackgroundSyncManager::RefCountedRegistration | 27 class BackgroundSyncManager::RefCountedRegistration |
| 29 : public base::RefCounted<RefCountedRegistration> { | 28 : public base::RefCounted<RefCountedRegistration> { |
| 30 public: | 29 public: |
| 31 BackgroundSyncRegistration* value() { return ®istration_; } | 30 BackgroundSyncRegistration* value() { return ®istration_; } |
| 32 const BackgroundSyncRegistration* value() const { return ®istration_; } | 31 const BackgroundSyncRegistration* value() const { return ®istration_; } |
| 33 | 32 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 | 206 |
| 208 BackgroundSyncManager::BackgroundSyncManager( | 207 BackgroundSyncManager::BackgroundSyncManager( |
| 209 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context) | 208 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context) |
| 210 : service_worker_context_(service_worker_context), | 209 : service_worker_context_(service_worker_context), |
| 211 disabled_(false), | 210 disabled_(false), |
| 212 weak_ptr_factory_(this) { | 211 weak_ptr_factory_(this) { |
| 213 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 212 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 214 | 213 |
| 215 service_worker_context_->AddObserver(this); | 214 service_worker_context_->AddObserver(this); |
| 216 | 215 |
| 217 #if defined(OS_ANDROID) | |
| 218 network_observer_.reset(new BackgroundSyncNetworkObserverAndroid( | |
| 219 base::Bind(&BackgroundSyncManager::OnNetworkChanged, | |
| 220 weak_ptr_factory_.GetWeakPtr()))); | |
| 221 #else | |
| 222 network_observer_.reset(new BackgroundSyncNetworkObserver( | 216 network_observer_.reset(new BackgroundSyncNetworkObserver( |
| 223 base::Bind(&BackgroundSyncManager::OnNetworkChanged, | 217 base::Bind(&BackgroundSyncManager::OnNetworkChanged, |
| 224 weak_ptr_factory_.GetWeakPtr()))); | 218 weak_ptr_factory_.GetWeakPtr()))); |
| 225 #endif | |
| 226 power_observer_.reset(new BackgroundSyncPowerObserver(base::Bind( | 219 power_observer_.reset(new BackgroundSyncPowerObserver(base::Bind( |
| 227 &BackgroundSyncManager::OnPowerChanged, weak_ptr_factory_.GetWeakPtr()))); | 220 &BackgroundSyncManager::OnPowerChanged, weak_ptr_factory_.GetWeakPtr()))); |
| 228 } | 221 } |
| 229 | 222 |
| 230 void BackgroundSyncManager::Init() { | 223 void BackgroundSyncManager::Init() { |
| 231 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 224 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 232 DCHECK(!op_scheduler_.ScheduledOperations()); | 225 DCHECK(!op_scheduler_.ScheduledOperations()); |
| 233 DCHECK(!disabled_); | 226 DCHECK(!disabled_); |
| 234 | 227 |
| 235 op_scheduler_.ScheduleOperation(base::Bind(&BackgroundSyncManager::InitImpl, | 228 op_scheduler_.ScheduleOperation(base::Bind(&BackgroundSyncManager::InitImpl, |
| (...skipping 1061 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1297 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) { | 1290 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) { |
| 1298 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1291 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1299 | 1292 |
| 1300 return base::Bind( | 1293 return base::Bind( |
| 1301 &BackgroundSyncManager::CompleteOperationCallback<StatusCallback, | 1294 &BackgroundSyncManager::CompleteOperationCallback<StatusCallback, |
| 1302 BackgroundSyncStatus>, | 1295 BackgroundSyncStatus>, |
| 1303 weak_ptr_factory_.GetWeakPtr(), callback); | 1296 weak_ptr_factory_.GetWeakPtr(), callback); |
| 1304 } | 1297 } |
| 1305 | 1298 |
| 1306 } // namespace content | 1299 } // namespace content |
| OLD | NEW |