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

Side by Side Diff: device/vr/vr_service_impl.cc

Issue 2590883003: Fix leak in VRServiceImpl (Closed)
Patch Set: fix compile Created 3 years, 12 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 unified diff | Download patch
« no previous file with comments | « device/vr/vr_service_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "device/vr/vr_service_impl.h" 5 #include "device/vr/vr_service_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "device/vr/vr_device.h" 10 #include "device/vr/vr_device.h"
11 #include "device/vr/vr_device_manager.h" 11 #include "device/vr/vr_device_manager.h"
12 #include "mojo/public/cpp/bindings/strong_binding.h"
12 13
13 namespace device { 14 namespace device {
14 15
15 VRServiceImpl::VRServiceImpl() : listening_for_activate_(false) {} 16 VRServiceImpl::VRServiceImpl() : listening_for_activate_(false) {}
16 17
17 VRServiceImpl::~VRServiceImpl() { 18 VRServiceImpl::~VRServiceImpl() {
18 RemoveFromDeviceManager(); 19 VRDeviceManager::GetInstance()->RemoveService(this);
19 } 20 }
20 21
21 void VRServiceImpl::BindRequest( 22 void VRServiceImpl::Create(mojo::InterfaceRequest<mojom::VRService> request) {
22 mojo::InterfaceRequest<mojom::VRService> request) { 23 mojo::MakeStrongBinding(base::MakeUnique<VRServiceImpl>(),
23 VRServiceImpl* service = new VRServiceImpl(); 24 std::move(request));
24 service->Bind(std::move(request));
25 } 25 }
26 26
27 // Gets a VRDisplayPtr unique to this service so that the associated page can 27 // Gets a VRDisplayPtr unique to this service so that the associated page can
28 // communicate with the VRDevice. 28 // communicate with the VRDevice.
29 VRDisplayImpl* VRServiceImpl::GetVRDisplayImpl(VRDevice* device) { 29 VRDisplayImpl* VRServiceImpl::GetVRDisplayImpl(VRDevice* device) {
30 DisplayImplMap::iterator it = displays_.find(device); 30 auto it = displays_.find(device);
31 if (it != displays_.end()) 31 if (it != displays_.end())
32 return it->second.get(); 32 return it->second.get();
33 33
34 VRDisplayImpl* display_impl = new VRDisplayImpl(device, this); 34 VRDisplayImpl* display_impl = new VRDisplayImpl(device, this);
35 displays_[device] = base::WrapUnique(display_impl); 35 displays_[device] = base::WrapUnique(display_impl);
36 return display_impl; 36 return display_impl;
37 } 37 }
38 38
39 void VRServiceImpl::Bind(mojo::InterfaceRequest<mojom::VRService> request) {
40 // TODO(shaobo.yan@intel.com) : Keep one binding_ and use close and rebind.
41 binding_.reset(new mojo::Binding<mojom::VRService>(this, std::move(request)));
42 binding_->set_connection_error_handler(base::Bind(
43 &VRServiceImpl::RemoveFromDeviceManager, base::Unretained(this)));
44 }
45
46 void VRServiceImpl::RemoveFromDeviceManager() {
47 displays_.clear();
48 VRDeviceManager* device_manager = VRDeviceManager::GetInstance();
49 device_manager->RemoveService(this);
50 }
51
52 void VRServiceImpl::RemoveDevice(VRDevice* device) { 39 void VRServiceImpl::RemoveDevice(VRDevice* device) {
53 displays_.erase(device); 40 displays_.erase(device);
54 } 41 }
55 42
56 void VRServiceImpl::SetClient(mojom::VRServiceClientPtr service_client, 43 void VRServiceImpl::SetClient(mojom::VRServiceClientPtr service_client,
57 const SetClientCallback& callback) { 44 const SetClientCallback& callback) {
58 DCHECK(!client_.get()); 45 DCHECK(!client_.get());
59 46
60 client_ = std::move(service_client); 47 client_ = std::move(service_client);
61 VRDeviceManager* device_manager = VRDeviceManager::GetInstance(); 48 VRDeviceManager* device_manager = VRDeviceManager::GetInstance();
62 // Once a client has been connected AddService will force any VRDisplays to 49 // Once a client has been connected AddService will force any VRDisplays to
63 // send OnConnected to it so that it's populated with the currently active 50 // send OnConnected to it so that it's populated with the currently active
64 // displays. Thereafer it will stay up to date by virtue of listening for new 51 // displays. Thereafer it will stay up to date by virtue of listening for new
65 // connected events. 52 // connected events.
66 device_manager->AddService(this); 53 device_manager->AddService(this);
67 callback.Run(device_manager->GetNumberOfConnectedDevices()); 54 callback.Run(device_manager->GetNumberOfConnectedDevices());
68 } 55 }
69 56
70 void VRServiceImpl::SetListeningForActivate(bool listening) { 57 void VRServiceImpl::SetListeningForActivate(bool listening) {
71 listening_for_activate_ = listening; 58 listening_for_activate_ = listening;
72 VRDeviceManager* device_manager = VRDeviceManager::GetInstance(); 59 VRDeviceManager* device_manager = VRDeviceManager::GetInstance();
73 device_manager->ListeningForActivateChanged(listening); 60 device_manager->ListeningForActivateChanged(listening);
74 } 61 }
75 62
76 } // namespace device 63 } // namespace device
OLDNEW
« no previous file with comments | « device/vr/vr_service_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698