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

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

Issue 1294603003: [BackgroundSync] Trigger Background Sync events when Chrome is backgrounded on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update browser tests to trigger network observer directly Created 5 years, 3 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/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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 191
191 BackgroundSyncManager::BackgroundSyncManager( 192 BackgroundSyncManager::BackgroundSyncManager(
192 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context) 193 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context)
193 : service_worker_context_(service_worker_context), 194 : service_worker_context_(service_worker_context),
194 disabled_(false), 195 disabled_(false),
195 weak_ptr_factory_(this) { 196 weak_ptr_factory_(this) {
196 DCHECK_CURRENTLY_ON(BrowserThread::IO); 197 DCHECK_CURRENTLY_ON(BrowserThread::IO);
197 198
198 service_worker_context_->AddObserver(this); 199 service_worker_context_->AddObserver(this);
199 200
201 #if defined(OS_ANDROID)
202 network_observer_.reset(new BackgroundSyncNetworkObserverAndroid(
203 base::Bind(&BackgroundSyncManager::OnNetworkChanged,
204 weak_ptr_factory_.GetWeakPtr())));
205 #else
200 network_observer_.reset(new BackgroundSyncNetworkObserver( 206 network_observer_.reset(new BackgroundSyncNetworkObserver(
201 base::Bind(&BackgroundSyncManager::OnNetworkChanged, 207 base::Bind(&BackgroundSyncManager::OnNetworkChanged,
202 weak_ptr_factory_.GetWeakPtr()))); 208 weak_ptr_factory_.GetWeakPtr())));
209 #endif
203 power_observer_.reset(new BackgroundSyncPowerObserver(base::Bind( 210 power_observer_.reset(new BackgroundSyncPowerObserver(base::Bind(
204 &BackgroundSyncManager::OnPowerChanged, weak_ptr_factory_.GetWeakPtr()))); 211 &BackgroundSyncManager::OnPowerChanged, weak_ptr_factory_.GetWeakPtr())));
205 } 212 }
206 213
207 void BackgroundSyncManager::Init() { 214 void BackgroundSyncManager::Init() {
208 DCHECK_CURRENTLY_ON(BrowserThread::IO); 215 DCHECK_CURRENTLY_ON(BrowserThread::IO);
209 DCHECK(!op_scheduler_.ScheduledOperations()); 216 DCHECK(!op_scheduler_.ScheduledOperations());
210 DCHECK(!disabled_); 217 DCHECK(!disabled_);
211 218
212 op_scheduler_.ScheduleOperation(base::Bind(&BackgroundSyncManager::InitImpl, 219 op_scheduler_.ScheduleOperation(base::Bind(&BackgroundSyncManager::InitImpl,
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) { 1083 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) {
1077 DCHECK_CURRENTLY_ON(BrowserThread::IO); 1084 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1078 1085
1079 return base::Bind( 1086 return base::Bind(
1080 &BackgroundSyncManager::CompleteOperationCallback<StatusCallback, 1087 &BackgroundSyncManager::CompleteOperationCallback<StatusCallback,
1081 BackgroundSyncStatus>, 1088 BackgroundSyncStatus>,
1082 weak_ptr_factory_.GetWeakPtr(), callback); 1089 weak_ptr_factory_.GetWeakPtr(), callback);
1083 } 1090 }
1084 1091
1085 } // namespace content 1092 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698