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
3 // found in the LICENSE file.
5 #include "content/browser/background_sync/background_sync_context_impl.h"
8 #include "content/browser/background_sync/background_sync_manager.h"
9 #include "content/browser/service_worker/service_worker_context_wrapper.h"
10 #include "content/public/browser/browser_thread.h"
14 BackgroundSyncContextImpl::BackgroundSyncContextImpl() {
15 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
18 BackgroundSyncContextImpl::~BackgroundSyncContextImpl() {
21 void BackgroundSyncContextImpl::Init(
22 const scoped_refptr
<ServiceWorkerContextWrapper
>& context
) {
23 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
25 BrowserThread::PostTask(
26 BrowserThread::IO
, FROM_HERE
,
27 base::Bind(&BackgroundSyncContextImpl::CreateBackgroundSyncManager
, this,
31 void BackgroundSyncContextImpl::Shutdown() {
32 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
34 BrowserThread::PostTask(
35 BrowserThread::IO
, FROM_HERE
,
36 base::Bind(&BackgroundSyncContextImpl::ShutdownOnIO
, this));
39 BackgroundSyncManager
* BackgroundSyncContextImpl::background_sync_manager()
41 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
43 return background_sync_manager_
.get();
46 void BackgroundSyncContextImpl::CreateBackgroundSyncManager(
47 const scoped_refptr
<ServiceWorkerContextWrapper
>& context
) {
48 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
49 DCHECK(!background_sync_manager_
);
51 background_sync_manager_
= BackgroundSyncManager::Create(context
);
54 void BackgroundSyncContextImpl::ShutdownOnIO() {
55 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
57 background_sync_manager_
.reset();
60 } // namespace content