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

Unified Diff: device/bluetooth/bluetooth_adapter_android.cc

Issue 2244693002: bluetooth: Refactor how we update based on Advertising Data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix arc Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/bluetooth_adapter_android.cc
diff --git a/device/bluetooth/bluetooth_adapter_android.cc b/device/bluetooth/bluetooth_adapter_android.cc
index ec9d0f88f0de201263362f88c46a6fb0356983b8..397257303e21b03b254ffc3c85b10a13d1f6e52f 100644
--- a/device/bluetooth/bluetooth_adapter_android.cc
+++ b/device/bluetooth/bluetooth_adapter_android.cc
@@ -7,6 +7,7 @@
#include <memory>
#include "base/android/jni_android.h"
+#include "base/android/jni_array.h"
#include "base/android/jni_string.h"
#include "base/bind.h"
#include "base/location.h"
@@ -21,6 +22,7 @@
using base::android::AttachCurrentThread;
using base::android::ConvertJavaStringToUTF8;
+using base::android::AppendJavaStringArrayToStringVector;
using base::android::JavaParamRef;
namespace {
@@ -187,23 +189,32 @@ void BluetoothAdapterAndroid::CreateOrUpdateDeviceOnScan(
std::string device_address = ConvertJavaStringToUTF8(env, address);
DevicesMap::const_iterator iter = devices_.find(device_address);
+ bool is_new_device = false;
+ BluetoothDeviceAndroid* device_android;
Jeffrey Yasskin 2016/08/18 16:04:33 To track ownership more clearly, I might write thi
ortuno 2016/08/19 20:50:33 Done.
+
if (iter == devices_.end()) {
// New device.
- BluetoothDeviceAndroid* device_android =
+ is_new_device = true;
+ device_android =
BluetoothDeviceAndroid::Create(this, bluetooth_device_wrapper);
- device_android->UpdateAdvertisedUUIDs(advertised_uuids);
- device_android->UpdateTimestamp();
+ } else {
+ // Existing device.
+ device_android = static_cast<BluetoothDeviceAndroid*>(iter->second);
+ }
+ DCHECK(device_android);
+ std::vector<std::string> advertised_uuids_strings;
+ AppendJavaStringArrayToStringVector(env, advertised_uuids,
Jeffrey Yasskin 2016/08/18 16:04:32 You're passing a List<ParcelUuid> to a function th
ortuno 2016/08/19 20:50:33 Changed the comment to String[]. Done.
+ &advertised_uuids_strings);
+
+ device_android->UpdateAdvertisementData(std::move(advertised_uuids_strings),
Jeffrey Yasskin 2016/08/18 16:04:33 I'm skeptical of having a single function that upd
ortuno 2016/08/19 20:50:33 I like having a compile time check to make sure al
Jeffrey Yasskin 2016/08/19 22:08:09 'k.
+ {} /* service_data */);
+
+ if (is_new_device) {
devices_.add(device_address,
std::unique_ptr<BluetoothDevice>(device_android));
FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
DeviceAdded(this, device_android));
} else {
- // Existing device.
- BluetoothDeviceAndroid* device_android =
- static_cast<BluetoothDeviceAndroid*>(iter->second);
- device_android->UpdateTimestamp();
- device_android->UpdateAdvertisedUUIDs(advertised_uuids);
-
FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
DeviceChanged(this, device_android));
}
@@ -282,6 +293,9 @@ void BluetoothAdapterAndroid::RemoveDiscoverySession(
VLOG(1) << "RemoveDiscoverySession: Now 0 sessions. Stopping scan.";
session_removed = Java_ChromeBluetoothAdapter_stopScan(
AttachCurrentThread(), j_adapter_);
+ for (const auto& device_id_object_pair : devices_) {
+ device_id_object_pair.second->ClearAdvertisementData();
+ }
} else {
VLOG(1) << "RemoveDiscoverySession: Now "
<< unsigned(num_discovery_sessions_) << " sessions.";

Powered by Google App Engine
This is Rietveld 408576698