diff options
author | iclelland <iclelland@chromium.org> | 2015-10-21 07:03:13 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-21 14:04:03 +0000 |
commit | 8467f460d6cf1b2b5c71664d952819e2b3b58b85 (patch) | |
tree | 624498cf3c7b3c17ac5e99d0fd5954e367ba5103 /content/browser/background_sync/background_sync_manager.cc | |
parent | 695d47eaa44d789ada5e81bfc1758929df52af93 (diff) | |
download | chromium_src-8467f460d6cf1b2b5c71664d952819e2b3b58b85.zip chromium_src-8467f460d6cf1b2b5c71664d952819e2b3b58b85.tar.gz chromium_src-8467f460d6cf1b2b5c71664d952819e2b3b58b85.tar.bz2 |
[Background Sync] Use GcmNetworkManager to start the browser for sync events.
This replaces the old BackgroundSyncLauncherService with one that
extends GcmTaskService, pulls in Play Services for Chrome on Android,
and uses the GCM network manager to schedule a one-off task to restart
the browser when the network comes back online if a one-shot background
sync is registered when the browser is stopped.
It also adds the RECEIVE_BOOT_COMPLETED permission to the Chrome Android
manifest, so that registered sync events can persist across device reboots.
(This is a non-dangerous permission)
This requires Google Play Services 7.5, which is a dependency of Chromium as of 0c50961:
https://crrev.com/0c50961006cd76b2a20f445a6f296535664e777d
BUG=491137
Review URL: https://codereview.chromium.org/1324173002
Cr-Commit-Position: refs/heads/master@{#355284}
Diffstat (limited to 'content/browser/background_sync/background_sync_manager.cc')
-rw-r--r-- | content/browser/background_sync/background_sync_manager.cc | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/content/browser/background_sync/background_sync_manager.cc b/content/browser/background_sync/background_sync_manager.cc index d7fb0f9..96e41e8 100644 --- a/content/browser/background_sync/background_sync_manager.cc +++ b/content/browser/background_sync/background_sync_manager.cc @@ -23,7 +23,6 @@ #include "content/public/browser/browser_thread.h" #if defined(OS_ANDROID) -#include "content/browser/android/background_sync_launcher_android.h" #include "content/browser/android/background_sync_network_observer_android.h" #endif @@ -62,18 +61,29 @@ bool ShouldDisableForFieldTrial() { base::CompareCase::INSENSITIVE_ASCII); } +// Returns nullptr if the controller cannot be accessed for any reason. +BackgroundSyncController* GetBackgroundSyncControllerOnUIThread( + const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context) { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + + if (!service_worker_context) + return nullptr; + StoragePartitionImpl* storage_partition_impl = + service_worker_context->storage_partition(); + if (!storage_partition_impl) // may be null in tests + return nullptr; + + return storage_partition_impl->browser_context() + ->GetBackgroundSyncController(); +} + void NotifyBackgroundSyncRegisteredOnUIThread( const scoped_refptr<ServiceWorkerContextWrapper>& sw_context_wrapper, const GURL& origin) { DCHECK_CURRENTLY_ON(BrowserThread::UI); - StoragePartitionImpl* storage_partition_impl = - sw_context_wrapper->storage_partition(); - if (!storage_partition_impl) // happens in tests - return; - BackgroundSyncController* background_sync_controller = - storage_partition_impl->browser_context()->GetBackgroundSyncController(); + GetBackgroundSyncControllerOnUIThread(sw_context_wrapper); if (!background_sync_controller) return; @@ -982,17 +992,30 @@ void BackgroundSyncManager::SchedulePendingRegistrations() { } } - // TODO(jkarlin): Use the context's path instead of the 'this' pointer as an - // identifier. See crbug.com/489705. BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, - base::Bind(&BackgroundSyncLauncherAndroid::LaunchBrowserWhenNextOnline, - this, keep_browser_alive_for_one_shot)); + 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); + } +} + void BackgroundSyncManager::FireReadyEvents() { DCHECK_CURRENTLY_ON(BrowserThread::IO); |