Index: content/browser/frame_host/render_frame_host_impl.cc |
diff --git a/content/browser/frame_host/render_frame_host_impl.cc b/content/browser/frame_host/render_frame_host_impl.cc |
index daff90dfa3b08b3134149274141276a4c9505882..2ce5272e148aa7c20723a055998bd256b9340251 100644 |
--- a/content/browser/frame_host/render_frame_host_impl.cc |
+++ b/content/browser/frame_host/render_frame_host_impl.cc |
@@ -14,6 +14,7 @@ |
#include "base/memory/ptr_util.h" |
#include "base/metrics/histogram_macros.h" |
#include "base/process/kill.h" |
+#include "base/stl_util.h" |
#include "base/time/time.h" |
#include "build/build_config.h" |
#include "content/browser/accessibility/ax_tree_id_registry.h" |
@@ -3208,19 +3209,24 @@ void RenderFrameHostImpl::AXContentTreeDataToAXTreeData( |
WebBluetoothServiceImpl* RenderFrameHostImpl::CreateWebBluetoothService( |
blink::mojom::WebBluetoothServiceRequest request) { |
- DCHECK(!web_bluetooth_service_); |
- web_bluetooth_service_.reset( |
- new WebBluetoothServiceImpl(this, std::move(request))); |
- // RFHI owns web_bluetooth_service_ and web_bluetooth_service owns the |
- // binding_ which may run the error handler. binding_ can't run the error |
+ // RFHI owns |web_bluetooth_services_| and |web_bluetooth_service| owns the |
+ // |binding_| which may run the error handler. |binding_| can't run the error |
// handler after it's destroyed so it can't run after the RFHI is destroyed. |
- web_bluetooth_service_->SetClientConnectionErrorHandler(base::Bind( |
- &RenderFrameHostImpl::DeleteWebBluetoothService, base::Unretained(this))); |
- return web_bluetooth_service_.get(); |
-} |
- |
-void RenderFrameHostImpl::DeleteWebBluetoothService() { |
- web_bluetooth_service_.reset(); |
+ std::unique_ptr<WebBluetoothServiceImpl> web_bluetooth_service = |
+ base::MakeUnique<WebBluetoothServiceImpl>(this, std::move(request)); |
+ web_bluetooth_service->SetClientConnectionErrorHandler( |
+ base::Bind(&RenderFrameHostImpl::DeleteWebBluetoothService, |
+ base::Unretained(this), web_bluetooth_service.get())); |
+ auto it = web_bluetooth_services_.insert(std::move(web_bluetooth_service)); |
+ return it.first->get(); |
dcheng
2016/12/22 08:37:20
I would suggest using a container of raw pointers
Reilly Grant (use Gerrit)
2016/12/22 16:23:13
That method would suggest using the now removed ST
clamy
2016/12/22 17:00:57
Why not use a map with an explicit id as a key? Th
juncai
2016/12/22 22:15:40
Changed it to use std::list<std::unique_ptr<WebBlu
|
+} |
+ |
+void RenderFrameHostImpl::DeleteWebBluetoothService( |
+ WebBluetoothServiceImpl* web_bluetooth_service) { |
+ auto it = web_bluetooth_services_.find( |
+ base::FakeUniquePtr<WebBluetoothServiceImpl>(web_bluetooth_service)); |
+ DCHECK(it != web_bluetooth_services_.end()); |
+ web_bluetooth_services_.erase(it); |
} |
void RenderFrameHostImpl::Create( |