OLD | NEW |
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" | |
9 #include "content/browser/background_sync/background_sync_manager.h" | 8 #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" | 9 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
12 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
13 | 11 |
14 namespace content { | 12 namespace content { |
15 | 13 |
16 BackgroundSyncContextImpl::BackgroundSyncContextImpl() { | 14 BackgroundSyncContextImpl::BackgroundSyncContextImpl() { |
17 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 15 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
18 } | 16 } |
19 | 17 |
20 BackgroundSyncContextImpl::~BackgroundSyncContextImpl() { | 18 BackgroundSyncContextImpl::~BackgroundSyncContextImpl() { |
(...skipping 22 matching lines...) Expand all Loading... |
43 void BackgroundSyncContextImpl::CreateService( | 41 void BackgroundSyncContextImpl::CreateService( |
44 mojo::InterfaceRequest<BackgroundSyncService> request) { | 42 mojo::InterfaceRequest<BackgroundSyncService> request) { |
45 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 43 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
46 | 44 |
47 BrowserThread::PostTask( | 45 BrowserThread::PostTask( |
48 BrowserThread::IO, FROM_HERE, | 46 BrowserThread::IO, FROM_HERE, |
49 base::Bind(&BackgroundSyncContextImpl::CreateServiceOnIOThread, this, | 47 base::Bind(&BackgroundSyncContextImpl::CreateServiceOnIOThread, this, |
50 base::Passed(&request))); | 48 base::Passed(&request))); |
51 } | 49 } |
52 | 50 |
53 void BackgroundSyncContextImpl::ServiceHadConnectionError( | |
54 BackgroundSyncServiceImpl* service) { | |
55 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
56 DCHECK(ContainsValue(services_, service)); | |
57 | |
58 services_.erase(service); | |
59 delete service; | |
60 } | |
61 | |
62 BackgroundSyncManager* BackgroundSyncContextImpl::background_sync_manager() | 51 BackgroundSyncManager* BackgroundSyncContextImpl::background_sync_manager() |
63 const { | 52 const { |
64 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 53 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
65 | 54 |
66 return background_sync_manager_.get(); | 55 return background_sync_manager_.get(); |
67 } | 56 } |
68 | 57 |
69 void BackgroundSyncContextImpl::CreateBackgroundSyncManager( | 58 void BackgroundSyncContextImpl::CreateBackgroundSyncManager( |
70 const scoped_refptr<ServiceWorkerContextWrapper>& context) { | 59 const scoped_refptr<ServiceWorkerContextWrapper>& context) { |
71 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 60 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
72 DCHECK(!background_sync_manager_); | 61 DCHECK(!background_sync_manager_); |
73 | 62 |
74 background_sync_manager_ = BackgroundSyncManager::Create(context); | 63 background_sync_manager_ = BackgroundSyncManager::Create(context); |
75 } | 64 } |
76 | 65 |
77 void BackgroundSyncContextImpl::CreateServiceOnIOThread( | 66 void BackgroundSyncContextImpl::CreateServiceOnIOThread( |
78 mojo::InterfaceRequest<BackgroundSyncService> request) { | 67 mojo::InterfaceRequest<BackgroundSyncService> request) { |
79 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 68 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
80 DCHECK(background_sync_manager_); | 69 DCHECK(background_sync_manager_); |
81 services_.insert(new BackgroundSyncServiceImpl(this, request.Pass())); | 70 services_.EmplaceService(request.Pass(), background_sync_manager()); |
82 } | 71 } |
83 | 72 |
84 void BackgroundSyncContextImpl::ShutdownOnIO() { | 73 void BackgroundSyncContextImpl::ShutdownOnIO() { |
85 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 74 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
86 | 75 |
87 STLDeleteElements(&services_); | 76 services_.Clear(); |
88 background_sync_manager_.reset(); | 77 background_sync_manager_.reset(); |
89 } | 78 } |
90 | 79 |
91 } // namespace content | 80 } // namespace content |
OLD | NEW |