Chromium Code Reviews| 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..542ac13213fb851bdb18967a029ae8d711f8c628 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_); |
| + DCHECK(services_.empty()); |
| } |
| void BackgroundSyncContextImpl::Init( |
| @@ -36,6 +40,25 @@ void BackgroundSyncContextImpl::Shutdown() { |
| base::Bind(&BackgroundSyncContextImpl::ShutdownOnIO, this)); |
| } |
| +void BackgroundSyncContextImpl::CreateService( |
| + mojo::InterfaceRequest<BackgroundSyncService> request) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, FROM_HERE, |
| + base::Bind(&BackgroundSyncContextImpl::CreateServiceOnIOThread, this, |
| + base::Passed(&request))); |
| +} |
| + |
| +void BackgroundSyncContextImpl::ServiceHadConnectionError( |
| + BackgroundSyncServiceImpl* service) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + DCHECK(ContainsValue(services_, service)); |
| + |
| + delete service; |
| + services_.erase(service); |
|
davidben
2015/08/13 14:54:30
I don't think it can actually make a difference he
jkarlin
2015/08/13 15:24:27
Done.
|
| +} |
| + |
| BackgroundSyncManager* BackgroundSyncContextImpl::background_sync_manager() |
| const { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| @@ -51,9 +74,25 @@ void BackgroundSyncContextImpl::CreateBackgroundSyncManager( |
| background_sync_manager_ = BackgroundSyncManager::Create(context); |
| } |
| +void BackgroundSyncContextImpl::CreateServiceOnIOThread( |
| + mojo::InterfaceRequest<BackgroundSyncService> request) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + if (!background_sync_manager_) { |
| + // This can happen during shutdown if the render process uses the background |
| + // sync API (creating this mojo channel request) after this object has |
| + // already shutdown (the StoragePartition can shut down before the |
| + // RenderProcessHost does). |
| + LOG(WARNING) << "Service created after shutdown called"; |
| + return; |
| + } |
| + services_.insert( |
| + new BackgroundSyncServiceImpl(make_scoped_refptr(this), request.Pass())); |
|
davidben
2015/08/13 14:54:30
Is this not a reference cycle?
jkarlin
2015/08/13 15:24:27
*hangs head in shame*. Fixed.
|
| +} |
| + |
| void BackgroundSyncContextImpl::ShutdownOnIO() { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + STLDeleteElements(&services_); |
| background_sync_manager_.reset(); |
| } |