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

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

Issue 2537723002: Refine VRDevice Class (Closed)
Patch Set: address comments Created 4 years 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_device.h" 5 #include "device/vr/vr_device.h"
6 #include "device/vr/vr_device_provider.h" 6 #include "device/vr/vr_device_provider.h"
7 #include "device/vr/vr_service_impl.h" 7 #include "device/vr/vr_display_impl.h"
8 8
9 namespace device { 9 namespace device {
10 10
11 unsigned int VRDevice::next_id_ = 1; 11 unsigned int VRDevice::next_id_ = 1;
12 12
13 VRDevice::VRDevice() : presenting_service_(nullptr), id_(next_id_) { 13 VRDevice::VRDevice() : presenting_display_(nullptr), id_(next_id_) {
14 // Prevent wraparound. Devices with this ID will be treated as invalid. 14 // Prevent wraparound. Devices with this ID will be treated as invalid.
15 if (next_id_ != VR_DEVICE_LAST_ID) 15 if (next_id_ != VR_DEVICE_LAST_ID)
16 next_id_++; 16 next_id_++;
17 } 17 }
18 18
19 VRDevice::~VRDevice() {} 19 VRDevice::~VRDevice() {}
20 20
21 void VRDevice::RequestPresent(const base::Callback<void(bool)>& callback) { 21 void VRDevice::RequestPresent(const base::Callback<void(bool)>& callback) {
22 callback.Run(true); 22 callback.Run(true);
23 } 23 }
24 24
25 void VRDevice::SetSecureOrigin(bool secure_origin) {} 25 void VRDevice::SetSecureOrigin(bool secure_origin) {}
26 26
27 void VRDevice::AddService(VRServiceImpl* service) { 27 void VRDevice::AddDisplay(VRDisplayImpl* display) {
28 // Create a VRDisplayImpl for this service/device pair 28 displays_.insert(display);
29 VRDisplayImpl* display_impl = service->GetVRDisplayImpl(this);
30 displays_.insert(std::make_pair(service, display_impl));
31 } 29 }
32 30
33 void VRDevice::RemoveService(VRServiceImpl* service) { 31 void VRDevice::RemoveDisplay(VRDisplayImpl* display) {
34 if (IsPresentingService(service)) 32 if (CheckPresentingDisplay(display))
35 ExitPresent(); 33 ExitPresent();
36 displays_.erase(service); 34 displays_.erase(display);
37 } 35 }
38 36
39 bool VRDevice::IsAccessAllowed(VRServiceImpl* service) { 37 bool VRDevice::IsAccessAllowed(VRDisplayImpl* display) {
40 return (!presenting_service_ || presenting_service_ == service); 38 return (!presenting_display_ || presenting_display_ == display);
41 } 39 }
42 40
43 bool VRDevice::IsPresentingService(VRServiceImpl* service) { 41 bool VRDevice::CheckPresentingDisplay(VRDisplayImpl* display) {
44 return (presenting_service_ && presenting_service_ == service); 42 return (presenting_display_ && presenting_display_ == display);
45 } 43 }
46 44
47 void VRDevice::OnChanged() { 45 void VRDevice::OnChanged() {
48 mojom::VRDisplayInfoPtr vr_device_info = GetVRDevice(); 46 mojom::VRDisplayInfoPtr vr_device_info = GetVRDevice();
49 if (vr_device_info.is_null()) 47 if (vr_device_info.is_null())
50 return; 48 return;
51 49
52 for (const auto& display : displays_) 50 for (const auto& display : displays_)
53 display.second->client()->OnChanged(vr_device_info.Clone()); 51 display->client()->OnChanged(vr_device_info.Clone());
54 } 52 }
55 53
56 void VRDevice::OnExitPresent() { 54 void VRDevice::OnExitPresent() {
57 DisplayClientMap::iterator it = displays_.find(presenting_service_); 55 DisplaySet::iterator it = displays_.find(presenting_display_);
mthiesse 2016/11/30 13:59:04 nit: 'auto it = displays_.find(presenting_display_
58 if (it != displays_.end()) 56 if (it != displays_.end())
59 it->second->client()->OnExitPresent(); 57 (*it)->client()->OnExitPresent();
60 58
61 SetPresentingService(nullptr); 59 SetPresentingDisplay(nullptr);
62 } 60 }
63 61
64 void VRDevice::OnBlur() { 62 void VRDevice::OnBlur() {
65 for (const auto& display : displays_) 63 for (const auto& display : displays_)
66 display.second->client()->OnBlur(); 64 display->client()->OnBlur();
67 } 65 }
68 66
69 void VRDevice::OnFocus() { 67 void VRDevice::OnFocus() {
70 for (const auto& display : displays_) 68 for (const auto& display : displays_)
71 display.second->client()->OnFocus(); 69 display->client()->OnFocus();
72 } 70 }
73 71
74 void VRDevice::OnActivate(mojom::VRDisplayEventReason reason) { 72 void VRDevice::OnActivate(mojom::VRDisplayEventReason reason) {
75 for (const auto& display : displays_) 73 for (const auto& display : displays_)
76 display.second->client()->OnActivate(reason); 74 display->client()->OnActivate(reason);
77 } 75 }
78 76
79 void VRDevice::OnDeactivate(mojom::VRDisplayEventReason reason) { 77 void VRDevice::OnDeactivate(mojom::VRDisplayEventReason reason) {
80 for (const auto& display : displays_) 78 for (const auto& display : displays_)
81 display.second->client()->OnDeactivate(reason); 79 display->client()->OnDeactivate(reason);
82 } 80 }
83 81
84 void VRDevice::SetPresentingService(VRServiceImpl* service) { 82 void VRDevice::SetPresentingDisplay(VRDisplayImpl* display) {
85 presenting_service_ = service; 83 presenting_display_ = display;
86 } 84 }
87 85
88 } // namespace device 86 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698