Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/background_sync/background_sync_context_impl.h" | 5 #include "content/browser/background_sync/background_sync_context_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/stl_util.h" | |
| 8 #include "content/browser/background_sync/background_sync_manager.h" | 9 #include "content/browser/background_sync/background_sync_manager.h" |
| 10 #include "content/browser/background_sync/background_sync_service_impl.h" | |
| 9 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 11 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 10 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 11 | 13 |
| 12 namespace content { | 14 namespace content { |
| 13 | 15 |
| 14 BackgroundSyncContextImpl::BackgroundSyncContextImpl() { | 16 BackgroundSyncContextImpl::BackgroundSyncContextImpl() { |
| 15 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 17 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 16 } | 18 } |
| 17 | 19 |
| 18 BackgroundSyncContextImpl::~BackgroundSyncContextImpl() { | 20 BackgroundSyncContextImpl::~BackgroundSyncContextImpl() { |
| 21 DCHECK(!background_sync_manager_); | |
| 22 DCHECK(services_.empty()); | |
| 19 } | 23 } |
| 20 | 24 |
| 21 void BackgroundSyncContextImpl::Init( | 25 void BackgroundSyncContextImpl::Init( |
| 22 const scoped_refptr<ServiceWorkerContextWrapper>& context) { | 26 const scoped_refptr<ServiceWorkerContextWrapper>& context) { |
| 23 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 27 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 24 | 28 |
| 25 BrowserThread::PostTask( | 29 BrowserThread::PostTask( |
| 26 BrowserThread::IO, FROM_HERE, | 30 BrowserThread::IO, FROM_HERE, |
| 27 base::Bind(&BackgroundSyncContextImpl::CreateBackgroundSyncManager, this, | 31 base::Bind(&BackgroundSyncContextImpl::CreateBackgroundSyncManager, this, |
| 28 context)); | 32 context)); |
| 29 } | 33 } |
| 30 | 34 |
| 31 void BackgroundSyncContextImpl::Shutdown() { | 35 void BackgroundSyncContextImpl::Shutdown() { |
| 32 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 36 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 33 | 37 |
| 34 BrowserThread::PostTask( | 38 BrowserThread::PostTask( |
| 35 BrowserThread::IO, FROM_HERE, | 39 BrowserThread::IO, FROM_HERE, |
| 36 base::Bind(&BackgroundSyncContextImpl::ShutdownOnIO, this)); | 40 base::Bind(&BackgroundSyncContextImpl::ShutdownOnIO, this)); |
| 37 } | 41 } |
| 38 | 42 |
| 43 void BackgroundSyncContextImpl::CreateService( | |
| 44 mojo::InterfaceRequest<BackgroundSyncService> request) { | |
| 45 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 46 | |
| 47 BrowserThread::PostTask( | |
| 48 BrowserThread::IO, FROM_HERE, | |
| 49 base::Bind(&BackgroundSyncContextImpl::CreateServiceOnIOThread, this, | |
| 50 base::Passed(&request))); | |
| 51 } | |
| 52 | |
| 53 void BackgroundSyncContextImpl::ServiceHadConnectionError( | |
| 54 BackgroundSyncServiceImpl* service) { | |
| 55 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 56 DCHECK(ContainsValue(services_, service)); | |
| 57 | |
| 58 delete service; | |
| 59 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.
| |
| 60 } | |
| 61 | |
| 39 BackgroundSyncManager* BackgroundSyncContextImpl::background_sync_manager() | 62 BackgroundSyncManager* BackgroundSyncContextImpl::background_sync_manager() |
| 40 const { | 63 const { |
| 41 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 64 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 42 | 65 |
| 43 return background_sync_manager_.get(); | 66 return background_sync_manager_.get(); |
| 44 } | 67 } |
| 45 | 68 |
| 46 void BackgroundSyncContextImpl::CreateBackgroundSyncManager( | 69 void BackgroundSyncContextImpl::CreateBackgroundSyncManager( |
| 47 const scoped_refptr<ServiceWorkerContextWrapper>& context) { | 70 const scoped_refptr<ServiceWorkerContextWrapper>& context) { |
| 48 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 71 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 49 DCHECK(!background_sync_manager_); | 72 DCHECK(!background_sync_manager_); |
| 50 | 73 |
| 51 background_sync_manager_ = BackgroundSyncManager::Create(context); | 74 background_sync_manager_ = BackgroundSyncManager::Create(context); |
| 52 } | 75 } |
| 53 | 76 |
| 77 void BackgroundSyncContextImpl::CreateServiceOnIOThread( | |
| 78 mojo::InterfaceRequest<BackgroundSyncService> request) { | |
| 79 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 80 if (!background_sync_manager_) { | |
| 81 // This can happen during shutdown if the render process uses the background | |
| 82 // sync API (creating this mojo channel request) after this object has | |
| 83 // already shutdown (the StoragePartition can shut down before the | |
| 84 // RenderProcessHost does). | |
| 85 LOG(WARNING) << "Service created after shutdown called"; | |
| 86 return; | |
| 87 } | |
| 88 services_.insert( | |
| 89 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.
| |
| 90 } | |
| 91 | |
| 54 void BackgroundSyncContextImpl::ShutdownOnIO() { | 92 void BackgroundSyncContextImpl::ShutdownOnIO() { |
| 55 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 93 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 56 | 94 |
| 95 STLDeleteElements(&services_); | |
| 57 background_sync_manager_.reset(); | 96 background_sync_manager_.reset(); |
| 58 } | 97 } |
| 59 | 98 |
| 60 } // namespace content | 99 } // namespace content |
| OLD | NEW |