Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Side by Side Diff: device/bluetooth/bluetooth_adapter_android.cc

Issue 1842223003: Remove outdated devices from Android device chooser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased on master Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "device/bluetooth/bluetooth_adapter_android.h" 5 #include "device/bluetooth/bluetooth_adapter_android.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
11 #include "base/bind.h"
12 #include "base/location.h"
11 #include "base/sequenced_task_runner.h" 13 #include "base/sequenced_task_runner.h"
12 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
13 #include "base/thread_task_runner_handle.h" 15 #include "base/thread_task_runner_handle.h"
14 #include "device/bluetooth/android/wrappers.h" 16 #include "device/bluetooth/android/wrappers.h"
15 #include "device/bluetooth/bluetooth_advertisement.h" 17 #include "device/bluetooth/bluetooth_advertisement.h"
16 #include "device/bluetooth/bluetooth_device_android.h" 18 #include "device/bluetooth/bluetooth_device_android.h"
17 #include "device/bluetooth/bluetooth_discovery_session_outcome.h" 19 #include "device/bluetooth/bluetooth_discovery_session_outcome.h"
18 #include "jni/ChromeBluetoothAdapter_jni.h" 20 #include "jni/ChromeBluetoothAdapter_jni.h"
19 21
20 using base::android::AttachCurrentThread; 22 using base::android::AttachCurrentThread;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 const JavaParamRef<jobject>& 165 const JavaParamRef<jobject>&
164 advertised_uuids) { // Java Type: List<ParcelUuid> 166 advertised_uuids) { // Java Type: List<ParcelUuid>
165 std::string device_address = ConvertJavaStringToUTF8(env, address); 167 std::string device_address = ConvertJavaStringToUTF8(env, address);
166 DevicesMap::const_iterator iter = devices_.find(device_address); 168 DevicesMap::const_iterator iter = devices_.find(device_address);
167 169
168 if (iter == devices_.end()) { 170 if (iter == devices_.end()) {
169 // New device. 171 // New device.
170 BluetoothDeviceAndroid* device_android = 172 BluetoothDeviceAndroid* device_android =
171 BluetoothDeviceAndroid::Create(this, bluetooth_device_wrapper); 173 BluetoothDeviceAndroid::Create(this, bluetooth_device_wrapper);
172 device_android->UpdateAdvertisedUUIDs(advertised_uuids); 174 device_android->UpdateAdvertisedUUIDs(advertised_uuids);
175 device_android->UpdateTimestamp();
173 devices_.add(device_address, 176 devices_.add(device_address,
174 std::unique_ptr<BluetoothDevice>(device_android)); 177 std::unique_ptr<BluetoothDevice>(device_android));
175 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 178 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
176 DeviceAdded(this, device_android)); 179 DeviceAdded(this, device_android));
177 } else { 180 } else {
178 // Existing device. 181 // Existing device.
179 BluetoothDeviceAndroid* device_android = 182 BluetoothDeviceAndroid* device_android =
180 static_cast<BluetoothDeviceAndroid*>(iter->second); 183 static_cast<BluetoothDeviceAndroid*>(iter->second);
184 device_android->UpdateTimestamp();
181 if (device_android->UpdateAdvertisedUUIDs(advertised_uuids)) { 185 if (device_android->UpdateAdvertisedUUIDs(advertised_uuids)) {
182 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 186 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
183 DeviceChanged(this, device_android)); 187 DeviceChanged(this, device_android));
184 } 188 }
185 } 189 }
186 } 190 }
187 191
188 BluetoothAdapterAndroid::BluetoothAdapterAndroid() : weak_ptr_factory_(this) { 192 BluetoothAdapterAndroid::BluetoothAdapterAndroid() : weak_ptr_factory_(this) {
193 ui_task_runner_ = base::ThreadTaskRunnerHandle::Get();
194 PurgeTimedOutDevices();
189 } 195 }
190 196
191 BluetoothAdapterAndroid::~BluetoothAdapterAndroid() { 197 BluetoothAdapterAndroid::~BluetoothAdapterAndroid() {
192 Java_ChromeBluetoothAdapter_onBluetoothAdapterAndroidDestruction( 198 Java_ChromeBluetoothAdapter_onBluetoothAdapterAndroidDestruction(
193 AttachCurrentThread(), j_adapter_.obj()); 199 AttachCurrentThread(), j_adapter_.obj());
194 } 200 }
195 201
202 void BluetoothAdapterAndroid::PurgeTimedOutDevices() {
203 RemoveTimedOutDevices();
204 ui_task_runner_->PostDelayedTask(
205 FROM_HERE, base::Bind(&BluetoothAdapterAndroid::PurgeTimedOutDevices,
206 weak_ptr_factory_.GetWeakPtr()),
207 base::TimeDelta::FromMilliseconds(5000));
208 }
209
196 void BluetoothAdapterAndroid::AddDiscoverySession( 210 void BluetoothAdapterAndroid::AddDiscoverySession(
197 BluetoothDiscoveryFilter* discovery_filter, 211 BluetoothDiscoveryFilter* discovery_filter,
198 const base::Closure& callback, 212 const base::Closure& callback,
199 const DiscoverySessionErrorCallback& error_callback) { 213 const DiscoverySessionErrorCallback& error_callback) {
200 // TODO(scheib): Support filters crbug.com/490401 214 // TODO(scheib): Support filters crbug.com/490401
201 if (Java_ChromeBluetoothAdapter_addDiscoverySession(AttachCurrentThread(), 215 if (Java_ChromeBluetoothAdapter_addDiscoverySession(AttachCurrentThread(),
202 j_adapter_.obj())) { 216 j_adapter_.obj())) {
203 callback.Run(); 217 callback.Run();
204 } else { 218 } else {
205 // TODO(scheib): Eventually wire the SCAN_FAILED result through to here. 219 // TODO(scheib): Eventually wire the SCAN_FAILED result through to here.
(...skipping 21 matching lines...) Expand all
227 // TODO(scheib): Support filters crbug.com/490401 241 // TODO(scheib): Support filters crbug.com/490401
228 NOTIMPLEMENTED(); 242 NOTIMPLEMENTED();
229 error_callback.Run(UMABluetoothDiscoverySessionOutcome::NOT_IMPLEMENTED); 243 error_callback.Run(UMABluetoothDiscoverySessionOutcome::NOT_IMPLEMENTED);
230 } 244 }
231 245
232 void BluetoothAdapterAndroid::RemovePairingDelegateInternal( 246 void BluetoothAdapterAndroid::RemovePairingDelegateInternal(
233 device::BluetoothDevice::PairingDelegate* pairing_delegate) { 247 device::BluetoothDevice::PairingDelegate* pairing_delegate) {
234 } 248 }
235 249
236 } // namespace device 250 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698