OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/api/dial/dial_registry.h" | 5 #include "chrome/browser/extensions/api/dial/dial_registry.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 } | 153 } |
154 | 154 |
155 bool DialRegistry::PruneExpiredDevices() { | 155 bool DialRegistry::PruneExpiredDevices() { |
156 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 156 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
157 bool pruned_device = false; | 157 bool pruned_device = false; |
158 DeviceByLabelMap::iterator it = device_by_label_map_.begin(); | 158 DeviceByLabelMap::iterator it = device_by_label_map_.begin(); |
159 while (it != device_by_label_map_.end()) { | 159 while (it != device_by_label_map_.end()) { |
160 auto* device = it->second; | 160 auto* device = it->second; |
161 if (IsDeviceExpired(*device)) { | 161 if (IsDeviceExpired(*device)) { |
162 VLOG(2) << "Device " << device->label() << " expired, removing"; | 162 VLOG(2) << "Device " << device->label() << " expired, removing"; |
163 const size_t num_erased_by_id = | 163 |
164 device_by_id_map_.erase(device->device_id()); | 164 // Make a copy of the device ID here since |device| will be destroyed |
165 // during erase(). | |
166 std::string device_id = device->device_id(); | |
miu
2016/10/22 18:37:19
nit: Probably not a big deal for performance, but
| |
167 const size_t num_erased_by_id = device_by_id_map_.erase(device_id); | |
Wez
2016/10/22 00:55:39
As discussed offline... wow, really surprised that
| |
165 DCHECK_EQ(1U, num_erased_by_id); | 168 DCHECK_EQ(1U, num_erased_by_id); |
166 device_by_label_map_.erase(it++); | 169 device_by_label_map_.erase(it++); |
167 pruned_device = true; | 170 pruned_device = true; |
168 } else { | 171 } else { |
169 ++it; | 172 ++it; |
170 } | 173 } |
171 } | 174 } |
172 return pruned_device; | 175 return pruned_device; |
173 } | 176 } |
174 | 177 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
325 case NetworkChangeNotifier::CONNECTION_BLUETOOTH: | 328 case NetworkChangeNotifier::CONNECTION_BLUETOOTH: |
326 if (!dial_) { | 329 if (!dial_) { |
327 VLOG(2) << "Connection detected, restarting discovery."; | 330 VLOG(2) << "Connection detected, restarting discovery."; |
328 StartPeriodicDiscovery(); | 331 StartPeriodicDiscovery(); |
329 } | 332 } |
330 break; | 333 break; |
331 } | 334 } |
332 } | 335 } |
333 | 336 |
334 } // namespace extensions | 337 } // namespace extensions |
OLD | NEW |