OLD | NEW |
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" |
(...skipping 19 matching lines...) Expand all Loading... |
30 DisplayImplMap::iterator it = displays_.find(device); | 30 DisplayImplMap::iterator 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) { | 39 void VRServiceImpl::Bind(mojo::InterfaceRequest<mojom::VRService> request) { |
40 // TODO(shaobo.yan@intel.com) : Keep one binding_ and use close and rebind. | 40 if (!binding_) |
41 binding_.reset(new mojo::Binding<mojom::VRService>(this, std::move(request))); | 41 binding_.reset( |
| 42 new mojo::Binding<mojom::VRService>(this, std::move(request))); |
| 43 else |
| 44 binding_->Bind(std::move(request)); |
42 binding_->set_connection_error_handler(base::Bind( | 45 binding_->set_connection_error_handler(base::Bind( |
43 &VRServiceImpl::RemoveFromDeviceManager, base::Unretained(this))); | 46 &VRServiceImpl::RemoveFromDeviceManager, base::Unretained(this))); |
44 } | 47 } |
45 | 48 |
46 void VRServiceImpl::RemoveFromDeviceManager() { | 49 void VRServiceImpl::RemoveFromDeviceManager() { |
47 displays_.clear(); | 50 // Remove VRDisplayImpl in service/device pair. |
| 51 // displays_ is a map which first element is a VRDevice pointer, |
| 52 // the second element is a VRDisplayImpl pointer. |
| 53 for (DisplayImplMap::iterator it = displays_.begin(); it != displays_.end(); |
| 54 ++it) { |
| 55 it->first->RemoveDisplay(it->second.get()); |
| 56 } |
| 57 |
48 VRDeviceManager* device_manager = VRDeviceManager::GetInstance(); | 58 VRDeviceManager* device_manager = VRDeviceManager::GetInstance(); |
49 device_manager->RemoveService(this); | 59 device_manager->RemoveService(this); |
| 60 displays_.clear(); |
50 } | 61 } |
51 | 62 |
52 void VRServiceImpl::RemoveDevice(VRDevice* device) { | 63 void VRServiceImpl::RemoveDevice(VRDevice* device) { |
53 displays_.erase(device); | 64 displays_.erase(device); |
54 } | 65 } |
55 | 66 |
56 void VRServiceImpl::SetClient(mojom::VRServiceClientPtr service_client, | 67 void VRServiceImpl::SetClient(mojom::VRServiceClientPtr service_client, |
57 const SetClientCallback& callback) { | 68 const SetClientCallback& callback) { |
58 DCHECK(!client_.get()); | 69 DCHECK(!client_.get()); |
59 | |
60 client_ = std::move(service_client); | 70 client_ = std::move(service_client); |
61 VRDeviceManager* device_manager = VRDeviceManager::GetInstance(); | 71 VRDeviceManager* device_manager = VRDeviceManager::GetInstance(); |
62 // Once a client has been connected AddService will force any VRDisplays to | 72 // 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 | 73 // 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 | 74 // displays. Thereafer it will stay up to date by virtue of listening for new |
65 // connected events. | 75 // connected events. |
66 device_manager->AddService(this); | 76 device_manager->AddService(this); |
67 callback.Run(device_manager->GetNumberOfConnectedDevices()); | 77 callback.Run(device_manager->GetNumberOfConnectedDevices()); |
68 } | 78 } |
69 | 79 |
70 void VRServiceImpl::SetListeningForActivate(bool listening) { | 80 void VRServiceImpl::SetListeningForActivate(bool listening) { |
71 listening_for_activate_ = listening; | 81 listening_for_activate_ = listening; |
72 VRDeviceManager* device_manager = VRDeviceManager::GetInstance(); | 82 VRDeviceManager* device_manager = VRDeviceManager::GetInstance(); |
73 device_manager->ListeningForActivateChanged(listening); | 83 device_manager->ListeningForActivateChanged(listening); |
74 } | 84 } |
75 | 85 |
76 } // namespace device | 86 } // namespace device |
OLD | NEW |