Commit 1ef7dd4b authored by juncai's avatar juncai Committed by Commit bot

Use new wrapper types for web_bluetooth.mojom

This CL modified code to use new wrapper types for web_bluetooth.mojom.
Also changed all instances of mojo::Array, mojo::String to std::vector,
std::string since mojo::Array, mojo::String have been deprecated.

BUG=597053

Review-Url: https://codereview.chromium.org/2506813003
Cr-Commit-Position: refs/heads/master@{#434892}
parent 45280ea9
...@@ -192,7 +192,7 @@ android_library("chrome_java") { ...@@ -192,7 +192,7 @@ android_library("chrome_java") {
"//services/service_manager/public/java:service_manager_java", "//services/service_manager/public/java:service_manager_java",
"//third_party/WebKit/public:android_mojo_bindings_java", "//third_party/WebKit/public:android_mojo_bindings_java",
"//third_party/WebKit/public:blink_headers_java", "//third_party/WebKit/public:blink_headers_java",
"//third_party/WebKit/public:new_wrapper_types_mojo_bindings_java", "//third_party/WebKit/public:mojo_bindings_java",
"//third_party/android_data_chart:android_data_chart_java", "//third_party/android_data_chart:android_data_chart_java",
"//third_party/android_media:android_media_java", "//third_party/android_media:android_media_java",
"//third_party/android_protobuf:protobuf_nano_javalib", "//third_party/android_protobuf:protobuf_nano_javalib",
......
...@@ -167,12 +167,16 @@ void BluetoothAllowedDevicesMap::AddUnionOfServicesTo( ...@@ -167,12 +167,16 @@ void BluetoothAllowedDevicesMap::AddUnionOfServicesTo(
std::unordered_set<BluetoothUUID, device::BluetoothUUIDHash>* std::unordered_set<BluetoothUUID, device::BluetoothUUIDHash>*
unionOfServices) { unionOfServices) {
for (const auto& filter : options->filters) { for (const auto& filter : options->filters) {
for (const base::Optional<BluetoothUUID>& uuid : filter->services) { if (!filter->services) {
unionOfServices->insert(uuid.value()); continue;
}
for (const BluetoothUUID& uuid : filter->services.value()) {
unionOfServices->insert(uuid);
} }
} }
for (const base::Optional<BluetoothUUID>& uuid : options->optional_services) { for (const BluetoothUUID& uuid : options->optional_services) {
unionOfServices->insert(uuid.value()); unionOfServices->insert(uuid);
} }
} }
......
...@@ -187,11 +187,11 @@ TEST_F(BluetoothAllowedDevicesMapTest, NoPermissionForAnyService) { ...@@ -187,11 +187,11 @@ TEST_F(BluetoothAllowedDevicesMapTest, NoPermissionForAnyService) {
// Setup device. // Setup device.
blink::mojom::WebBluetoothRequestDeviceOptionsPtr options = blink::mojom::WebBluetoothRequestDeviceOptionsPtr options =
blink::mojom::WebBluetoothRequestDeviceOptions::New(); blink::mojom::WebBluetoothRequestDeviceOptions::New();
blink::mojom::WebBluetoothScanFilterPtr scanFilter = blink::mojom::WebBluetoothScanFilterPtr scan_filter =
blink::mojom::WebBluetoothScanFilter::New(); blink::mojom::WebBluetoothScanFilter::New();
scanFilter->name = kDeviceName; scan_filter->name = kDeviceName;
options->filters.push_back(scanFilter.Clone()); options->filters.push_back(scan_filter.Clone());
// Add to map. // Add to map.
const WebBluetoothDeviceId device_id = const WebBluetoothDeviceId device_id =
...@@ -210,16 +210,18 @@ TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_OneOriginOneDevice) { ...@@ -210,16 +210,18 @@ TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_OneOriginOneDevice) {
// Setup device. // Setup device.
blink::mojom::WebBluetoothRequestDeviceOptionsPtr options = blink::mojom::WebBluetoothRequestDeviceOptionsPtr options =
blink::mojom::WebBluetoothRequestDeviceOptions::New(); blink::mojom::WebBluetoothRequestDeviceOptions::New();
blink::mojom::WebBluetoothScanFilterPtr scanFilter1 = blink::mojom::WebBluetoothScanFilterPtr scan_filter1 =
blink::mojom::WebBluetoothScanFilter::New(); blink::mojom::WebBluetoothScanFilter::New();
blink::mojom::WebBluetoothScanFilterPtr scanFilter2 = blink::mojom::WebBluetoothScanFilterPtr scan_filter2 =
blink::mojom::WebBluetoothScanFilter::New(); blink::mojom::WebBluetoothScanFilter::New();
scanFilter1->services.push_back(kGlucoseUUID); scan_filter1->services.emplace();
options->filters.push_back(scanFilter1.Clone()); scan_filter1->services->push_back(kGlucoseUUID);
options->filters.push_back(scan_filter1.Clone());
scanFilter2->services.push_back(kHeartRateUUID); scan_filter2->services.emplace();
options->filters.push_back(scanFilter2.Clone()); scan_filter2->services->push_back(kHeartRateUUID);
options->filters.push_back(scan_filter2.Clone());
options->optional_services.push_back(kBatteryServiceUUID); options->optional_services.push_back(kBatteryServiceUUID);
options->optional_services.push_back(kHeartRateUUID); options->optional_services.push_back(kHeartRateUUID);
...@@ -258,8 +260,8 @@ TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_OneOriginOneDevice) { ...@@ -258,8 +260,8 @@ TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_OneOriginOneDevice) {
blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 = blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 =
blink::mojom::WebBluetoothRequestDeviceOptions::New(); blink::mojom::WebBluetoothRequestDeviceOptions::New();
options2->filters.push_back(scanFilter1.Clone()); options2->filters.push_back(scan_filter1.Clone());
options2->filters.push_back(scanFilter2.Clone()); options2->filters.push_back(scan_filter2.Clone());
const WebBluetoothDeviceId device_id2 = const WebBluetoothDeviceId device_id2 =
allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options2); allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options2);
...@@ -291,22 +293,24 @@ TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_OneOriginTwoDevices) { ...@@ -291,22 +293,24 @@ TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_OneOriginTwoDevices) {
// Setup request for device #1. // Setup request for device #1.
blink::mojom::WebBluetoothRequestDeviceOptionsPtr options1 = blink::mojom::WebBluetoothRequestDeviceOptionsPtr options1 =
blink::mojom::WebBluetoothRequestDeviceOptions::New(); blink::mojom::WebBluetoothRequestDeviceOptions::New();
blink::mojom::WebBluetoothScanFilterPtr scanFilter1 = blink::mojom::WebBluetoothScanFilterPtr scan_filter1 =
blink::mojom::WebBluetoothScanFilter::New(); blink::mojom::WebBluetoothScanFilter::New();
scanFilter1->services.push_back(kGlucoseUUID); scan_filter1->services.emplace();
options1->filters.push_back(std::move(scanFilter1)); scan_filter1->services->push_back(kGlucoseUUID);
options1->filters.push_back(std::move(scan_filter1));
options1->optional_services.push_back(kHeartRateUUID); options1->optional_services.push_back(kHeartRateUUID);
// Setup request for device #2. // Setup request for device #2.
blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 = blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 =
blink::mojom::WebBluetoothRequestDeviceOptions::New(); blink::mojom::WebBluetoothRequestDeviceOptions::New();
blink::mojom::WebBluetoothScanFilterPtr scanFilter2 = blink::mojom::WebBluetoothScanFilterPtr scan_filter2 =
blink::mojom::WebBluetoothScanFilter::New(); blink::mojom::WebBluetoothScanFilter::New();
scanFilter2->services.push_back(kBatteryServiceUUID); scan_filter2->services.emplace();
options2->filters.push_back(std::move(scanFilter2)); scan_filter2->services->push_back(kBatteryServiceUUID);
options2->filters.push_back(std::move(scan_filter2));
options2->optional_services.push_back(kBloodPressureUUID); options2->optional_services.push_back(kBloodPressureUUID);
...@@ -352,22 +356,24 @@ TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_TwoOriginsOneDevice) { ...@@ -352,22 +356,24 @@ TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_TwoOriginsOneDevice) {
// Setup request #1 for device. // Setup request #1 for device.
blink::mojom::WebBluetoothRequestDeviceOptionsPtr options1 = blink::mojom::WebBluetoothRequestDeviceOptionsPtr options1 =
blink::mojom::WebBluetoothRequestDeviceOptions::New(); blink::mojom::WebBluetoothRequestDeviceOptions::New();
blink::mojom::WebBluetoothScanFilterPtr scanFilter1 = blink::mojom::WebBluetoothScanFilterPtr scan_filter1 =
blink::mojom::WebBluetoothScanFilter::New(); blink::mojom::WebBluetoothScanFilter::New();
scanFilter1->services.push_back(kGlucoseUUID); scan_filter1->services.emplace();
options1->filters.push_back(std::move(scanFilter1)); scan_filter1->services->push_back(kGlucoseUUID);
options1->filters.push_back(std::move(scan_filter1));
options1->optional_services.push_back(kHeartRateUUID); options1->optional_services.push_back(kHeartRateUUID);
// Setup request #2 for device. // Setup request #2 for device.
blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 = blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 =
blink::mojom::WebBluetoothRequestDeviceOptions::New(); blink::mojom::WebBluetoothRequestDeviceOptions::New();
blink::mojom::WebBluetoothScanFilterPtr scanFilter2 = blink::mojom::WebBluetoothScanFilterPtr scan_filter2 =
blink::mojom::WebBluetoothScanFilter::New(); blink::mojom::WebBluetoothScanFilter::New();
scanFilter2->services.push_back(kBatteryServiceUUID); scan_filter2->services.emplace();
options2->filters.push_back(std::move(scanFilter2)); scan_filter2->services->push_back(kBatteryServiceUUID);
options2->filters.push_back(std::move(scan_filter2));
options2->optional_services.push_back(kBloodPressureUUID); options2->optional_services.push_back(kBloodPressureUUID);
...@@ -432,11 +438,12 @@ TEST_F(BluetoothAllowedDevicesMapTest, MergeServices) { ...@@ -432,11 +438,12 @@ TEST_F(BluetoothAllowedDevicesMapTest, MergeServices) {
// Setup first request. // Setup first request.
blink::mojom::WebBluetoothRequestDeviceOptionsPtr options1 = blink::mojom::WebBluetoothRequestDeviceOptionsPtr options1 =
blink::mojom::WebBluetoothRequestDeviceOptions::New(); blink::mojom::WebBluetoothRequestDeviceOptions::New();
blink::mojom::WebBluetoothScanFilterPtr scanFilter1 = blink::mojom::WebBluetoothScanFilterPtr scan_filter1 =
blink::mojom::WebBluetoothScanFilter::New(); blink::mojom::WebBluetoothScanFilter::New();
scanFilter1->services.push_back(kGlucoseUUID); scan_filter1->services.emplace();
options1->filters.push_back(std::move(scanFilter1)); scan_filter1->services->push_back(kGlucoseUUID);
options1->filters.push_back(std::move(scan_filter1));
options1->optional_services.push_back(kBatteryServiceUUID); options1->optional_services.push_back(kBatteryServiceUUID);
...@@ -447,11 +454,12 @@ TEST_F(BluetoothAllowedDevicesMapTest, MergeServices) { ...@@ -447,11 +454,12 @@ TEST_F(BluetoothAllowedDevicesMapTest, MergeServices) {
// Setup second request. // Setup second request.
blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 = blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 =
blink::mojom::WebBluetoothRequestDeviceOptions::New(); blink::mojom::WebBluetoothRequestDeviceOptions::New();
blink::mojom::WebBluetoothScanFilterPtr scanFilter2 = blink::mojom::WebBluetoothScanFilterPtr scan_filter2 =
blink::mojom::WebBluetoothScanFilter::New(); blink::mojom::WebBluetoothScanFilter::New();
scanFilter2->services.push_back(kHeartRateUUID); scan_filter2->services.emplace();
options2->filters.push_back(std::move(scanFilter2)); scan_filter2->services->push_back(kHeartRateUUID);
options2->filters.push_back(std::move(scan_filter2));
options2->optional_services.push_back(kBloodPressureUUID); options2->optional_services.push_back(kBloodPressureUUID);
...@@ -482,4 +490,23 @@ TEST_F(BluetoothAllowedDevicesMapTest, CorrectIdFormat) { ...@@ -482,4 +490,23 @@ TEST_F(BluetoothAllowedDevicesMapTest, CorrectIdFormat) {
EXPECT_TRUE(WebBluetoothDeviceId::IsValid(device_id.str())); EXPECT_TRUE(WebBluetoothDeviceId::IsValid(device_id.str()));
} }
TEST_F(BluetoothAllowedDevicesMapTest, NoFilterServices) {
BluetoothAllowedDevicesMap allowed_devices_map;
// Setup request.
blink::mojom::WebBluetoothRequestDeviceOptionsPtr options =
blink::mojom::WebBluetoothRequestDeviceOptions::New();
blink::mojom::WebBluetoothScanFilterPtr scan_filter =
blink::mojom::WebBluetoothScanFilter::New();
options->filters.push_back(std::move(scan_filter));
// Add to map.
const WebBluetoothDeviceId device_id =
allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options);
EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessAtLeastOneService(
kTestOrigin1, device_id));
}
} // namespace content } // namespace content
...@@ -86,10 +86,13 @@ bool BluetoothBlocklist::IsExcluded(const BluetoothUUID& uuid) const { ...@@ -86,10 +86,13 @@ bool BluetoothBlocklist::IsExcluded(const BluetoothUUID& uuid) const {
} }
bool BluetoothBlocklist::IsExcluded( bool BluetoothBlocklist::IsExcluded(
const mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>& filters) { const std::vector<blink::mojom::WebBluetoothScanFilterPtr>& filters) {
for (const blink::mojom::WebBluetoothScanFilterPtr& filter : filters) { for (const blink::mojom::WebBluetoothScanFilterPtr& filter : filters) {
for (const base::Optional<BluetoothUUID>& service : filter->services) { if (!filter->services) {
if (IsExcluded(service.value())) { continue;
}
for (const BluetoothUUID& service : filter->services.value()) {
if (IsExcluded(service)) {
return true; return true;
} }
} }
...@@ -115,10 +118,9 @@ bool BluetoothBlocklist::IsExcludedFromWrites(const BluetoothUUID& uuid) const { ...@@ -115,10 +118,9 @@ bool BluetoothBlocklist::IsExcludedFromWrites(const BluetoothUUID& uuid) const {
void BluetoothBlocklist::RemoveExcludedUUIDs( void BluetoothBlocklist::RemoveExcludedUUIDs(
blink::mojom::WebBluetoothRequestDeviceOptions* options) { blink::mojom::WebBluetoothRequestDeviceOptions* options) {
mojo::Array<base::Optional<BluetoothUUID>> std::vector<device::BluetoothUUID> optional_services_blocklist_filtered;
optional_services_blocklist_filtered; for (const BluetoothUUID& uuid : options->optional_services) {
for (const base::Optional<BluetoothUUID>& uuid : options->optional_services) { if (!IsExcluded(uuid)) {
if (!IsExcluded(uuid.value())) {
optional_services_blocklist_filtered.push_back(uuid); optional_services_blocklist_filtered.push_back(uuid);
} }
} }
......
...@@ -65,7 +65,7 @@ class CONTENT_EXPORT BluetoothBlocklist final { ...@@ -65,7 +65,7 @@ class CONTENT_EXPORT BluetoothBlocklist final {
// Returns if any UUID in a set of filters is excluded from all operations. // Returns if any UUID in a set of filters is excluded from all operations.
// UUID must be valid. // UUID must be valid.
bool IsExcluded( bool IsExcluded(
const mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>& filters); const std::vector<blink::mojom::WebBluetoothScanFilterPtr>& filters);
// Returns if a UUID is excluded from read operations. UUID must be valid. // Returns if a UUID is excluded from read operations. UUID must be valid.
bool IsExcludedFromReads(const device::BluetoothUUID&) const; bool IsExcludedFromReads(const device::BluetoothUUID&) const;
......
...@@ -64,17 +64,17 @@ void LogRequestDeviceOptions( ...@@ -64,17 +64,17 @@ void LogRequestDeviceOptions(
int i = 0; int i = 0;
for (const auto& filter : options->filters) { for (const auto& filter : options->filters) {
VLOG(1) << "Filter #" << ++i; VLOG(1) << "Filter #" << ++i;
if (!filter->name.is_null()) if (filter->name)
VLOG(1) << "Name: " << filter->name; VLOG(1) << "Name: " << filter->name.value();
if (!filter->name_prefix.is_null()) if (filter->name_prefix)
VLOG(1) << "Name Prefix: " << filter->name_prefix; VLOG(1) << "Name Prefix: " << filter->name_prefix.value();
if (!filter->services.is_null()) { if (filter->services) {
VLOG(1) << "Services: "; VLOG(1) << "Services: ";
VLOG(1) << "\t["; VLOG(1) << "\t[";
for (const auto& service : filter->services) for (const auto& service : filter->services.value())
VLOG(1) << "\t\t" << service->canonical_value(); VLOG(1) << "\t\t" << service.canonical_value();
VLOG(1) << "\t]"; VLOG(1) << "\t]";
} }
} }
...@@ -83,25 +83,24 @@ void LogRequestDeviceOptions( ...@@ -83,25 +83,24 @@ void LogRequestDeviceOptions(
bool IsEmptyOrInvalidFilter( bool IsEmptyOrInvalidFilter(
const blink::mojom::WebBluetoothScanFilterPtr& filter) { const blink::mojom::WebBluetoothScanFilterPtr& filter) {
// At least one member needs to be present. // At least one member needs to be present.
if (filter->name.is_null() && filter->name_prefix.is_null() && if (!filter->name && !filter->name_prefix && !filter->services)
filter->services.is_null())
return true; return true;
// The renderer will never send a name or a name_prefix longer than // The renderer will never send a name or a name_prefix longer than
// kMaxLengthForDeviceName. // kMaxLengthForDeviceName.
if (!filter->name.is_null() && filter->name.size() > kMaxLengthForDeviceName) if (filter->name && filter->name->size() > kMaxLengthForDeviceName)
return true; return true;
if (!filter->name_prefix.is_null() && filter->name_prefix.size() == 0) if (filter->name_prefix && filter->name_prefix->size() == 0)
return true; return true;
if (!filter->name_prefix.is_null() && if (filter->name_prefix &&
filter->name_prefix.size() > kMaxLengthForDeviceName) filter->name_prefix->size() > kMaxLengthForDeviceName)
return true; return true;
return false; return false;
} }
bool HasEmptyOrInvalidFilter( bool HasEmptyOrInvalidFilter(
const mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>& filters) { const std::vector<blink::mojom::WebBluetoothScanFilterPtr>& filters) {
return filters.empty() return filters.empty()
? true ? true
: filters.end() != std::find_if(filters.begin(), filters.end(), : filters.end() != std::find_if(filters.begin(), filters.end(),
...@@ -111,24 +110,24 @@ bool HasEmptyOrInvalidFilter( ...@@ -111,24 +110,24 @@ bool HasEmptyOrInvalidFilter(
bool MatchesFilter(const std::string* device_name, bool MatchesFilter(const std::string* device_name,
const UUIDSet& device_uuids, const UUIDSet& device_uuids,
const blink::mojom::WebBluetoothScanFilterPtr& filter) { const blink::mojom::WebBluetoothScanFilterPtr& filter) {
if (!filter->name.is_null()) { if (filter->name) {
if (device_name == nullptr) if (device_name == nullptr)
return false; return false;
if (filter->name != *device_name) if (filter->name.value() != *device_name)
return false; return false;
} }
if (!filter->name_prefix.is_null() && filter->name_prefix.size()) { if (filter->name_prefix && filter->name_prefix->size()) {
if (device_name == nullptr) if (device_name == nullptr)
return false; return false;
if (!base::StartsWith(*device_name, filter->name_prefix.get(), if (!base::StartsWith(*device_name, filter->name_prefix.value(),
base::CompareCase::SENSITIVE)) base::CompareCase::SENSITIVE))
return false; return false;
} }
if (!filter->services.is_null()) { if (filter->services) {
for (const base::Optional<BluetoothUUID>& service : filter->services) { for (const auto& service : filter->services.value()) {
if (!base::ContainsKey(device_uuids, service.value())) { if (!base::ContainsKey(device_uuids, service)) {
return false; return false;
} }
} }
...@@ -140,7 +139,7 @@ bool MatchesFilter(const std::string* device_name, ...@@ -140,7 +139,7 @@ bool MatchesFilter(const std::string* device_name,
bool MatchesFilters( bool MatchesFilters(
const std::string* device_name, const std::string* device_name,
const UUIDSet& device_uuids, const UUIDSet& device_uuids,
const mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>& filters) { const std::vector<blink::mojom::WebBluetoothScanFilterPtr>& filters) {
DCHECK(!HasEmptyOrInvalidFilter(filters)); DCHECK(!HasEmptyOrInvalidFilter(filters));
for (const auto& filter : filters) { for (const auto& filter : filters) {
if (MatchesFilter(device_name, device_uuids, filter)) { if (MatchesFilter(device_name, device_uuids, filter)) {
...@@ -151,11 +150,14 @@ bool MatchesFilters( ...@@ -151,11 +150,14 @@ bool MatchesFilters(
} }
std::unique_ptr<device::BluetoothDiscoveryFilter> ComputeScanFilter( std::unique_ptr<device::BluetoothDiscoveryFilter> ComputeScanFilter(
const mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>& filters) { const std::vector<blink::mojom::WebBluetoothScanFilterPtr>& filters) {
std::unordered_set<BluetoothUUID, device::BluetoothUUIDHash> services; std::unordered_set<BluetoothUUID, device::BluetoothUUIDHash> services;
for (const auto& filter : filters) { for (const auto& filter : filters) {
for (const base::Optional<BluetoothUUID>& service : filter->services) { if (!filter->services) {
services.insert(service.value()); continue;
}
for (const auto& service : filter->services.value()) {
services.insert(service);
} }
} }
// There isn't much support for GATT over BR/EDR from neither platforms nor // There isn't much support for GATT over BR/EDR from neither platforms nor
......
...@@ -63,13 +63,16 @@ void RecordRequestDeviceOutcome(UMARequestDeviceOutcome outcome) { ...@@ -63,13 +63,16 @@ void RecordRequestDeviceOutcome(UMARequestDeviceOutcome outcome) {
} }
static void RecordRequestDeviceFilters( static void RecordRequestDeviceFilters(
const mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>& filters) { const std::vector<blink::mojom::WebBluetoothScanFilterPtr>& filters) {
UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.Filters.Count", UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.Filters.Count",
filters.size()); filters.size());
for (const auto& filter : filters) { for (const auto& filter : filters) {
if (!filter->services) {
continue;
}
UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.FilterSize", UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.FilterSize",
filter->services.size()); filter->services->size());
for (const base::Optional<BluetoothUUID>& service : filter->services) { for (const BluetoothUUID& service : filter->services.value()) {
// TODO(ortuno): Use a macro to histogram strings. // TODO(ortuno): Use a macro to histogram strings.
// http://crbug.com/520284 // http://crbug.com/520284
UMA_HISTOGRAM_SPARSE_SLOWLY( UMA_HISTOGRAM_SPARSE_SLOWLY(
...@@ -79,10 +82,10 @@ static void RecordRequestDeviceFilters( ...@@ -79,10 +82,10 @@ static void RecordRequestDeviceFilters(
} }
static void RecordRequestDeviceOptionalServices( static void RecordRequestDeviceOptionalServices(
const mojo::Array<base::Optional<BluetoothUUID>>& optional_services) { const std::vector<BluetoothUUID>& optional_services) {
UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.OptionalServices.Count", UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.OptionalServices.Count",
optional_services.size()); optional_services.size());
for (const base::Optional<BluetoothUUID>& service : optional_services) { for (const BluetoothUUID& service : optional_services) {
// TODO(ortuno): Use a macro to histogram strings. // TODO(ortuno): Use a macro to histogram strings.
// http://crbug.com/520284 // http://crbug.com/520284
UMA_HISTOGRAM_SPARSE_SLOWLY( UMA_HISTOGRAM_SPARSE_SLOWLY(
...@@ -94,14 +97,16 @@ static void RecordRequestDeviceOptionalServices( ...@@ -94,14 +97,16 @@ static void RecordRequestDeviceOptionalServices(
static void RecordUnionOfServices( static void RecordUnionOfServices(
const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options) { const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options) {
std::unordered_set<std::string> union_of_services; std::unordered_set<std::string> union_of_services;
for (const base::Optional<BluetoothUUID>& service : for (const BluetoothUUID& service : options->optional_services) {
options->optional_services) { union_of_services.insert(service.canonical_value());
union_of_services.insert(service->canonical_value());
} }
for (const auto& filter : options->filters) { for (const auto& filter : options->filters) {
for (const base::Optional<BluetoothUUID>& service : filter->services) { if (!filter->services) {
union_of_services.insert(service->canonical_value()); continue;
}
for (const BluetoothUUID& service : filter->services.value()) {
union_of_services.insert(service.canonical_value());
} }
} }
......
...@@ -308,10 +308,10 @@ void WebBluetoothServiceImpl::GattCharacteristicValueChanged( ...@@ -308,10 +308,10 @@ void WebBluetoothServiceImpl::GattCharacteristicValueChanged(
void WebBluetoothServiceImpl::NotifyCharacteristicValueChanged( void WebBluetoothServiceImpl::NotifyCharacteristicValueChanged(
const std::string& characteristic_instance_id, const std::string& characteristic_instance_id,
std::vector<uint8_t> value) { const std::vector<uint8_t>& value) {
if (client_) { if (client_) {
client_->RemoteCharacteristicValueChanged( client_->RemoteCharacteristicValueChanged(characteristic_instance_id,
characteristic_instance_id, mojo::Array<uint8_t>(std::move(value))); value);
} }
} }
...@@ -411,7 +411,7 @@ void WebBluetoothServiceImpl::RemoteServerGetPrimaryServices( ...@@ -411,7 +411,7 @@ void WebBluetoothServiceImpl::RemoteServerGetPrimaryServices(
GetOrigin(), device_id)) { GetOrigin(), device_id)) {
callback.Run( callback.Run(
blink::mojom::WebBluetoothResult::NOT_ALLOWED_TO_ACCESS_ANY_SERVICE, blink::mojom::WebBluetoothResult::NOT_ALLOWED_TO_ACCESS_ANY_SERVICE,
nullptr /* service */); base::nullopt /* service */);
return; return;
} }
...@@ -420,7 +420,7 @@ void WebBluetoothServiceImpl::RemoteServerGetPrimaryServices( ...@@ -420,7 +420,7 @@ void WebBluetoothServiceImpl::RemoteServerGetPrimaryServices(
GetOrigin(), device_id, services_uuid.value())) { GetOrigin(), device_id, services_uuid.value())) {
callback.Run( callback.Run(
blink::mojom::WebBluetoothResult::NOT_ALLOWED_TO_ACCESS_SERVICE, blink::mojom::WebBluetoothResult::NOT_ALLOWED_TO_ACCESS_SERVICE,
nullptr /* service */); base::nullopt /* service */);
return; return;
} }
...@@ -432,7 +432,7 @@ void WebBluetoothServiceImpl::RemoteServerGetPrimaryServices( ...@@ -432,7 +432,7 @@ void WebBluetoothServiceImpl::RemoteServerGetPrimaryServices(
if (query_result.outcome != CacheQueryOutcome::SUCCESS) { if (query_result.outcome != CacheQueryOutcome::SUCCESS) {
RecordGetPrimaryServicesOutcome(quantity, query_result.outcome); RecordGetPrimaryServicesOutcome(quantity, query_result.outcome);
callback.Run(query_result.GetWebResult(), nullptr /* service */); callback.Run(query_result.GetWebResult(), base::nullopt /* service */);
return; return;
} }
...@@ -453,7 +453,7 @@ void WebBluetoothServiceImpl::RemoteServerGetPrimaryServices( ...@@ -453,7 +453,7 @@ void WebBluetoothServiceImpl::RemoteServerGetPrimaryServices(
} }
void WebBluetoothServiceImpl::RemoteServiceGetCharacteristics( void WebBluetoothServiceImpl::RemoteServiceGetCharacteristics(
const mojo::String& service_instance_id, const std::string& service_instance_id,
blink::mojom::WebBluetoothGATTQueryQuantity quantity, blink::mojom::WebBluetoothGATTQueryQuantity quantity,
const base::Optional<BluetoothUUID>& characteristics_uuid, const base::Optional<BluetoothUUID>& characteristics_uuid,
const RemoteServiceGetCharacteristicsCallback& callback) { const RemoteServiceGetCharacteristicsCallback& callback) {
...@@ -471,7 +471,7 @@ void WebBluetoothServiceImpl::RemoteServiceGetCharacteristics( ...@@ -471,7 +471,7 @@ void WebBluetoothServiceImpl::RemoteServiceGetCharacteristics(
UMAGetCharacteristicOutcome::BLOCKLISTED); UMAGetCharacteristicOutcome::BLOCKLISTED);
callback.Run( callback.Run(
blink::mojom::WebBluetoothResult::BLOCKLISTED_CHARACTERISTIC_UUID, blink::mojom::WebBluetoothResult::BLOCKLISTED_CHARACTERISTIC_UUID,
nullptr /* characteristics */); base::nullopt /* characteristics */);
return; return;
} }
...@@ -484,7 +484,8 @@ void WebBluetoothServiceImpl::RemoteServiceGetCharacteristics( ...@@ -484,7 +484,8 @@ void WebBluetoothServiceImpl::RemoteServiceGetCharacteristics(
if (query_result.outcome != CacheQueryOutcome::SUCCESS) { if (query_result.outcome != CacheQueryOutcome::SUCCESS) {
RecordGetCharacteristicsOutcome(quantity, query_result.outcome); RecordGetCharacteristicsOutcome(quantity, query_result.outcome);
callback.Run(query_result.GetWebResult(), nullptr /* characteristics */); callback.Run(query_result.GetWebResult(),
base::nullopt /* characteristics */);
return; return;
} }
...@@ -494,7 +495,7 @@ void WebBluetoothServiceImpl::RemoteServiceGetCharacteristics( ...@@ -494,7 +495,7 @@ void WebBluetoothServiceImpl::RemoteServiceGetCharacteristics(
characteristics_uuid.value()) characteristics_uuid.value())
: query_result.service->GetCharacteristics(); : query_result.service->GetCharacteristics();
mojo::Array<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr> std::vector<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr>
response_characteristics; response_characteristics;
for (device::BluetoothRemoteGattCharacteristic* characteristic : for (device::BluetoothRemoteGattCharacteristic* characteristic :
characteristics) { characteristics) {
...@@ -536,11 +537,11 @@ void WebBluetoothServiceImpl::RemoteServiceGetCharacteristics( ...@@ -536,11 +537,11 @@ void WebBluetoothServiceImpl::RemoteServiceGetCharacteristics(
callback.Run(characteristics_uuid callback.Run(characteristics_uuid
? blink::mojom::WebBluetoothResult::CHARACTERISTIC_NOT_FOUND ? blink::mojom::WebBluetoothResult::CHARACTERISTIC_NOT_FOUND
: blink::mojom::WebBluetoothResult::NO_CHARACTERISTICS_FOUND, : blink::mojom::WebBluetoothResult::NO_CHARACTERISTICS_FOUND,
nullptr /* characteristics */); base::nullopt /* characteristics */);
} }
void WebBluetoothServiceImpl::RemoteCharacteristicReadValue( void WebBluetoothServiceImpl::RemoteCharacteristicReadValue(
const mojo::String& characteristic_instance_id, const std::string& characteristic_instance_id,
const RemoteCharacteristicReadValueCallback& callback) { const RemoteCharacteristicReadValueCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
RecordWebBluetoothFunctionCall( RecordWebBluetoothFunctionCall(
...@@ -555,7 +556,7 @@ void WebBluetoothServiceImpl::RemoteCharacteristicReadValue( ...@@ -555,7 +556,7 @@ void WebBluetoothServiceImpl::RemoteCharacteristicReadValue(
if (query_result.outcome != CacheQueryOutcome::SUCCESS) { if (query_result.outcome != CacheQueryOutcome::SUCCESS) {
RecordCharacteristicReadValueOutcome(query_result.outcome); RecordCharacteristicReadValueOutcome(query_result.outcome);
callback.Run(query_result.GetWebResult(), nullptr /* value */); callback.Run(query_result.GetWebResult(), base::nullopt /* value */);
return; return;
} }
...@@ -563,7 +564,7 @@ void WebBluetoothServiceImpl::RemoteCharacteristicReadValue( ...@@ -563,7 +564,7 @@ void WebBluetoothServiceImpl::RemoteCharacteristicReadValue(
query_result.characteristic->GetUUID())) { query_result.characteristic->GetUUID())) {
RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::BLOCKLISTED); RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::BLOCKLISTED);
callback.Run(blink::mojom::WebBluetoothResult::BLOCKLISTED_READ, callback.Run(blink::mojom::WebBluetoothResult::BLOCKLISTED_READ,
nullptr /* value */); base::nullopt /* value */);
return; return;
} }
...@@ -575,8 +576,8 @@ void WebBluetoothServiceImpl::RemoteCharacteristicReadValue( ...@@ -575,8 +576,8 @@ void WebBluetoothServiceImpl::RemoteCharacteristicReadValue(
} }
void WebBluetoothServiceImpl::RemoteCharacteristicWriteValue( void WebBluetoothServiceImpl::RemoteCharacteristicWriteValue(
const mojo::String& characteristic_instance_id, const std::string& characteristic_instance_id,
mojo::Array<uint8_t> value, const std::vector<uint8_t>& value,
const RemoteCharacteristicWriteValueCallback& callback) { const RemoteCharacteristicWriteValueCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
RecordWebBluetoothFunctionCall( RecordWebBluetoothFunctionCall(
...@@ -611,15 +612,14 @@ void WebBluetoothServiceImpl::RemoteCharacteristicWriteValue( ...@@ -611,15 +612,14 @@ void WebBluetoothServiceImpl::RemoteCharacteristicWriteValue(
} }
query_result.characteristic->WriteRemoteCharacteristic( query_result.characteristic->WriteRemoteCharacteristic(
value.To<std::vector<uint8_t>>(), value, base::Bind(&WebBluetoothServiceImpl::OnWriteValueSuccess,
base::Bind(&WebBluetoothServiceImpl::OnWriteValueSuccess, weak_ptr_factory_.GetWeakPtr(), callback),
weak_ptr_factory_.GetWeakPtr(), callback),
base::Bind(&WebBluetoothServiceImpl::OnWriteValueFailed, base::Bind(&WebBluetoothServiceImpl::OnWriteValueFailed,
weak_ptr_factory_.GetWeakPtr(), callback)); weak_ptr_factory_.GetWeakPtr(), callback));
} }
void WebBluetoothServiceImpl::RemoteCharacteristicStartNotifications( void WebBluetoothServiceImpl::RemoteCharacteristicStartNotifications(
const mojo::String& characteristic_instance_id, const std::string& characteristic_instance_id,
const RemoteCharacteristicStartNotificationsCallback& callback) { const RemoteCharacteristicStartNotificationsCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
RecordWebBluetoothFunctionCall( RecordWebBluetoothFunctionCall(
...@@ -665,7 +665,7 @@ void WebBluetoothServiceImpl::RemoteCharacteristicStartNotifications( ...@@ -665,7 +665,7 @@ void WebBluetoothServiceImpl::RemoteCharacteristicStartNotifications(
} }
void WebBluetoothServiceImpl::RemoteCharacteristicStopNotifications( void WebBluetoothServiceImpl::RemoteCharacteristicStopNotifications(
const mojo::String& characteristic_instance_id, const std::string& characteristic_instance_id,
const RemoteCharacteristicStopNotificationsCallback& callback) { const RemoteCharacteristicStopNotificationsCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
RecordWebBluetoothFunctionCall( RecordWebBluetoothFunctionCall(
...@@ -726,7 +726,7 @@ void WebBluetoothServiceImpl::RemoteServerGetPrimaryServicesImpl( ...@@ -726,7 +726,7 @@ void WebBluetoothServiceImpl::RemoteServerGetPrimaryServicesImpl(
services_uuid ? GetPrimaryServicesByUUID(device, services_uuid.value()) services_uuid ? GetPrimaryServicesByUUID(device, services_uuid.value())
: GetPrimaryServices(device); : GetPrimaryServices(device);
mojo::Array<blink::mojom::WebBluetoothRemoteGATTServicePtr> response_services; std::vector<blink::mojom::WebBluetoothRemoteGATTServicePtr> response_services;
for (device::BluetoothRemoteGattService* service : services) { for (device::BluetoothRemoteGattService* service : services) {
if (!allowed_devices_map_.IsOriginAllowedToAccessService( if (!allowed_devices_map_.IsOriginAllowedToAccessService(
GetOrigin(), device_id, service->GetUUID())) { GetOrigin(), device_id, service->GetUUID())) {
...@@ -767,7 +767,7 @@ void WebBluetoothServiceImpl::RemoteServerGetPrimaryServicesImpl( ...@@ -767,7 +767,7 @@ void WebBluetoothServiceImpl::RemoteServerGetPrimaryServicesImpl(
callback.Run(services_uuid callback.Run(services_uuid
? blink::mojom::WebBluetoothResult::SERVICE_NOT_FOUND ? blink::mojom::WebBluetoothResult::SERVICE_NOT_FOUND
: blink::mojom::WebBluetoothResult::NO_SERVICES_FOUND, : blink::mojom::WebBluetoothResult::NO_SERVICES_FOUND,
nullptr /* services */); base::nullopt /* services */);
} }
void WebBluetoothServiceImpl::OnGetDeviceSuccess( void WebBluetoothServiceImpl::OnGetDeviceSuccess(
...@@ -794,8 +794,7 @@ void WebBluetoothServiceImpl::OnGetDeviceSuccess( ...@@ -794,8 +794,7 @@ void WebBluetoothServiceImpl::OnGetDeviceSuccess(
blink::mojom::WebBluetoothDevicePtr device_ptr = blink::mojom::WebBluetoothDevicePtr device_ptr =
blink::mojom::WebBluetoothDevice::New(); blink::mojom::WebBluetoothDevice::New();
device_ptr->id = device_id_for_origin; device_ptr->id = device_id_for_origin;
device_ptr->name = device->GetName() ? mojo::String(device->GetName().value()) device_ptr->name = device->GetName();
: mojo::String(nullptr);
RecordRequestDeviceOutcome(UMARequestDeviceOutcome::SUCCESS); RecordRequestDeviceOutcome(UMARequestDeviceOutcome::SUCCESS);
callback.Run(blink::mojom::WebBluetoothResult::SUCCESS, callback.Run(blink::mojom::WebBluetoothResult::SUCCESS,
...@@ -837,8 +836,7 @@ void WebBluetoothServiceImpl::OnReadValueSuccess( ...@@ -837,8 +836,7 @@ void WebBluetoothServiceImpl::OnReadValueSuccess(
const std::vector<uint8_t>& value) { const std::vector<uint8_t>& value) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::SUCCESS); RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::SUCCESS);
callback.Run(blink::mojom::WebBluetoothResult::SUCCESS, callback.Run(blink::mojom::WebBluetoothResult::SUCCESS, value);
mojo::Array<uint8_t>::From(value));
} }
void WebBluetoothServiceImpl::OnReadValueFailed( void WebBluetoothServiceImpl::OnReadValueFailed(
...@@ -847,7 +845,7 @@ void WebBluetoothServiceImpl::OnReadValueFailed( ...@@ -847,7 +845,7 @@ void WebBluetoothServiceImpl::OnReadValueFailed(
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
callback.Run(TranslateGATTErrorAndRecord( callback.Run(TranslateGATTErrorAndRecord(
error_code, UMAGATTOperation::CHARACTERISTIC_READ), error_code, UMAGATTOperation::CHARACTERISTIC_READ),
nullptr /* value */); base::nullopt /* value */);
} }
void WebBluetoothServiceImpl::OnWriteValueSuccess( void WebBluetoothServiceImpl::OnWriteValueSuccess(
......
...@@ -94,7 +94,7 @@ class CONTENT_EXPORT WebBluetoothServiceImpl ...@@ -94,7 +94,7 @@ class CONTENT_EXPORT WebBluetoothServiceImpl
// characteristics that have been returned to the client in the past. // characteristics that have been returned to the client in the past.
void NotifyCharacteristicValueChanged( void NotifyCharacteristicValueChanged(
const std::string& characteristic_instance_id, const std::string& characteristic_instance_id,
std::vector<uint8_t> value); const std::vector<uint8_t>& value);
// WebBluetoothService methods: // WebBluetoothService methods:
void SetClient( void SetClient(
...@@ -108,25 +108,25 @@ class CONTENT_EXPORT WebBluetoothServiceImpl ...@@ -108,25 +108,25 @@ class CONTENT_EXPORT WebBluetoothServiceImpl
void RemoteServerGetPrimaryServices( void RemoteServerGetPrimaryServices(
const WebBluetoothDeviceId& device_id, const WebBluetoothDeviceId& device_id,
blink::mojom::WebBluetoothGATTQueryQuantity quantity, blink::mojom::WebBluetoothGATTQueryQuantity quantity,
const base::Optional<device::BluetoothUUID>& service_uuid, const base::Optional<device::BluetoothUUID>& services_uuid,
const RemoteServerGetPrimaryServicesCallback& callback) override; const RemoteServerGetPrimaryServicesCallback& callback) override;
void RemoteServiceGetCharacteristics( void RemoteServiceGetCharacteristics(
const mojo::String& service_instance_id, const std::string& service_instance_id,
blink::mojom::WebBluetoothGATTQueryQuantity quantity, blink::mojom::WebBluetoothGATTQueryQuantity quantity,
const base::Optional<device::BluetoothUUID>& characteristics_uuid, const base::Optional<device::BluetoothUUID>& characteristics_uuid,
const RemoteServiceGetCharacteristicsCallback& callback) override; const RemoteServiceGetCharacteristicsCallback& callback) override;
void RemoteCharacteristicReadValue( void RemoteCharacteristicReadValue(
const mojo::String& characteristic_instance_id, const std::string& characteristic_instance_id,
const RemoteCharacteristicReadValueCallback& callback) override; const RemoteCharacteristicReadValueCallback& callback) override;
void RemoteCharacteristicWriteValue( void RemoteCharacteristicWriteValue(
const mojo::String& characteristic_instance_id, const std::string& characteristic_instance_id,
mojo::Array<uint8_t> value, const std::vector<uint8_t>& value,
const RemoteCharacteristicWriteValueCallback& callback) override; const RemoteCharacteristicWriteValueCallback& callback) override;
void RemoteCharacteristicStartNotifications( void RemoteCharacteristicStartNotifications(
const mojo::String& characteristic_instance_id, const std::string& characteristic_instance_id,
const RemoteCharacteristicStartNotificationsCallback& callback) override; const RemoteCharacteristicStartNotificationsCallback& callback) override;
void RemoteCharacteristicStopNotifications( void RemoteCharacteristicStopNotifications(
const mojo::String& characteristic_instance_id, const std::string& characteristic_instance_id,
const RemoteCharacteristicStopNotificationsCallback& callback) override; const RemoteCharacteristicStopNotificationsCallback& callback) override;
void RequestDeviceImpl( void RequestDeviceImpl(
......
...@@ -604,7 +604,6 @@ mojom("mojo_bindings") { ...@@ -604,7 +604,6 @@ mojom("mojo_bindings") {
"//services/video_capture/public/interfaces", "//services/video_capture/public/interfaces",
"//skia/public/interfaces", "//skia/public/interfaces",
"//third_party/WebKit/public:mojo_bindings", "//third_party/WebKit/public:mojo_bindings",
"//third_party/WebKit/public:new_wrapper_types_mojo_bindings",
"//ui/base/mojo:mojo_bindings", "//ui/base/mojo:mojo_bindings",
"//ui/gfx/geometry/mojo", "//ui/gfx/geometry/mojo",
"//ui/gfx/mojo", "//ui/gfx/mojo",
......
...@@ -50,7 +50,7 @@ android_library("content_java") { ...@@ -50,7 +50,7 @@ android_library("content_java") {
"//services/service_manager/public/interfaces:interfaces_java", "//services/service_manager/public/interfaces:interfaces_java",
"//services/service_manager/public/java:service_manager_java", "//services/service_manager/public/java:service_manager_java",
"//third_party/WebKit/public:blink_headers_java", "//third_party/WebKit/public:blink_headers_java",
"//third_party/WebKit/public:new_wrapper_types_mojo_bindings_java", "//third_party/WebKit/public:mojo_bindings_java",
"//third_party/android_tools:android_support_annotations_java", "//third_party/android_tools:android_support_annotations_java",
"//third_party/jsr-305:jsr_305_javalib", "//third_party/jsr-305:jsr_305_javalib",
"//ui/accessibility:ui_accessibility_java", "//ui/accessibility:ui_accessibility_java",
......
per-file *_type_converter*.*=set noparent
per-file *_type_converter*.*=file://ipc/SECURITY_OWNERS
jyasskin@chromium.org jyasskin@chromium.org
ortuno@chromium.org ortuno@chromium.org
scheib@chromium.org scheib@chromium.org
...@@ -17,15 +17,18 @@ blink::mojom::WebBluetoothScanFilterPtr TypeConverter< ...@@ -17,15 +17,18 @@ blink::mojom::WebBluetoothScanFilterPtr TypeConverter<
blink::mojom::WebBluetoothScanFilterPtr filter = blink::mojom::WebBluetoothScanFilterPtr filter =
blink::mojom::WebBluetoothScanFilter::New(); blink::mojom::WebBluetoothScanFilter::New();
if (!web_filter.services.isEmpty()) if (!web_filter.services.isEmpty()) {
filter->services = filter->services.emplace();
Array<base::Optional<device::BluetoothUUID>>::From(web_filter.services); for (const auto& service : web_filter.services) {
filter->services->push_back(device::BluetoothUUID(service.utf8()));
}
}
if (web_filter.hasName) if (web_filter.hasName)
filter->name = String::From(web_filter.name); filter->name = web_filter.name.utf8();
if (!web_filter.namePrefix.isEmpty()) if (!web_filter.namePrefix.isEmpty())
filter->name_prefix = String::From(web_filter.namePrefix); filter->name_prefix = web_filter.namePrefix.utf8();
return filter; return filter;
} }
...@@ -37,22 +40,24 @@ TypeConverter<blink::mojom::WebBluetoothRequestDeviceOptionsPtr, ...@@ -37,22 +40,24 @@ TypeConverter<blink::mojom::WebBluetoothRequestDeviceOptionsPtr,
blink::mojom::WebBluetoothRequestDeviceOptionsPtr options = blink::mojom::WebBluetoothRequestDeviceOptionsPtr options =
blink::mojom::WebBluetoothRequestDeviceOptions::New(); blink::mojom::WebBluetoothRequestDeviceOptions::New();
options->filters = mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>::From( for (const auto& filter : web_options.filters) {
web_options.filters); options->filters.push_back(blink::mojom::WebBluetoothScanFilter::From<
options->optional_services = blink::WebBluetoothScanFilter>(filter));
mojo::Array<base::Optional<device::BluetoothUUID>>::From( }
web_options.optionalServices); for (const auto& optional_service : web_options.optionalServices) {
options->optional_services.push_back(
device::BluetoothUUID(optional_service.utf8()));
}
return options; return options;
} }
// static // static
base::Optional<device::BluetoothUUID> device::BluetoothUUID
TypeConverter<base::Optional<device::BluetoothUUID>, blink::WebString>::Convert( TypeConverter<device::BluetoothUUID, blink::WebString>::Convert(
const blink::WebString& web_string) { const blink::WebString& web_string) {
base::Optional<device::BluetoothUUID> uuid = device::BluetoothUUID uuid = device::BluetoothUUID(web_string.utf8());
device::BluetoothUUID(web_string.utf8());
DCHECK(uuid->IsValid()); DCHECK(uuid.IsValid());
return uuid; return uuid;
} }
......
...@@ -33,9 +33,8 @@ struct TypeConverter<blink::mojom::WebBluetoothRequestDeviceOptionsPtr, ...@@ -33,9 +33,8 @@ struct TypeConverter<blink::mojom::WebBluetoothRequestDeviceOptionsPtr,
}; };
template <> template <>
struct TypeConverter<base::Optional<device::BluetoothUUID>, blink::WebString> { struct TypeConverter<device::BluetoothUUID, blink::WebString> {
static base::Optional<device::BluetoothUUID> Convert( static device::BluetoothUUID Convert(const blink::WebString& web_string);
const blink::WebString& web_string);
}; };
} // namespace mojo } // namespace mojo
......
...@@ -170,15 +170,14 @@ void WebBluetoothImpl::registerCharacteristicObject( ...@@ -170,15 +170,14 @@ void WebBluetoothImpl::registerCharacteristicObject(
} }
void WebBluetoothImpl::RemoteCharacteristicValueChanged( void WebBluetoothImpl::RemoteCharacteristicValueChanged(
const mojo::String& characteristic_instance_id, const std::string& characteristic_instance_id,
mojo::Array<uint8_t> value) { const std::vector<uint8_t>& value) {
// We post a task so that the event is fired after any pending promises have // We post a task so that the event is fired after any pending promises have
// resolved. // resolved.
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, FROM_HERE,
base::Bind(&WebBluetoothImpl::DispatchCharacteristicValueChanged, base::Bind(&WebBluetoothImpl::DispatchCharacteristicValueChanged,
base::Unretained(this), characteristic_instance_id, base::Unretained(this), characteristic_instance_id, value));
value.PassStorage()));
} }
void WebBluetoothImpl::OnRequestDeviceComplete( void WebBluetoothImpl::OnRequestDeviceComplete(
...@@ -188,8 +187,8 @@ void WebBluetoothImpl::OnRequestDeviceComplete( ...@@ -188,8 +187,8 @@ void WebBluetoothImpl::OnRequestDeviceComplete(
if (result == blink::mojom::WebBluetoothResult::SUCCESS) { if (result == blink::mojom::WebBluetoothResult::SUCCESS) {
callbacks->onSuccess(base::MakeUnique<blink::WebBluetoothDeviceInit>( callbacks->onSuccess(base::MakeUnique<blink::WebBluetoothDeviceInit>(
blink::WebString::fromUTF8(device->id.str()), blink::WebString::fromUTF8(device->id.str()),
device->name.is_null() ? blink::WebString() device->name ? blink::WebString::fromUTF8(device->name.value())
: blink::WebString::fromUTF8(device->name))); : blink::WebString()));
} else { } else {
callbacks->onError(ToInt32(result)); callbacks->onError(ToInt32(result));
} }
...@@ -223,17 +222,18 @@ void WebBluetoothImpl::OnGetPrimaryServicesComplete( ...@@ -223,17 +222,18 @@ void WebBluetoothImpl::OnGetPrimaryServicesComplete(
const blink::WebString& device_id, const blink::WebString& device_id,
std::unique_ptr<blink::WebBluetoothGetPrimaryServicesCallbacks> callbacks, std::unique_ptr<blink::WebBluetoothGetPrimaryServicesCallbacks> callbacks,
blink::mojom::WebBluetoothResult result, blink::mojom::WebBluetoothResult result,
mojo::Array<blink::mojom::WebBluetoothRemoteGATTServicePtr> services) { base::Optional<std::vector<blink::mojom::WebBluetoothRemoteGATTServicePtr>>
services) {
if (result == blink::mojom::WebBluetoothResult::SUCCESS) { if (result == blink::mojom::WebBluetoothResult::SUCCESS) {
DCHECK(services);
// TODO(dcheng): This WebVector should use smart pointers. // TODO(dcheng): This WebVector should use smart pointers.
blink::WebVector<blink::WebBluetoothRemoteGATTService*> promise_services( blink::WebVector<blink::WebBluetoothRemoteGATTService*> promise_services(
services.size()); services->size());
for (size_t i = 0; i < services->size(); i++) {
for (size_t i = 0; i < services.size(); i++) {
promise_services[i] = new blink::WebBluetoothRemoteGATTService( promise_services[i] = new blink::WebBluetoothRemoteGATTService(
blink::WebString::fromUTF8(services[i]->instance_id), blink::WebString::fromUTF8(services.value()[i]->instance_id),
blink::WebString::fromUTF8(services[i]->uuid), true /* isPrimary */, blink::WebString::fromUTF8(services.value()[i]->uuid),
device_id); true /* isPrimary */, device_id);
} }
callbacks->onSuccess(promise_services); callbacks->onSuccess(promise_services);
} else { } else {
...@@ -245,20 +245,21 @@ void WebBluetoothImpl::OnGetCharacteristicsComplete( ...@@ -245,20 +245,21 @@ void WebBluetoothImpl::OnGetCharacteristicsComplete(
const blink::WebString& service_instance_id, const blink::WebString& service_instance_id,
std::unique_ptr<blink::WebBluetoothGetCharacteristicsCallbacks> callbacks, std::unique_ptr<blink::WebBluetoothGetCharacteristicsCallbacks> callbacks,
blink::mojom::WebBluetoothResult result, blink::mojom::WebBluetoothResult result,
mojo::Array<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr> base::Optional<
std::vector<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr>>
characteristics) { characteristics) {
if (result == blink::mojom::WebBluetoothResult::SUCCESS) { if (result == blink::mojom::WebBluetoothResult::SUCCESS) {
DCHECK(characteristics);
// TODO(dcheng): This WebVector should use smart pointers. // TODO(dcheng): This WebVector should use smart pointers.
blink::WebVector<blink::WebBluetoothRemoteGATTCharacteristicInit*> blink::WebVector<blink::WebBluetoothRemoteGATTCharacteristicInit*>
promise_characteristics(characteristics.size()); promise_characteristics(characteristics->size());
for (size_t i = 0; i < characteristics->size(); i++) {
for (size_t i = 0; i < characteristics.size(); i++) {
promise_characteristics[i] = promise_characteristics[i] =
new blink::WebBluetoothRemoteGATTCharacteristicInit( new blink::WebBluetoothRemoteGATTCharacteristicInit(
service_instance_id, service_instance_id, blink::WebString::fromUTF8(
blink::WebString::fromUTF8(characteristics[i]->instance_id), characteristics.value()[i]->instance_id),
blink::WebString::fromUTF8(characteristics[i]->uuid), blink::WebString::fromUTF8(characteristics.value()[i]->uuid),
characteristics[i]->properties); characteristics.value()[i]->properties);
} }
callbacks->onSuccess(promise_characteristics); callbacks->onSuccess(promise_characteristics);
} else { } else {
...@@ -269,9 +270,10 @@ void WebBluetoothImpl::OnGetCharacteristicsComplete( ...@@ -269,9 +270,10 @@ void WebBluetoothImpl::OnGetCharacteristicsComplete(
void WebBluetoothImpl::OnReadValueComplete( void WebBluetoothImpl::OnReadValueComplete(
std::unique_ptr<blink::WebBluetoothReadValueCallbacks> callbacks, std::unique_ptr<blink::WebBluetoothReadValueCallbacks> callbacks,
blink::mojom::WebBluetoothResult result, blink::mojom::WebBluetoothResult result,
mojo::Array<uint8_t> value) { const base::Optional<std::vector<uint8_t>>& value) {
if (result == blink::mojom::WebBluetoothResult::SUCCESS) { if (result == blink::mojom::WebBluetoothResult::SUCCESS) {
callbacks->onSuccess(value.PassStorage()); DCHECK(value);
callbacks->onSuccess(value.value());
} else { } else {
callbacks->onError(ToInt32(result)); callbacks->onError(ToInt32(result));
} }
......
...@@ -86,8 +86,8 @@ class CONTENT_EXPORT WebBluetoothImpl ...@@ -86,8 +86,8 @@ class CONTENT_EXPORT WebBluetoothImpl
struct GetCharacteristicsCallback; struct GetCharacteristicsCallback;
// WebBluetoothServiceClient methods: // WebBluetoothServiceClient methods:
void RemoteCharacteristicValueChanged( void RemoteCharacteristicValueChanged(
const mojo::String& characteristic_instance_id, const std::string& characteristic_instance_id,
mojo::Array<uint8_t> value) override; const std::vector<uint8_t>& value) override;
void GattServerDisconnected(const WebBluetoothDeviceId& device_id) override; void GattServerDisconnected(const WebBluetoothDeviceId& device_id) override;
// Callbacks for WebBluetoothService calls: // Callbacks for WebBluetoothService calls:
...@@ -103,17 +103,20 @@ class CONTENT_EXPORT WebBluetoothImpl ...@@ -103,17 +103,20 @@ class CONTENT_EXPORT WebBluetoothImpl
const blink::WebString& device_id, const blink::WebString& device_id,
std::unique_ptr<blink::WebBluetoothGetPrimaryServicesCallbacks> callbacks, std::unique_ptr<blink::WebBluetoothGetPrimaryServicesCallbacks> callbacks,
blink::mojom::WebBluetoothResult result, blink::mojom::WebBluetoothResult result,
mojo::Array<blink::mojom::WebBluetoothRemoteGATTServicePtr> services); base::Optional<
std::vector<blink::mojom::WebBluetoothRemoteGATTServicePtr>>
services);
void OnGetCharacteristicsComplete( void OnGetCharacteristicsComplete(
const blink::WebString& service_instance_id, const blink::WebString& service_instance_id,
std::unique_ptr<blink::WebBluetoothGetCharacteristicsCallbacks> callbacks, std::unique_ptr<blink::WebBluetoothGetCharacteristicsCallbacks> callbacks,
blink::mojom::WebBluetoothResult result, blink::mojom::WebBluetoothResult result,
mojo::Array<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr> base::Optional<
std::vector<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr>>
characteristics); characteristics);
void OnReadValueComplete( void OnReadValueComplete(
std::unique_ptr<blink::WebBluetoothReadValueCallbacks> callbacks, std::unique_ptr<blink::WebBluetoothReadValueCallbacks> callbacks,
blink::mojom::WebBluetoothResult result, blink::mojom::WebBluetoothResult result,
mojo::Array<uint8_t> value); const base::Optional<std::vector<uint8_t>>& value);
void OnWriteValueComplete( void OnWriteValueComplete(
const blink::WebVector<uint8_t>& value, const blink::WebVector<uint8_t>& value,
std::unique_ptr<blink::WebBluetoothWriteValueCallbacks> callbacks, std::unique_ptr<blink::WebBluetoothWriteValueCallbacks> callbacks,
......
...@@ -273,7 +273,7 @@ void PresentationDispatcher::startListening( ...@@ -273,7 +273,7 @@ void PresentationDispatcher::startListening(
auto status_it = availability_status_.find(observer->url()); auto status_it = availability_status_.find(observer->url());
if (status_it == availability_status_.end()) { if (status_it == availability_status_.end()) {
DLOG(WARNING) << "Start listening for availability for unknown URL " DLOG(WARNING) << "Start listening for availability for unknown URL "
<< observer->url(); << GURL(observer->url());
return; return;
} }
status_it->second->availability_observers.insert(observer); status_it->second->availability_observers.insert(observer);
...@@ -285,7 +285,7 @@ void PresentationDispatcher::stopListening( ...@@ -285,7 +285,7 @@ void PresentationDispatcher::stopListening(
auto status_it = availability_status_.find(observer->url()); auto status_it = availability_status_.find(observer->url());
if (status_it == availability_status_.end()) { if (status_it == availability_status_.end()) {
DLOG(WARNING) << "Stop listening for availability for unknown URL " DLOG(WARNING) << "Stop listening for availability for unknown URL "
<< observer->url(); << GURL(observer->url());
return; return;
} }
status_it->second->availability_observers.erase(observer); status_it->second->availability_observers.erase(observer);
......
...@@ -3,13 +3,9 @@ ...@@ -3,13 +3,9 @@
# found in the LICENSE file. # found in the LICENSE file.
mojom = "//device/bluetooth/public/interfaces/uuid.mojom" mojom = "//device/bluetooth/public/interfaces/uuid.mojom"
public_headers = [ public_headers = [ "//device/bluetooth/bluetooth_uuid.h" ]
"//base/optional.h",
"//device/bluetooth/bluetooth_uuid.h",
]
traits_headers = [ "//device/bluetooth/public/interfaces/uuid_struct_traits.h" ] traits_headers = [ "//device/bluetooth/public/interfaces/uuid_struct_traits.h" ]
deps = [ deps = [
"//base",
"//device/bluetooth", "//device/bluetooth",
] ]
type_mappings = [ "bluetooth.mojom.UUID=base::Optional<device::BluetoothUUID>[nullable_is_same_type]" ] type_mappings = [ "bluetooth.mojom.UUID=device::BluetoothUUID" ]
...@@ -640,38 +640,11 @@ grit("image_resources") { ...@@ -640,38 +640,11 @@ grit("image_resources") {
} }
mojom("mojo_bindings") { mojom("mojo_bindings") {
sources = [
"platform/modules/bluetooth/web_bluetooth.mojom",
]
public_deps = [
":android_mojo_bindings",
":new_wrapper_types_mojo_bindings",
"//device/bluetooth/public/interfaces",
"//mojo/common:common_custom_types",
"//url/mojo:url_mojom_origin",
]
use_new_wrapper_types = false
# The chromium variant must be linked with content and use the same export
# settings in component build because of the WebBluetoothDeviceId typemap
# inside content.
export_class_attribute = "CONTENT_EXPORT"
export_define = "CONTENT_IMPLEMENTATION=1"
export_header = "content/common/content_export.h"
# Similarly, the blink variant must be linked with the platform component
# since it uses types from it in its typemaps.
export_class_attribute_blink = "BLINK_PLATFORM_EXPORT"
export_define_blink = "BLINK_PLATFORM_IMPLEMENTATION=1"
export_header_blink = "third_party/WebKit/public/platform/WebCommon.h"
}
mojom("new_wrapper_types_mojo_bindings") {
sources = [ sources = [
"platform/mime_registry.mojom", "platform/mime_registry.mojom",
"platform/modules/app_banner/app_banner.mojom", "platform/modules/app_banner/app_banner.mojom",
"platform/modules/background_sync/background_sync.mojom", "platform/modules/background_sync/background_sync.mojom",
"platform/modules/bluetooth/web_bluetooth.mojom",
"platform/modules/broadcastchannel/broadcast_channel.mojom", "platform/modules/broadcastchannel/broadcast_channel.mojom",
"platform/modules/budget_service/budget_service.mojom", "platform/modules/budget_service/budget_service.mojom",
"platform/modules/hyphenation/hyphenation.mojom", "platform/modules/hyphenation/hyphenation.mojom",
...@@ -691,6 +664,8 @@ mojom("new_wrapper_types_mojo_bindings") { ...@@ -691,6 +664,8 @@ mojom("new_wrapper_types_mojo_bindings") {
"web/window_features.mojom", "web/window_features.mojom",
] ]
public_deps = [ public_deps = [
":android_mojo_bindings",
"//device/bluetooth/public/interfaces",
"//mojo/common:common_custom_types", "//mojo/common:common_custom_types",
"//ui/gfx/geometry/mojo", "//ui/gfx/geometry/mojo",
"//ui/gfx/geometry/mojo:mojo", "//ui/gfx/geometry/mojo:mojo",
...@@ -698,10 +673,15 @@ mojom("new_wrapper_types_mojo_bindings") { ...@@ -698,10 +673,15 @@ mojom("new_wrapper_types_mojo_bindings") {
"//url/mojo:url_mojom_origin", "//url/mojo:url_mojom_origin",
] ]
# See comment above. # The chromium variant must be linked with content and use the same export
# settings in component build because of the WebBluetoothDeviceId typemap
# inside content.
export_class_attribute = "CONTENT_EXPORT" export_class_attribute = "CONTENT_EXPORT"
export_define = "CONTENT_IMPLEMENTATION=1" export_define = "CONTENT_IMPLEMENTATION=1"
export_header = "content/common/content_export.h" export_header = "content/common/content_export.h"
# Similarly, the blink variant must be linked with the platform component
# since it uses types from it in its typemaps.
export_class_attribute_blink = "BLINK_PLATFORM_EXPORT" export_class_attribute_blink = "BLINK_PLATFORM_EXPORT"
export_define_blink = "BLINK_PLATFORM_IMPLEMENTATION=1" export_define_blink = "BLINK_PLATFORM_IMPLEMENTATION=1"
export_header_blink = "third_party/WebKit/public/platform/WebCommon.h" export_header_blink = "third_party/WebKit/public/platform/WebCommon.h"
...@@ -762,6 +742,6 @@ source_set("shared_typemap_traits") { ...@@ -762,6 +742,6 @@ source_set("shared_typemap_traits") {
"web/WindowFeaturesStructTraits.cpp", "web/WindowFeaturesStructTraits.cpp",
] ]
deps = [ deps = [
":new_wrapper_types_mojo_bindings_shared__generator", ":mojo_bindings_shared__generator",
] ]
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment