Chromium Code Reviews| 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/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| 11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
| 13 #include "content/browser/background_sync/background_sync_metrics.h" | 13 #include "content/browser/background_sync/background_sync_metrics.h" |
| 14 #include "content/browser/background_sync/background_sync_network_observer.h" | 14 #include "content/browser/background_sync/background_sync_network_observer.h" |
| 15 #include "content/browser/background_sync/background_sync_power_observer.h" | 15 #include "content/browser/background_sync/background_sync_power_observer.h" |
| 16 #include "content/browser/background_sync/background_sync_registration_handle.h" | 16 #include "content/browser/background_sync/background_sync_registration_handle.h" |
| 17 #include "content/browser/background_sync/background_sync_registration_options.h " | 17 #include "content/browser/background_sync/background_sync_registration_options.h " |
| 18 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 18 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 19 #include "content/browser/service_worker/service_worker_storage.h" | 19 #include "content/browser/service_worker/service_worker_storage.h" |
| 20 #include "content/browser/storage_partition_impl.h" | 20 #include "content/browser/storage_partition_impl.h" |
| 21 #include "content/public/browser/background_sync_controller.h" | 21 #include "content/public/browser/background_sync_controller.h" |
| 22 #include "content/public/browser/browser_context.h" | 22 #include "content/public/browser/browser_context.h" |
| 23 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 24 | 24 |
| 25 #if defined(OS_ANDROID) | 25 #if defined(OS_ANDROID) |
| 26 #include "content/browser/android/background_sync_launcher_android.h" | |
| 27 #include "content/browser/android/background_sync_network_observer_android.h" | 26 #include "content/browser/android/background_sync_network_observer_android.h" |
| 28 #endif | 27 #endif |
| 29 | 28 |
| 30 namespace content { | 29 namespace content { |
| 31 | 30 |
| 32 class BackgroundSyncManager::RefCountedRegistration | 31 class BackgroundSyncManager::RefCountedRegistration |
| 33 : public base::RefCounted<RefCountedRegistration> { | 32 : public base::RefCounted<RefCountedRegistration> { |
| 34 public: | 33 public: |
| 35 BackgroundSyncRegistration* value() { return ®istration_; } | 34 BackgroundSyncRegistration* value() { return ®istration_; } |
| 36 const BackgroundSyncRegistration* value() const { return ®istration_; } | 35 const BackgroundSyncRegistration* value() const { return ®istration_; } |
| (...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 974 if (registration.options()->periodicity == SYNC_ONE_SHOT) { | 973 if (registration.options()->periodicity == SYNC_ONE_SHOT) { |
| 975 keep_browser_alive_for_one_shot = true; | 974 keep_browser_alive_for_one_shot = true; |
| 976 } else { | 975 } else { |
| 977 // TODO(jkarlin): Support keeping the browser alive for periodic | 976 // TODO(jkarlin): Support keeping the browser alive for periodic |
| 978 // syncs. | 977 // syncs. |
| 979 } | 978 } |
| 980 } | 979 } |
| 981 } | 980 } |
| 982 } | 981 } |
| 983 | 982 |
| 984 // TODO(jkarlin): Use the context's path instead of the 'this' pointer as an | |
| 985 // identifier. See crbug.com/489705. | |
| 986 BrowserThread::PostTask( | 983 BrowserThread::PostTask( |
| 987 BrowserThread::UI, FROM_HERE, | 984 BrowserThread::UI, FROM_HERE, |
| 988 base::Bind(&BackgroundSyncLauncherAndroid::LaunchBrowserWhenNextOnline, | 985 base::Bind(&BackgroundSyncManager::SchedulePendingRegistrationsOnUIThread, |
| 989 this, keep_browser_alive_for_one_shot)); | 986 base::Unretained(this), keep_browser_alive_for_one_shot)); |
| 987 | |
| 990 #else | 988 #else |
| 991 // TODO(jkarlin): Toggle Chrome's background mode. | 989 // TODO(jkarlin): Toggle Chrome's background mode. |
| 992 #endif | 990 #endif |
| 993 } | 991 } |
| 994 | 992 |
| 993 void BackgroundSyncManager::SchedulePendingRegistrationsOnUIThread( | |
| 994 bool keep_browser_alive_for_one_shot) { | |
| 995 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 996 if (!service_worker_context_) // happens in tests? | |
| 997 return; | |
| 998 StoragePartitionImpl* storage_partition_impl = | |
| 999 service_worker_context_->storage_partition(); | |
| 1000 if (!storage_partition_impl) // happens in tests | |
| 1001 return; | |
| 1002 BackgroundSyncController* background_sync_controller = | |
| 1003 storage_partition_impl->browser_context()->GetBackgroundSyncController(); | |
|
jkarlin
2015/10/14 18:30:29
It seems like the above code should be consolidate
iclelland
2015/10/14 19:31:24
Done. That's a good idea. I've refactored the othe
| |
| 1004 | |
| 1005 if (background_sync_controller) { | |
| 1006 // TODO(jkarlin): Use the context's path instead of the 'this' pointer as an | |
| 1007 // identifier. See crbug.com/489705. | |
| 1008 background_sync_controller->LaunchBrowserWhenNextOnline( | |
| 1009 this, keep_browser_alive_for_one_shot); | |
| 1010 } | |
| 1011 } | |
| 1012 | |
| 995 void BackgroundSyncManager::FireReadyEvents() { | 1013 void BackgroundSyncManager::FireReadyEvents() { |
| 996 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1014 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 997 | 1015 |
| 998 if (disabled_) | 1016 if (disabled_) |
| 999 return; | 1017 return; |
| 1000 | 1018 |
| 1001 op_scheduler_.ScheduleOperation( | 1019 op_scheduler_.ScheduleOperation( |
| 1002 base::Bind(&BackgroundSyncManager::FireReadyEventsImpl, | 1020 base::Bind(&BackgroundSyncManager::FireReadyEventsImpl, |
| 1003 weak_ptr_factory_.GetWeakPtr(), MakeEmptyCompletion())); | 1021 weak_ptr_factory_.GetWeakPtr(), MakeEmptyCompletion())); |
| 1004 } | 1022 } |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1318 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) { | 1336 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) { |
| 1319 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1337 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1320 | 1338 |
| 1321 return base::Bind( | 1339 return base::Bind( |
| 1322 &BackgroundSyncManager::CompleteOperationCallback<StatusCallback, | 1340 &BackgroundSyncManager::CompleteOperationCallback<StatusCallback, |
| 1323 BackgroundSyncStatus>, | 1341 BackgroundSyncStatus>, |
| 1324 weak_ptr_factory_.GetWeakPtr(), callback); | 1342 weak_ptr_factory_.GetWeakPtr(), callback); |
| 1325 } | 1343 } |
| 1326 | 1344 |
| 1327 } // namespace content | 1345 } // namespace content |
| OLD | NEW |