| // Copyright 2015 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "content/browser/background_sync/background_sync_context_impl.h" |
| |
| #include "base/bind.h" |
| #include "content/browser/background_sync/background_sync_manager.h" |
| #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| #include "content/public/browser/browser_thread.h" |
| |
| namespace content { |
| |
| BackgroundSyncContextImpl::BackgroundSyncContextImpl() { |
| DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| } |
| |
| BackgroundSyncContextImpl::~BackgroundSyncContextImpl() { |
| } |
| |
| void BackgroundSyncContextImpl::Init( |
| const scoped_refptr<ServiceWorkerContextWrapper>& context) { |
| DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| |
| BrowserThread::PostTask( |
| BrowserThread::IO, FROM_HERE, |
| base::Bind(&BackgroundSyncContextImpl::CreateBackgroundSyncManager, this, |
| context)); |
| } |
| |
| void BackgroundSyncContextImpl::Shutdown() { |
| DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| |
| BrowserThread::PostTask( |
| BrowserThread::IO, FROM_HERE, |
| base::Bind(&BackgroundSyncContextImpl::ShutdownOnIO, this)); |
| } |
| |
| BackgroundSyncManager* BackgroundSyncContextImpl::background_sync_manager() |
| const { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| |
| return background_sync_manager_.get(); |
| } |
| |
| void BackgroundSyncContextImpl::CreateBackgroundSyncManager( |
| const scoped_refptr<ServiceWorkerContextWrapper>& context) { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| DCHECK(!background_sync_manager_); |
| |
| background_sync_manager_ = BackgroundSyncManager::Create(context); |
| } |
| |
| void BackgroundSyncContextImpl::ShutdownOnIO() { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| |
| background_sync_manager_.reset(); |
| } |
| |
| } // namespace content |