| 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 "chromeos/components/tether/tether_host_fetcher.h" | 5 #include "chromeos/components/tether/tether_host_fetcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "components/cryptauth/cryptauth_device_manager.h" | 9 #include "components/cryptauth/cryptauth_device_manager.h" |
| 10 #include "components/cryptauth/remote_device_loader.h" | 10 #include "components/cryptauth/remote_device_loader.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 78 |
| 79 // Make a copy of the requests to ensure that if one of the callbacks makes a | 79 // Make a copy of the requests to ensure that if one of the callbacks makes a |
| 80 // new fetch request, it does not affect the iteration of requests. | 80 // new fetch request, it does not affect the iteration of requests. |
| 81 std::vector<TetherHostFetchRequest> requests = requests_; | 81 std::vector<TetherHostFetchRequest> requests = requests_; |
| 82 requests_.clear(); | 82 requests_.clear(); |
| 83 | 83 |
| 84 for (auto& request : requests) { | 84 for (auto& request : requests) { |
| 85 if (request.device_id.empty()) { | 85 if (request.device_id.empty()) { |
| 86 DCHECK(!request.list_callback.is_null()); | 86 DCHECK(!request.list_callback.is_null()); |
| 87 | 87 |
| 88 request.list_callback.Run(remote_devices); | 88 request.list_callback.Run(remote_devices_copy); |
| 89 continue; | 89 continue; |
| 90 } | 90 } |
| 91 | 91 |
| 92 DCHECK(!request.single_callback.is_null()); | 92 DCHECK(!request.single_callback.is_null()); |
| 93 bool has_run_callback = false; | 93 bool has_run_callback = false; |
| 94 for (const auto& remote_device : remote_devices_copy) { | 94 for (const auto& remote_device : remote_devices_copy) { |
| 95 if (request.device_id == remote_device.GetDeviceId()) { | 95 if (request.device_id == remote_device.GetDeviceId()) { |
| 96 has_run_callback = true; | 96 has_run_callback = true; |
| 97 request.single_callback.Run( | 97 request.single_callback.Run( |
| 98 base::MakeUnique<cryptauth::RemoteDevice>(remote_device)); | 98 base::MakeUnique<cryptauth::RemoteDevice>(remote_device)); |
| 99 break; | 99 break; |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 if (!has_run_callback) { | 103 if (!has_run_callback) { |
| 104 request.single_callback.Run(nullptr); | 104 request.single_callback.Run(nullptr); |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 | 108 |
| 109 } // namespace tether | 109 } // namespace tether |
| 110 | 110 |
| 111 } // namespace chromeos | 111 } // namespace chromeos |
| OLD | NEW |