| 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_options.h
" | 15 #include "content/browser/background_sync/background_sync_registration_options.h
" |
| 16 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 16 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 17 #include "content/browser/service_worker/service_worker_storage.h" | 17 #include "content/browser/service_worker/service_worker_storage.h" |
| 18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 | 19 |
| 20 #if defined(OS_ANDROID) | 20 #if defined(OS_ANDROID) |
| 21 #include "content/browser/android/background_sync_launcher_android.h" | 21 #include "content/browser/android/background_sync_launcher_android.h" |
| 22 #include "content/browser/android/background_sync_network_observer_android.h" |
| 22 #endif | 23 #endif |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 const char kBackgroundSyncUserDataKey[] = "BackgroundSyncUserData"; | 26 const char kBackgroundSyncUserDataKey[] = "BackgroundSyncUserData"; |
| 26 } | 27 } |
| 27 | 28 |
| 28 namespace content { | 29 namespace content { |
| 29 | 30 |
| 30 BackgroundSyncManager::BackgroundSyncRegistrations:: | 31 BackgroundSyncManager::BackgroundSyncRegistrations:: |
| 31 BackgroundSyncRegistrations() | 32 BackgroundSyncRegistrations() |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 190 |
| 190 BackgroundSyncManager::BackgroundSyncManager( | 191 BackgroundSyncManager::BackgroundSyncManager( |
| 191 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context) | 192 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context) |
| 192 : service_worker_context_(service_worker_context), | 193 : service_worker_context_(service_worker_context), |
| 193 disabled_(false), | 194 disabled_(false), |
| 194 weak_ptr_factory_(this) { | 195 weak_ptr_factory_(this) { |
| 195 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 196 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 196 | 197 |
| 197 service_worker_context_->AddObserver(this); | 198 service_worker_context_->AddObserver(this); |
| 198 | 199 |
| 200 #if defined(OS_ANDROID) |
| 201 network_observer_.reset(new BackgroundSyncNetworkObserverAndroid( |
| 202 base::Bind(&BackgroundSyncManager::OnNetworkChanged, |
| 203 weak_ptr_factory_.GetWeakPtr()))); |
| 204 #else |
| 199 network_observer_.reset(new BackgroundSyncNetworkObserver( | 205 network_observer_.reset(new BackgroundSyncNetworkObserver( |
| 200 base::Bind(&BackgroundSyncManager::OnNetworkChanged, | 206 base::Bind(&BackgroundSyncManager::OnNetworkChanged, |
| 201 weak_ptr_factory_.GetWeakPtr()))); | 207 weak_ptr_factory_.GetWeakPtr()))); |
| 208 #endif |
| 202 power_observer_.reset(new BackgroundSyncPowerObserver(base::Bind( | 209 power_observer_.reset(new BackgroundSyncPowerObserver(base::Bind( |
| 203 &BackgroundSyncManager::OnPowerChanged, weak_ptr_factory_.GetWeakPtr()))); | 210 &BackgroundSyncManager::OnPowerChanged, weak_ptr_factory_.GetWeakPtr()))); |
| 204 } | 211 } |
| 205 | 212 |
| 206 void BackgroundSyncManager::Init() { | 213 void BackgroundSyncManager::Init() { |
| 207 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 214 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 208 DCHECK(!op_scheduler_.ScheduledOperations()); | 215 DCHECK(!op_scheduler_.ScheduledOperations()); |
| 209 DCHECK(!disabled_); | 216 DCHECK(!disabled_); |
| 210 | 217 |
| 211 op_scheduler_.ScheduleOperation(base::Bind(&BackgroundSyncManager::InitImpl, | 218 op_scheduler_.ScheduleOperation(base::Bind(&BackgroundSyncManager::InitImpl, |
| (...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1073 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) { | 1080 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) { |
| 1074 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1081 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1075 | 1082 |
| 1076 return base::Bind( | 1083 return base::Bind( |
| 1077 &BackgroundSyncManager::CompleteOperationCallback<StatusCallback, | 1084 &BackgroundSyncManager::CompleteOperationCallback<StatusCallback, |
| 1078 BackgroundSyncStatus>, | 1085 BackgroundSyncStatus>, |
| 1079 weak_ptr_factory_.GetWeakPtr(), callback); | 1086 weak_ptr_factory_.GetWeakPtr(), callback); |
| 1080 } | 1087 } |
| 1081 | 1088 |
| 1082 } // namespace content | 1089 } // namespace content |
| OLD | NEW |