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

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

Issue 2563483006: Move gamepad_service out of content/ and into device/ (Closed)
Patch Set: addressed Blundell's review 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
« no previous file with comments | « content/renderer/gamepad_shared_memory_reader.h ('k') | content/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/common/gamepad_hardware_buffer.h"
10 #include "content/public/renderer/render_thread.h" 9 #include "content/public/renderer/render_thread.h"
11 #include "content/renderer/renderer_blink_platform_impl.h" 10 #include "content/renderer/renderer_blink_platform_impl.h"
12 #include "ipc/ipc_sync_message_filter.h" 11 #include "ipc/ipc_sync_message_filter.h"
13 #include "services/service_manager/public/cpp/interface_provider.h" 12 #include "services/service_manager/public/cpp/interface_provider.h"
14 #include "third_party/WebKit/public/platform/WebGamepadListener.h" 13 #include "third_party/WebKit/public/platform/WebGamepadListener.h"
15 #include "third_party/WebKit/public/platform/WebPlatformEventListener.h" 14 #include "third_party/WebKit/public/platform/WebPlatformEventListener.h"
16 15
17 namespace content { 16 namespace content {
18 17
19 GamepadSharedMemoryReader::GamepadSharedMemoryReader(RenderThread* thread) 18 GamepadSharedMemoryReader::GamepadSharedMemoryReader(RenderThread* thread)
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 return; 84 return;
86 85
87 // Only try to read this many times before failing to avoid waiting here 86 // Only try to read this many times before failing to avoid waiting here
88 // very long in case of contention with the writer. TODO(scottmg) Tune this 87 // very long in case of contention with the writer. TODO(scottmg) Tune this
89 // number (as low as 1?) if histogram shows distribution as mostly 88 // number (as low as 1?) if histogram shows distribution as mostly
90 // 0-and-maximum. 89 // 0-and-maximum.
91 const int kMaximumContentionCount = 10; 90 const int kMaximumContentionCount = 10;
92 int contention_count = -1; 91 int contention_count = -1;
93 base::subtle::Atomic32 version; 92 base::subtle::Atomic32 version;
94 do { 93 do {
95 version = gamepad_hardware_buffer_->sequence.ReadBegin(); 94 version = gamepad_hardware_buffer_->seqlock.ReadBegin();
96 memcpy(&read_into, &gamepad_hardware_buffer_->buffer, sizeof(read_into)); 95 memcpy(&read_into, &gamepad_hardware_buffer_->data, sizeof(read_into));
97 ++contention_count; 96 ++contention_count;
98 if (contention_count == kMaximumContentionCount) 97 if (contention_count == kMaximumContentionCount)
99 break; 98 break;
100 } while (gamepad_hardware_buffer_->sequence.ReadRetry(version)); 99 } while (gamepad_hardware_buffer_->seqlock.ReadRetry(version));
101 UMA_HISTOGRAM_COUNTS("Gamepad.ReadContentionCount", contention_count); 100 UMA_HISTOGRAM_COUNTS("Gamepad.ReadContentionCount", contention_count);
102 101
103 if (contention_count >= kMaximumContentionCount) { 102 if (contention_count >= kMaximumContentionCount) {
104 // We failed to successfully read, presumably because the hardware 103 // We failed to successfully read, presumably because the hardware
105 // thread was taking unusually long. Don't copy the data to the output 104 // thread was taking unusually long. Don't copy the data to the output
106 // buffer, and simply leave what was there before. 105 // buffer, and simply leave what was there before.
107 return; 106 return;
108 } 107 }
109 108
110 // New data was read successfully, copy it into the output buffer. 109 // New data was read successfully, copy it into the output buffer.
(...skipping 24 matching lines...) Expand all
135 } 134 }
136 135
137 void GamepadSharedMemoryReader::GamepadDisconnected( 136 void GamepadSharedMemoryReader::GamepadDisconnected(
138 int index, 137 int index,
139 const blink::WebGamepad& gamepad) { 138 const blink::WebGamepad& gamepad) {
140 if (listener()) 139 if (listener())
141 listener()->didDisconnectGamepad(index, gamepad); 140 listener()->didDisconnectGamepad(index, gamepad);
142 } 141 }
143 142
144 } // namespace content 143 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/gamepad_shared_memory_reader.h ('k') | content/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698