summaryrefslogtreecommitdiffstats
path: root/content/browser/background_sync/background_sync_manager.cc
diff options
context:
space:
mode:
authorjkarlin <jkarlin@chromium.org>2015-11-06 05:18:41 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-06 13:19:28 +0000
commitfe08f137f867befed12f1b9c0c1ed8e5c2d59e80 (patch)
treed1ccce2ae2e9464d7be01fab970d5cdf168fc9c6 /content/browser/background_sync/background_sync_manager.cc
parent9919d1bdb281d1a0ef47786818536d90bc18ef4e (diff)
downloadchromium_src-fe08f137f867befed12f1b9c0c1ed8e5c2d59e80.zip
chromium_src-fe08f137f867befed12f1b9c0c1ed8e5c2d59e80.tar.gz
chromium_src-fe08f137f867befed12f1b9c0c1ed8e5c2d59e80.tar.bz2
[BackgroundSync] Unify relaunching browser API for all platforms
Creates BackgroundSyncController::RunInBackground(bool) which can be used on all platforms. On Android it will forward to LaunchBrowserWhenNextOnline and on other platforms it will enable background mode. Adds content_unittests for the BackgroundSyncController to verify that it's being called correctly by the BackgroundSyncManager. This requires access to a BrowserContext from tests (hence the switch to using the single argument EmbeddedWorkerTestHelper constructor). BUG=549550,489705,549826,548052 Review URL: https://codereview.chromium.org/1422583003 Cr-Commit-Position: refs/heads/master@{#358313}
Diffstat (limited to 'content/browser/background_sync/background_sync_manager.cc')
-rw-r--r--content/browser/background_sync/background_sync_manager.cc37
1 files changed, 15 insertions, 22 deletions
diff --git a/content/browser/background_sync/background_sync_manager.cc b/content/browser/background_sync/background_sync_manager.cc
index 5624239..df3fcb6 100644
--- a/content/browser/background_sync/background_sync_manager.cc
+++ b/content/browser/background_sync/background_sync_manager.cc
@@ -91,6 +91,18 @@ void NotifyBackgroundSyncRegisteredOnUIThread(
background_sync_controller->NotifyBackgroundSyncRegistered(origin);
}
+void RunInBackgroundOnUIThread(
+ const scoped_refptr<ServiceWorkerContextWrapper>& sw_context_wrapper,
+ bool enabled) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+
+ BackgroundSyncController* background_sync_controller =
+ GetBackgroundSyncControllerOnUIThread(sw_context_wrapper);
+ if (background_sync_controller) {
+ background_sync_controller->RunInBackground(enabled);
+ }
+}
+
} // namespace
BackgroundSyncManager::BackgroundSyncRegistrations::
@@ -973,7 +985,6 @@ bool BackgroundSyncManager::IsRegistrationReadyToFire(
}
void BackgroundSyncManager::SchedulePendingRegistrations() {
-#if defined(OS_ANDROID)
bool keep_browser_alive_for_one_shot = false;
for (const auto& sw_id_and_registrations : active_registrations_) {
@@ -994,26 +1005,8 @@ void BackgroundSyncManager::SchedulePendingRegistrations() {
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
- base::Bind(&BackgroundSyncManager::SchedulePendingRegistrationsOnUIThread,
- base::Unretained(this), keep_browser_alive_for_one_shot));
-
-#else
-// TODO(jkarlin): Toggle Chrome's background mode.
-#endif
-}
-
-void BackgroundSyncManager::SchedulePendingRegistrationsOnUIThread(
- bool keep_browser_alive_for_one_shot) {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
-
- BackgroundSyncController* background_sync_controller =
- GetBackgroundSyncControllerOnUIThread(service_worker_context_);
- if (background_sync_controller) {
- // TODO(jkarlin): Use the context's path instead of the 'this' pointer as an
- // identifier. See crbug.com/489705.
- background_sync_controller->LaunchBrowserWhenNextOnline(
- this, keep_browser_alive_for_one_shot);
- }
+ base::Bind(RunInBackgroundOnUIThread, service_worker_context_,
+ keep_browser_alive_for_one_shot));
}
void BackgroundSyncManager::FireReadyEvents() {
@@ -1058,7 +1051,7 @@ void BackgroundSyncManager::FireReadyEventsImpl(const base::Closure& callback) {
// If there are no registrations currently ready, then just run |callback|.
// Otherwise, fire them all, and record the result when done.
- if (sw_id_and_keys_to_fire.size() == 0) {
+ if (sw_id_and_keys_to_fire.empty()) {
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
base::Bind(callback));
} else {