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

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

Issue 1283703003: Change ownership of BackgroundSyncServiceImpl to BackgroundSyncContextImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Small fixes Created 5 years, 4 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
Index: content/browser/background_sync/background_sync_context_impl.cc
diff --git a/content/browser/background_sync/background_sync_context_impl.cc b/content/browser/background_sync/background_sync_context_impl.cc
index 31ad2a0a99cad980f7716102345938974bd4fcbb..7abd1637acf64487f6760dd803d262e253b12e14 100644
--- a/content/browser/background_sync/background_sync_context_impl.cc
+++ b/content/browser/background_sync/background_sync_context_impl.cc
@@ -5,7 +5,9 @@
#include "content/browser/background_sync/background_sync_context_impl.h"
#include "base/bind.h"
+#include "base/stl_util.h"
#include "content/browser/background_sync/background_sync_manager.h"
+#include "content/browser/background_sync/background_sync_service_impl.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/public/browser/browser_thread.h"
@@ -16,6 +18,8 @@ BackgroundSyncContextImpl::BackgroundSyncContextImpl() {
}
BackgroundSyncContextImpl::~BackgroundSyncContextImpl() {
+ DCHECK(!background_sync_manager_);
iclelland 2015/08/12 04:01:09 Is this really just asserting that ShutdownOnIO is
jkarlin 2015/08/12 11:50:11 Yes, rather than delete everything in either scena
+ DCHECK(services_.empty());
}
void BackgroundSyncContextImpl::Init(
@@ -51,9 +55,40 @@ void BackgroundSyncContextImpl::CreateBackgroundSyncManager(
background_sync_manager_ = BackgroundSyncManager::Create(context);
}
+// static
+void BackgroundSyncContextImpl::CreateService(
iclelland 2015/08/12 04:01:08 Why a static method that takes an instance as the
jkarlin 2015/08/12 11:50:11 Good point. Done.
+ const scoped_refptr<BackgroundSyncContextImpl>& context,
+ mojo::InterfaceRequest<BackgroundSyncService> request) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&BackgroundSyncContextImpl::CreateServiceOnIOThread, context,
+ base::Passed(&request)));
+}
+
+void BackgroundSyncContextImpl::CreateServiceOnIOThread(
+ mojo::InterfaceRequest<BackgroundSyncService> request) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ if (!background_sync_manager_)
iclelland 2015/08/12 04:01:08 Is this is going to fail silently, should we docum
jkarlin 2015/08/12 11:50:11 It can happen in the wild. Documented and log mess
+ return;
+ services_.insert(
+ new BackgroundSyncServiceImpl(make_scoped_refptr(this), request.Pass()));
+}
+
+void BackgroundSyncContextImpl::ServiceHadConnectionError(
+ BackgroundSyncServiceImpl* service) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DCHECK(ContainsValue(services_, service));
+
+ delete service;
+ services_.erase(service);
+}
+
void BackgroundSyncContextImpl::ShutdownOnIO() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ STLDeleteElements(&services_);
background_sync_manager_.reset();
}

Powered by Google App Engine
This is Rietveld 408576698