Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(598)

Side by Side Diff: content/browser/background_sync/background_sync_manager.cc

Issue 1383663004: Reland of [Background Sync] Trigger Background Sync events when Chrome is backgrounded on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Don't crash in embedded webview; check permissions before creating NCNAD Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
21 21
22 #if defined(OS_ANDROID) 22 #if defined(OS_ANDROID)
23 #include "content/browser/android/background_sync_launcher_android.h" 23 #include "content/browser/android/background_sync_launcher_android.h"
24 #include "content/browser/android/background_sync_network_observer_android.h"
24 #endif 25 #endif
25 26
26 namespace content { 27 namespace content {
27 28
28 class BackgroundSyncManager::RefCountedRegistration 29 class BackgroundSyncManager::RefCountedRegistration
29 : public base::RefCounted<RefCountedRegistration> { 30 : public base::RefCounted<RefCountedRegistration> {
30 public: 31 public:
31 BackgroundSyncRegistration* value() { return &registration_; } 32 BackgroundSyncRegistration* value() { return &registration_; }
32 const BackgroundSyncRegistration* value() const { return &registration_; } 33 const BackgroundSyncRegistration* value() const { return &registration_; }
33 34
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 215
215 BackgroundSyncManager::BackgroundSyncManager( 216 BackgroundSyncManager::BackgroundSyncManager(
216 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context) 217 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context)
217 : service_worker_context_(service_worker_context), 218 : service_worker_context_(service_worker_context),
218 disabled_(false), 219 disabled_(false),
219 weak_ptr_factory_(this) { 220 weak_ptr_factory_(this) {
220 DCHECK_CURRENTLY_ON(BrowserThread::IO); 221 DCHECK_CURRENTLY_ON(BrowserThread::IO);
221 222
222 service_worker_context_->AddObserver(this); 223 service_worker_context_->AddObserver(this);
223 224
225 #if defined(OS_ANDROID)
226 network_observer_.reset(new BackgroundSyncNetworkObserverAndroid(
227 base::Bind(&BackgroundSyncManager::OnNetworkChanged,
228 weak_ptr_factory_.GetWeakPtr())));
229 #else
224 network_observer_.reset(new BackgroundSyncNetworkObserver( 230 network_observer_.reset(new BackgroundSyncNetworkObserver(
225 base::Bind(&BackgroundSyncManager::OnNetworkChanged, 231 base::Bind(&BackgroundSyncManager::OnNetworkChanged,
226 weak_ptr_factory_.GetWeakPtr()))); 232 weak_ptr_factory_.GetWeakPtr())));
233 #endif
227 power_observer_.reset(new BackgroundSyncPowerObserver(base::Bind( 234 power_observer_.reset(new BackgroundSyncPowerObserver(base::Bind(
228 &BackgroundSyncManager::OnPowerChanged, weak_ptr_factory_.GetWeakPtr()))); 235 &BackgroundSyncManager::OnPowerChanged, weak_ptr_factory_.GetWeakPtr())));
229 } 236 }
230 237
231 void BackgroundSyncManager::Init() { 238 void BackgroundSyncManager::Init() {
232 DCHECK_CURRENTLY_ON(BrowserThread::IO); 239 DCHECK_CURRENTLY_ON(BrowserThread::IO);
233 DCHECK(!op_scheduler_.ScheduledOperations()); 240 DCHECK(!op_scheduler_.ScheduledOperations());
234 DCHECK(!disabled_); 241 DCHECK(!disabled_);
235 242
236 op_scheduler_.ScheduleOperation(base::Bind(&BackgroundSyncManager::InitImpl, 243 op_scheduler_.ScheduleOperation(base::Bind(&BackgroundSyncManager::InitImpl,
(...skipping 1073 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) { 1317 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) {
1311 DCHECK_CURRENTLY_ON(BrowserThread::IO); 1318 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1312 1319
1313 return base::Bind( 1320 return base::Bind(
1314 &BackgroundSyncManager::CompleteOperationCallback<StatusCallback, 1321 &BackgroundSyncManager::CompleteOperationCallback<StatusCallback,
1315 BackgroundSyncStatus>, 1322 BackgroundSyncStatus>,
1316 weak_ptr_factory_.GetWeakPtr(), callback); 1323 weak_ptr_factory_.GetWeakPtr(), callback);
1317 } 1324 }
1318 1325
1319 } // namespace content 1326 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698