[MacViews] Show comboboxes with a native NSMenu
[chromium-blink-merge.git] / content / browser / background_sync / background_sync_context_impl.cc
blob4e55d839bad0d3dd7d86c6bde36bee940e0a2f97
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"
7 #include "base/bind.h"
8 #include "base/stl_util.h"
9 #include "content/browser/background_sync/background_sync_manager.h"
10 #include "content/browser/background_sync/background_sync_service_impl.h"
11 #include "content/browser/service_worker/service_worker_context_wrapper.h"
12 #include "content/public/browser/browser_thread.h"
14 namespace content {
16 BackgroundSyncContextImpl::BackgroundSyncContextImpl() {
17 DCHECK_CURRENTLY_ON(BrowserThread::UI);
20 BackgroundSyncContextImpl::~BackgroundSyncContextImpl() {
21 DCHECK(!background_sync_manager_);
22 DCHECK(services_.empty());
25 void BackgroundSyncContextImpl::Init(
26 const scoped_refptr<ServiceWorkerContextWrapper>& context) {
27 DCHECK_CURRENTLY_ON(BrowserThread::UI);
29 BrowserThread::PostTask(
30 BrowserThread::IO, FROM_HERE,
31 base::Bind(&BackgroundSyncContextImpl::CreateBackgroundSyncManager, this,
32 context));
35 void BackgroundSyncContextImpl::Shutdown() {
36 DCHECK_CURRENTLY_ON(BrowserThread::UI);
38 BrowserThread::PostTask(
39 BrowserThread::IO, FROM_HERE,
40 base::Bind(&BackgroundSyncContextImpl::ShutdownOnIO, this));
43 void BackgroundSyncContextImpl::CreateService(
44 mojo::InterfaceRequest<BackgroundSyncService> request) {
45 DCHECK_CURRENTLY_ON(BrowserThread::UI);
47 BrowserThread::PostTask(
48 BrowserThread::IO, FROM_HERE,
49 base::Bind(&BackgroundSyncContextImpl::CreateServiceOnIOThread, this,
50 base::Passed(&request)));
53 void BackgroundSyncContextImpl::ServiceHadConnectionError(
54 BackgroundSyncServiceImpl* service) {
55 DCHECK_CURRENTLY_ON(BrowserThread::IO);
56 DCHECK(ContainsValue(services_, service));
58 services_.erase(service);
59 delete service;
62 BackgroundSyncManager* BackgroundSyncContextImpl::background_sync_manager()
63 const {
64 DCHECK_CURRENTLY_ON(BrowserThread::IO);
66 return background_sync_manager_.get();
69 void BackgroundSyncContextImpl::CreateBackgroundSyncManager(
70 const scoped_refptr<ServiceWorkerContextWrapper>& context) {
71 DCHECK_CURRENTLY_ON(BrowserThread::IO);
72 DCHECK(!background_sync_manager_);
74 background_sync_manager_ = BackgroundSyncManager::Create(context);
77 void BackgroundSyncContextImpl::CreateServiceOnIOThread(
78 mojo::InterfaceRequest<BackgroundSyncService> request) {
79 DCHECK_CURRENTLY_ON(BrowserThread::IO);
80 DCHECK(background_sync_manager_);
81 services_.insert(new BackgroundSyncServiceImpl(this, request.Pass()));
84 void BackgroundSyncContextImpl::ShutdownOnIO() {
85 DCHECK_CURRENTLY_ON(BrowserThread::IO);
87 STLDeleteElements(&services_);
88 background_sync_manager_.reset();
91 } // namespace content