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

Unified Diff: content/browser/background_sync/background_sync_manager.cc

Issue 1324173002: [Background Sync] Use GcmNetworkManager to start the browser for sync events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@bgsync-fix-background5
Patch Set: Addressing comments from PS#25 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/background_sync/background_sync_manager.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/background_sync/background_sync_manager.cc
diff --git a/content/browser/background_sync/background_sync_manager.cc b/content/browser/background_sync/background_sync_manager.cc
index 01cdcb51d69f7a55cb59f964ad1b2be2c4de3265..f6c4e75ff8de5a37049105f563b98e2c959cc416 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);
« no previous file with comments | « content/browser/background_sync/background_sync_manager.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698