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.h" | 5 #include "content/browser/background_sync/background_sync_context.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/ptr_util.h" |
10 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
11 #include "content/browser/background_sync/background_sync_manager.h" | 12 #include "content/browser/background_sync/background_sync_manager.h" |
12 #include "content/browser/background_sync/background_sync_service_impl.h" | 13 #include "content/browser/background_sync/background_sync_service_impl.h" |
13 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 14 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 | 18 |
18 BackgroundSyncContext::BackgroundSyncContext() { | 19 BackgroundSyncContext::BackgroundSyncContext() { |
19 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 20 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
(...skipping 28 matching lines...) Expand all Loading... |
48 | 49 |
49 BrowserThread::PostTask( | 50 BrowserThread::PostTask( |
50 BrowserThread::IO, FROM_HERE, | 51 BrowserThread::IO, FROM_HERE, |
51 base::Bind(&BackgroundSyncContext::CreateServiceOnIOThread, this, | 52 base::Bind(&BackgroundSyncContext::CreateServiceOnIOThread, this, |
52 base::Passed(&request))); | 53 base::Passed(&request))); |
53 } | 54 } |
54 | 55 |
55 void BackgroundSyncContext::ServiceHadConnectionError( | 56 void BackgroundSyncContext::ServiceHadConnectionError( |
56 BackgroundSyncServiceImpl* service) { | 57 BackgroundSyncServiceImpl* service) { |
57 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 58 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
58 DCHECK(base::ContainsValue(services_, service)); | 59 DCHECK(base::ContainsKey(services_, service)); |
59 | 60 |
60 services_.erase(service); | 61 services_.erase(service); |
61 delete service; | |
62 } | 62 } |
63 | 63 |
64 BackgroundSyncManager* BackgroundSyncContext::background_sync_manager() const { | 64 BackgroundSyncManager* BackgroundSyncContext::background_sync_manager() const { |
65 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 65 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
66 | 66 |
67 return background_sync_manager_.get(); | 67 return background_sync_manager_.get(); |
68 } | 68 } |
69 | 69 |
70 void BackgroundSyncContext::set_background_sync_manager_for_testing( | 70 void BackgroundSyncContext::set_background_sync_manager_for_testing( |
71 std::unique_ptr<BackgroundSyncManager> manager) { | 71 std::unique_ptr<BackgroundSyncManager> manager) { |
72 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 72 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
73 | 73 |
74 background_sync_manager_ = std::move(manager); | 74 background_sync_manager_ = std::move(manager); |
75 } | 75 } |
76 | 76 |
77 void BackgroundSyncContext::CreateBackgroundSyncManager( | 77 void BackgroundSyncContext::CreateBackgroundSyncManager( |
78 scoped_refptr<ServiceWorkerContextWrapper> context) { | 78 scoped_refptr<ServiceWorkerContextWrapper> context) { |
79 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 79 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
80 DCHECK(!background_sync_manager_); | 80 DCHECK(!background_sync_manager_); |
81 | 81 |
82 background_sync_manager_ = BackgroundSyncManager::Create(context); | 82 background_sync_manager_ = BackgroundSyncManager::Create(context); |
83 } | 83 } |
84 | 84 |
85 void BackgroundSyncContext::CreateServiceOnIOThread( | 85 void BackgroundSyncContext::CreateServiceOnIOThread( |
86 mojo::InterfaceRequest<blink::mojom::BackgroundSyncService> request) { | 86 mojo::InterfaceRequest<blink::mojom::BackgroundSyncService> request) { |
87 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 87 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
88 DCHECK(background_sync_manager_); | 88 DCHECK(background_sync_manager_); |
89 services_.insert(new BackgroundSyncServiceImpl(this, std::move(request))); | 89 BackgroundSyncServiceImpl* service = |
| 90 new BackgroundSyncServiceImpl(this, std::move(request)); |
| 91 services_[service] = base::WrapUnique(service); |
90 } | 92 } |
91 | 93 |
92 void BackgroundSyncContext::ShutdownOnIO() { | 94 void BackgroundSyncContext::ShutdownOnIO() { |
93 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 95 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
94 | 96 |
95 base::STLDeleteElements(&services_); | 97 services_.clear(); |
96 background_sync_manager_.reset(); | 98 background_sync_manager_.reset(); |
97 } | 99 } |
98 | 100 |
99 } // namespace content | 101 } // namespace content |
OLD | NEW |