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

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

Issue 2658473002: Refactor BluetoothAllowedDevicesMap (Closed)
Patch Set: set --similarity=20 when did git cl upload 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 9f3510187804038d808295a293f6feb2c5faf7a0..822c1daa67f573cc75859a0a8242de431dabe628 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"
@@ -173,6 +175,14 @@ WebBluetoothServiceImpl::WebBluetoothServiceImpl(
weak_ptr_factory_(this) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
CHECK(web_contents());
+ WebContentsDelegate* delegate = web_contents()->GetDelegate();
+ DCHECK(delegate);
scheib 2017/01/26 04:27:36 These first 2 DCHECKs can be removed. The last wil
juncai 2017/01/30 20:34:55 Done.
+ BluetoothAllowedDevicesMapBase* allowed_devices_map =
+ delegate->GetBluetoothDevicesMap(render_frame_host_);
+ DCHECK(allowed_devices_map);
+ allowed_devices_ =
+ allowed_devices_map->GetOrCreateAllowedDevices(GetOrigin());
+ DCHECK(allowed_devices_);
}
WebBluetoothServiceImpl::~WebBluetoothServiceImpl() {
@@ -187,8 +197,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(
@@ -386,8 +395,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 */);
@@ -395,8 +403,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 */);
@@ -774,8 +782,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();
@@ -832,14 +840,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);
@@ -941,7 +949,7 @@ void WebBluetoothServiceImpl::OnStopNotifySessionComplete(
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);
@@ -970,7 +978,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);
@@ -985,8 +993,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);
}
@@ -1046,7 +1054,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