Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(598)

Side by Side Diff: content/browser/background_sync/background_sync_context_impl.cc

Issue 1283703003: Change ownership of BackgroundSyncServiceImpl to BackgroundSyncContextImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Small fixes Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_);
iclelland 2015/08/12 04:01:09 Is this really just asserting that ShutdownOnIO is
jkarlin 2015/08/12 11:50:11 Yes, rather than delete everything in either scena
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));
(...skipping 15 matching lines...) Expand all
44 } 48 }
45 49
46 void BackgroundSyncContextImpl::CreateBackgroundSyncManager( 50 void BackgroundSyncContextImpl::CreateBackgroundSyncManager(
47 const scoped_refptr<ServiceWorkerContextWrapper>& context) { 51 const scoped_refptr<ServiceWorkerContextWrapper>& context) {
48 DCHECK_CURRENTLY_ON(BrowserThread::IO); 52 DCHECK_CURRENTLY_ON(BrowserThread::IO);
49 DCHECK(!background_sync_manager_); 53 DCHECK(!background_sync_manager_);
50 54
51 background_sync_manager_ = BackgroundSyncManager::Create(context); 55 background_sync_manager_ = BackgroundSyncManager::Create(context);
52 } 56 }
53 57
58 // static
59 void BackgroundSyncContextImpl::CreateService(
iclelland 2015/08/12 04:01:08 Why a static method that takes an instance as the
jkarlin 2015/08/12 11:50:11 Good point. Done.
60 const scoped_refptr<BackgroundSyncContextImpl>& context,
61 mojo::InterfaceRequest<BackgroundSyncService> request) {
62 DCHECK_CURRENTLY_ON(BrowserThread::UI);
63
64 BrowserThread::PostTask(
65 BrowserThread::IO, FROM_HERE,
66 base::Bind(&BackgroundSyncContextImpl::CreateServiceOnIOThread, context,
67 base::Passed(&request)));
68 }
69
70 void BackgroundSyncContextImpl::CreateServiceOnIOThread(
71 mojo::InterfaceRequest<BackgroundSyncService> request) {
72 DCHECK_CURRENTLY_ON(BrowserThread::IO);
73 if (!background_sync_manager_)
iclelland 2015/08/12 04:01:08 Is this is going to fail silently, should we docum
jkarlin 2015/08/12 11:50:11 It can happen in the wild. Documented and log mess
74 return;
75 services_.insert(
76 new BackgroundSyncServiceImpl(make_scoped_refptr(this), request.Pass()));
77 }
78
79 void BackgroundSyncContextImpl::ServiceHadConnectionError(
80 BackgroundSyncServiceImpl* service) {
81 DCHECK_CURRENTLY_ON(BrowserThread::IO);
82 DCHECK(ContainsValue(services_, service));
83
84 delete service;
85 services_.erase(service);
86 }
87
54 void BackgroundSyncContextImpl::ShutdownOnIO() { 88 void BackgroundSyncContextImpl::ShutdownOnIO() {
55 DCHECK_CURRENTLY_ON(BrowserThread::IO); 89 DCHECK_CURRENTLY_ON(BrowserThread::IO);
56 90
91 STLDeleteElements(&services_);
57 background_sync_manager_.reset(); 92 background_sync_manager_.reset();
58 } 93 }
59 94
60 } // namespace content 95 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698