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

Side by Side Diff: content/renderer/gamepad_shared_memory_reader.cc

Issue 2808093006: [Device Service] Move Gamepad Blink headers to be part of the Gamepad client library (Closed)
Patch Set: rebase and address comments Created 3 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/renderer/gamepad_shared_memory_reader.h" 5 #include "content/renderer/gamepad_shared_memory_reader.h"
6 6
7 #include "base/metrics/histogram_macros.h" 7 #include "base/metrics/histogram_macros.h"
8 #include "base/trace_event/trace_event.h" 8 #include "base/trace_event/trace_event.h"
9 #include "content/public/common/service_names.mojom.h" 9 #include "content/public/common/service_names.mojom.h"
10 #include "content/public/renderer/render_thread.h" 10 #include "content/public/renderer/render_thread.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 53
54 renderer_shared_buffer_mapping_ = 54 renderer_shared_buffer_mapping_ =
55 renderer_shared_buffer_handle_->Map(sizeof(GamepadHardwareBuffer)); 55 renderer_shared_buffer_handle_->Map(sizeof(GamepadHardwareBuffer));
56 CHECK(renderer_shared_buffer_mapping_); 56 CHECK(renderer_shared_buffer_mapping_);
57 void* memory = renderer_shared_buffer_mapping_.get(); 57 void* memory = renderer_shared_buffer_mapping_.get();
58 CHECK(memory); 58 CHECK(memory);
59 gamepad_hardware_buffer_ = 59 gamepad_hardware_buffer_ =
60 static_cast<GamepadHardwareBuffer*>(memory); 60 static_cast<GamepadHardwareBuffer*>(memory);
61 } 61 }
62 62
63 void GamepadSharedMemoryReader::SampleGamepads(blink::WebGamepads& gamepads) { 63 void GamepadSharedMemoryReader::SampleGamepads(device::Gamepads& gamepads) {
64 // Blink should have started observing at that point. 64 // Blink should have started observing at that point.
65 CHECK(is_observing()); 65 CHECK(is_observing());
66 66
67 // ========== 67 // ==========
68 // DANGER 68 // DANGER
69 // ========== 69 // ==========
70 // 70 //
71 // This logic is duplicated in Pepper as well. If you change it, that also 71 // This logic is duplicated in Pepper as well. If you change it, that also
72 // needs to be in sync. See ppapi/proxy/gamepad_resource.cc. 72 // needs to be in sync. See ppapi/proxy/gamepad_resource.cc.
73 blink::WebGamepads read_into; 73 device::Gamepads read_into;
74 TRACE_EVENT0("GAMEPAD", "SampleGamepads"); 74 TRACE_EVENT0("GAMEPAD", "SampleGamepads");
75 75
76 if (!renderer_shared_buffer_handle_.is_valid()) 76 if (!renderer_shared_buffer_handle_.is_valid())
77 return; 77 return;
78 78
79 // Only try to read this many times before failing to avoid waiting here 79 // Only try to read this many times before failing to avoid waiting here
80 // very long in case of contention with the writer. TODO(scottmg) Tune this 80 // very long in case of contention with the writer. TODO(scottmg) Tune this
81 // number (as low as 1?) if histogram shows distribution as mostly 81 // number (as low as 1?) if histogram shows distribution as mostly
82 // 0-and-maximum. 82 // 0-and-maximum.
83 const int kMaximumContentionCount = 10; 83 const int kMaximumContentionCount = 10;
(...skipping 16 matching lines...) Expand all
100 } 100 }
101 101
102 // New data was read successfully, copy it into the output buffer. 102 // New data was read successfully, copy it into the output buffer.
103 memcpy(&gamepads, &read_into, sizeof(gamepads)); 103 memcpy(&gamepads, &read_into, sizeof(gamepads));
104 104
105 if (!ever_interacted_with_) { 105 if (!ever_interacted_with_) {
106 // Clear the connected flag if the user hasn't interacted with any of the 106 // Clear the connected flag if the user hasn't interacted with any of the
107 // gamepads to prevent fingerprinting. The actual data is not cleared. 107 // gamepads to prevent fingerprinting. The actual data is not cleared.
108 // WebKit will only copy out data into the JS buffers for connected 108 // WebKit will only copy out data into the JS buffers for connected
109 // gamepads so this is sufficient. 109 // gamepads so this is sufficient.
110 for (unsigned i = 0; i < blink::WebGamepads::kItemsLengthCap; i++) 110 for (unsigned i = 0; i < device::Gamepads::kItemsLengthCap; i++)
111 gamepads.items[i].connected = false; 111 gamepads.items[i].connected = false;
112 } 112 }
113 } 113 }
114 114
115 GamepadSharedMemoryReader::~GamepadSharedMemoryReader() { 115 GamepadSharedMemoryReader::~GamepadSharedMemoryReader() {
116 StopIfObserving(); 116 StopIfObserving();
117 } 117 }
118 118
119 void GamepadSharedMemoryReader::GamepadConnected( 119 void GamepadSharedMemoryReader::GamepadConnected(
120 int index, 120 int index,
121 const blink::WebGamepad& gamepad) { 121 const device::Gamepad& gamepad) {
122 // The browser already checks if the user actually interacted with a device. 122 // The browser already checks if the user actually interacted with a device.
123 ever_interacted_with_ = true; 123 ever_interacted_with_ = true;
124 124
125 if (listener()) 125 if (listener())
126 listener()->DidConnectGamepad(index, gamepad); 126 listener()->DidConnectGamepad(index, gamepad);
127 } 127 }
128 128
129 void GamepadSharedMemoryReader::GamepadDisconnected( 129 void GamepadSharedMemoryReader::GamepadDisconnected(
130 int index, 130 int index,
131 const blink::WebGamepad& gamepad) { 131 const device::Gamepad& gamepad) {
132 if (listener()) 132 if (listener())
133 listener()->DidDisconnectGamepad(index, gamepad); 133 listener()->DidDisconnectGamepad(index, gamepad);
134 } 134 }
135 135
136 } // namespace content 136 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/gamepad_shared_memory_reader.h ('k') | content/renderer/pepper/event_conversion.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698