1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
// 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 "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"
namespace content {
BackgroundSyncContextImpl::BackgroundSyncContextImpl() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
}
BackgroundSyncContextImpl::~BackgroundSyncContextImpl() {
DCHECK(!background_sync_manager_);
DCHECK(services_.empty());
}
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));
}
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));
services_.erase(service);
delete service;
}
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::CreateServiceOnIOThread(
mojo::InterfaceRequest<BackgroundSyncService> request) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(background_sync_manager_);
services_.insert(new BackgroundSyncServiceImpl(this, request.Pass()));
}
void BackgroundSyncContextImpl::ShutdownOnIO() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
STLDeleteElements(&services_);
background_sync_manager_.reset();
}
} // namespace content
|