OLD | NEW |
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/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "content/common/gamepad_messages.h" | 9 #include "content/common/gamepad_messages.h" |
10 #include "content/common/gamepad_user_gesture.h" | 10 #include "content/common/gamepad_user_gesture.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 return; | 28 return; |
29 renderer_shared_memory_.reset( | 29 renderer_shared_memory_.reset( |
30 new base::SharedMemory(renderer_shared_memory_handle_, true)); | 30 new base::SharedMemory(renderer_shared_memory_handle_, true)); |
31 CHECK(renderer_shared_memory_->Map(sizeof(GamepadHardwareBuffer))); | 31 CHECK(renderer_shared_memory_->Map(sizeof(GamepadHardwareBuffer))); |
32 void *memory = renderer_shared_memory_->memory(); | 32 void *memory = renderer_shared_memory_->memory(); |
33 CHECK(memory); | 33 CHECK(memory); |
34 gamepad_hardware_buffer_ = | 34 gamepad_hardware_buffer_ = |
35 static_cast<GamepadHardwareBuffer*>(memory); | 35 static_cast<GamepadHardwareBuffer*>(memory); |
36 } | 36 } |
37 | 37 |
38 void GamepadSharedMemoryReader::SampleGamepads(WebKit::WebGamepads& gamepads) { | 38 void GamepadSharedMemoryReader::SampleGamepads(blink::WebGamepads& gamepads) { |
39 // ========== | 39 // ========== |
40 // DANGER | 40 // DANGER |
41 // ========== | 41 // ========== |
42 // | 42 // |
43 // This logic is duplicated in Pepper as well. If you change it, that also | 43 // This logic is duplicated in Pepper as well. If you change it, that also |
44 // needs to be in sync. See ppapi/proxy/gamepad_resource.cc. | 44 // needs to be in sync. See ppapi/proxy/gamepad_resource.cc. |
45 WebKit::WebGamepads read_into; | 45 blink::WebGamepads read_into; |
46 TRACE_EVENT0("GAMEPAD", "SampleGamepads"); | 46 TRACE_EVENT0("GAMEPAD", "SampleGamepads"); |
47 | 47 |
48 if (!base::SharedMemory::IsHandleValid(renderer_shared_memory_handle_)) | 48 if (!base::SharedMemory::IsHandleValid(renderer_shared_memory_handle_)) |
49 return; | 49 return; |
50 | 50 |
51 // Only try to read this many times before failing to avoid waiting here | 51 // Only try to read this many times before failing to avoid waiting here |
52 // very long in case of contention with the writer. TODO(scottmg) Tune this | 52 // very long in case of contention with the writer. TODO(scottmg) Tune this |
53 // number (as low as 1?) if histogram shows distribution as mostly | 53 // number (as low as 1?) if histogram shows distribution as mostly |
54 // 0-and-maximum. | 54 // 0-and-maximum. |
55 const int kMaximumContentionCount = 10; | 55 const int kMaximumContentionCount = 10; |
(...skipping 19 matching lines...) Expand all Loading... |
75 memcpy(&gamepads, &read_into, sizeof(gamepads)); | 75 memcpy(&gamepads, &read_into, sizeof(gamepads)); |
76 | 76 |
77 if (!ever_interacted_with_) { | 77 if (!ever_interacted_with_) { |
78 if (GamepadsHaveUserGesture(gamepads)) { | 78 if (GamepadsHaveUserGesture(gamepads)) { |
79 ever_interacted_with_ = true; | 79 ever_interacted_with_ = true; |
80 } else { | 80 } else { |
81 // Clear the connected flag if the user hasn't interacted with any of the | 81 // Clear the connected flag if the user hasn't interacted with any of the |
82 // gamepads to prevent fingerprinting. The actual data is not cleared. | 82 // gamepads to prevent fingerprinting. The actual data is not cleared. |
83 // WebKit will only copy out data into the JS buffers for connected | 83 // WebKit will only copy out data into the JS buffers for connected |
84 // gamepads so this is sufficient. | 84 // gamepads so this is sufficient. |
85 for (unsigned i = 0; i < WebKit::WebGamepads::itemsLengthCap; i++) | 85 for (unsigned i = 0; i < blink::WebGamepads::itemsLengthCap; i++) |
86 gamepads.items[i].connected = false; | 86 gamepads.items[i].connected = false; |
87 } | 87 } |
88 } | 88 } |
89 } | 89 } |
90 | 90 |
91 GamepadSharedMemoryReader::~GamepadSharedMemoryReader() { | 91 GamepadSharedMemoryReader::~GamepadSharedMemoryReader() { |
92 RenderThread::Get()->Send(new GamepadHostMsg_StopPolling()); | 92 RenderThread::Get()->Send(new GamepadHostMsg_StopPolling()); |
93 } | 93 } |
94 | 94 |
95 } // namespace content | 95 } // namespace content |
OLD | NEW |