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

Unified Diff: content/browser/bluetooth/web_bluetooth_service_impl.cc

Issue 2658473002: Refactor BluetoothAllowedDevicesMap (Closed)
Patch Set: updated test code Created 3 years, 11 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: content/browser/bluetooth/web_bluetooth_service_impl.cc
diff --git a/content/browser/bluetooth/web_bluetooth_service_impl.cc b/content/browser/bluetooth/web_bluetooth_service_impl.cc
index 5adce0eeaf41874eec81f3bf15c7b6341768c44f..ab12b6fb3584978b04081f955452b9e6d8e1d372 100644
--- a/content/browser/bluetooth/web_bluetooth_service_impl.cc
+++ b/content/browser/bluetooth/web_bluetooth_service_impl.cc
@@ -20,10 +20,12 @@
#include "content/browser/bluetooth/frame_connected_bluetooth_devices.h"
#include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/common/bluetooth/web_bluetooth_device_id.h"
+#include "content/public/browser/bluetooth_allowed_devices_map_base.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_delegate.h"
#include "device/bluetooth/bluetooth_adapter_factory_wrapper.h"
#include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
#include "device/bluetooth/bluetooth_remote_gatt_descriptor.h"
@@ -190,8 +192,7 @@ void WebBluetoothServiceImpl::SetClientConnectionErrorHandler(
bool WebBluetoothServiceImpl::IsDevicePaired(
const std::string& device_address) {
- return allowed_devices_map_.GetDeviceId(GetOrigin(), device_address) !=
- nullptr;
+ return allowed_devices()->GetDeviceId(device_address) != nullptr;
}
void WebBluetoothServiceImpl::DidFinishNavigation(
@@ -389,8 +390,7 @@ void WebBluetoothServiceImpl::RemoteServerGetPrimaryServices(
: UMAWebBluetoothFunction::GET_PRIMARY_SERVICES);
RecordGetPrimaryServicesServices(quantity, services_uuid);
- if (!allowed_devices_map_.IsOriginAllowedToAccessAtLeastOneService(
- GetOrigin(), device_id)) {
+ if (!allowed_devices()->IsAllowedToAccessAtLeastOneService(device_id)) {
callback.Run(
blink::mojom::WebBluetoothResult::NOT_ALLOWED_TO_ACCESS_ANY_SERVICE,
base::nullopt /* service */);
@@ -398,8 +398,8 @@ void WebBluetoothServiceImpl::RemoteServerGetPrimaryServices(
}
if (services_uuid &&
- !allowed_devices_map_.IsOriginAllowedToAccessService(
- GetOrigin(), device_id, services_uuid.value())) {
+ !allowed_devices()->IsAllowedToAccessService(device_id,
+ services_uuid.value())) {
callback.Run(
blink::mojom::WebBluetoothResult::NOT_ALLOWED_TO_ACCESS_SERVICE,
base::nullopt /* service */);
@@ -812,8 +812,8 @@ void WebBluetoothServiceImpl::RemoteServerGetPrimaryServicesImpl(
std::vector<blink::mojom::WebBluetoothRemoteGATTServicePtr> response_services;
for (device::BluetoothRemoteGattService* service : services) {
- if (!allowed_devices_map_.IsOriginAllowedToAccessService(
- GetOrigin(), device_id, service->GetUUID())) {
+ if (!allowed_devices()->IsAllowedToAccessService(device_id,
+ service->GetUUID())) {
continue;
}
std::string service_instance_id = service->GetIdentifier();
@@ -870,14 +870,14 @@ void WebBluetoothServiceImpl::OnGetDeviceSuccess(
return;
}
- const WebBluetoothDeviceId device_id_for_origin =
- allowed_devices_map_.AddDevice(GetOrigin(), device_address, options);
+ const WebBluetoothDeviceId device_id =
+ allowed_devices()->AddDevice(device_address, options);
DVLOG(1) << "Device: " << device->GetNameForDisplay();
blink::mojom::WebBluetoothDevicePtr device_ptr =
blink::mojom::WebBluetoothDevice::New();
- device_ptr->id = device_id_for_origin;
+ device_ptr->id = device_id;
device_ptr->name = device->GetName();
RecordRequestDeviceOutcome(UMARequestDeviceOutcome::SUCCESS);
@@ -996,7 +996,7 @@ void WebBluetoothServiceImpl::OnDescriptorReadValueFailed(
CacheQueryResult WebBluetoothServiceImpl::QueryCacheForDevice(
const WebBluetoothDeviceId& device_id) {
const std::string& device_address =
- allowed_devices_map_.GetDeviceAddress(GetOrigin(), device_id);
+ allowed_devices()->GetDeviceAddress(device_id);
if (device_address.empty()) {
CrashRendererAndClosePipe(bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN);
return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER);
@@ -1025,7 +1025,7 @@ CacheQueryResult WebBluetoothServiceImpl::QueryCacheForService(
}
const WebBluetoothDeviceId* device_id =
- allowed_devices_map_.GetDeviceId(GetOrigin(), device_iter->second);
+ allowed_devices()->GetDeviceId(device_iter->second);
// Kill the renderer if origin is not allowed to access the device.
if (device_id == nullptr) {
CrashRendererAndClosePipe(bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN);
@@ -1040,8 +1040,8 @@ CacheQueryResult WebBluetoothServiceImpl::QueryCacheForService(
result.service = result.device->GetGattService(service_instance_id);
if (result.service == nullptr) {
result.outcome = CacheQueryOutcome::NO_SERVICE;
- } else if (!allowed_devices_map_.IsOriginAllowedToAccessService(
- GetOrigin(), *device_id, result.service->GetUUID())) {
+ } else if (!allowed_devices()->IsAllowedToAccessService(
+ *device_id, result.service->GetUUID())) {
CrashRendererAndClosePipe(bad_message::BDH_SERVICE_NOT_ALLOWED_FOR_ORIGIN);
return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER);
}
@@ -1121,6 +1121,18 @@ url::Origin WebBluetoothServiceImpl::GetOrigin() {
return render_frame_host_->GetLastCommittedOrigin();
}
+BluetoothAllowedDevices* WebBluetoothServiceImpl::allowed_devices() {
+ if (!allowed_devices_) {
+ WebContentsDelegate* delegate = web_contents()->GetDelegate();
+ BluetoothAllowedDevicesMapBase* allowed_devices_map =
+ delegate->GetBluetoothDevicesMap(render_frame_host_);
+ allowed_devices_ =
+ allowed_devices_map->GetOrCreateAllowedDevices(GetOrigin());
dcheng 2017/02/01 07:54:09 Is this expected to be immutable per-origin?
juncai 2017/02/02 01:44:33 The BluetoothAllowedDevices object that an origin
+ DCHECK(allowed_devices_);
+ }
+ return allowed_devices_;
+}
+
void WebBluetoothServiceImpl::ClearState() {
characteristic_id_to_notify_session_.clear();
pending_primary_services_requests_.clear();
@@ -1129,7 +1141,6 @@ void WebBluetoothServiceImpl::ClearState() {
service_id_to_device_address_.clear();
connected_devices_.reset(
new FrameConnectedBluetoothDevices(render_frame_host_));
- allowed_devices_map_ = BluetoothAllowedDevicesMap();
device_chooser_controller_.reset();
BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this);
}

Powered by Google App Engine
This is Rietveld 408576698