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..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(); |
| } |