OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "services/preferences/public/cpp/pref_store_manager_impl.h" | 5 #include "services/preferences/public/cpp/pref_store_manager_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 }; | 51 }; |
52 | 52 |
53 // static | 53 // static |
54 void ConnectionBarrier::Create(const PrefStorePtrs& pref_store_ptrs, | 54 void ConnectionBarrier::Create(const PrefStorePtrs& pref_store_ptrs, |
55 const ConnectCallback& callback) { | 55 const ConnectCallback& callback) { |
56 make_scoped_refptr(new ConnectionBarrier(pref_store_ptrs, callback)) | 56 make_scoped_refptr(new ConnectionBarrier(pref_store_ptrs, callback)) |
57 ->Init(pref_store_ptrs); | 57 ->Init(pref_store_ptrs); |
58 } | 58 } |
59 | 59 |
60 void ConnectionBarrier::Init(const PrefStorePtrs& pref_store_ptrs) { | 60 void ConnectionBarrier::Init(const PrefStorePtrs& pref_store_ptrs) { |
| 61 if (expected_connections_ == 0) { |
| 62 // Degenerate case. We don't expect this, but it could happen in |
| 63 // e.g. testing. |
| 64 callback_.Run(std::move(connections_)); |
| 65 return; |
| 66 } |
61 for (const auto& ptr : pref_store_ptrs) { | 67 for (const auto& ptr : pref_store_ptrs) { |
62 ptr.second->AddObserver( | 68 ptr.second->AddObserver( |
63 base::Bind(&ConnectionBarrier::OnConnect, this, ptr.first)); | 69 base::Bind(&ConnectionBarrier::OnConnect, this, ptr.first)); |
64 } | 70 } |
65 } | 71 } |
66 | 72 |
67 ConnectionBarrier::ConnectionBarrier(const PrefStorePtrs& pref_store_ptrs, | 73 ConnectionBarrier::ConnectionBarrier(const PrefStorePtrs& pref_store_ptrs, |
68 const ConnectCallback& callback) | 74 const ConnectCallback& callback) |
69 : callback_(callback), expected_connections_(pref_store_ptrs.size()) {} | 75 : callback_(callback), expected_connections_(pref_store_ptrs.size()) {} |
70 | 76 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 PrefValueStore::PrefStoreType type) { | 191 PrefValueStore::PrefStoreType type) { |
186 DVLOG(1) << "Deregistering pref store: " << type; | 192 DVLOG(1) << "Deregistering pref store: " << type; |
187 pref_store_ptrs_.erase(type); | 193 pref_store_ptrs_.erase(type); |
188 } | 194 } |
189 | 195 |
190 bool PrefStoreManagerImpl::AllConnected() const { | 196 bool PrefStoreManagerImpl::AllConnected() const { |
191 return pref_store_ptrs_.size() == expected_pref_stores_.size(); | 197 return pref_store_ptrs_.size() == expected_pref_stores_.size(); |
192 } | 198 } |
193 | 199 |
194 } // namespace prefs | 200 } // namespace prefs |
OLD | NEW |