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

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

Issue 2466073002: Movw GamepadService out of content/browser/ and into device/ (Closed)
Patch Set: Fixed everything but one unittest Created 4 years, 1 month 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 "third_party/WebKit/public/platform/WebGamepadListener.h" 12 #include "third_party/WebKit/public/platform/WebGamepadListener.h"
14 #include "third_party/WebKit/public/platform/WebPlatformEventListener.h" 13 #include "third_party/WebKit/public/platform/WebPlatformEventListener.h"
15 14
16 namespace content { 15 namespace content {
17 16
18 GamepadSharedMemoryReader::GamepadSharedMemoryReader(RenderThread* thread) 17 GamepadSharedMemoryReader::GamepadSharedMemoryReader(RenderThread* thread)
19 : RendererGamepadProvider(thread), 18 : RendererGamepadProvider(thread),
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 return; 67 return;
69 68
70 // Only try to read this many times before failing to avoid waiting here 69 // Only try to read this many times before failing to avoid waiting here
71 // very long in case of contention with the writer. TODO(scottmg) Tune this 70 // very long in case of contention with the writer. TODO(scottmg) Tune this
72 // number (as low as 1?) if histogram shows distribution as mostly 71 // number (as low as 1?) if histogram shows distribution as mostly
73 // 0-and-maximum. 72 // 0-and-maximum.
74 const int kMaximumContentionCount = 10; 73 const int kMaximumContentionCount = 10;
75 int contention_count = -1; 74 int contention_count = -1;
76 base::subtle::Atomic32 version; 75 base::subtle::Atomic32 version;
77 do { 76 do {
78 version = gamepad_hardware_buffer_->sequence.ReadBegin(); 77 version = gamepad_hardware_buffer_->seqlock.ReadBegin();
79 memcpy(&read_into, &gamepad_hardware_buffer_->buffer, sizeof(read_into)); 78 memcpy(&read_into, &gamepad_hardware_buffer_->data, sizeof(read_into));
80 ++contention_count; 79 ++contention_count;
81 if (contention_count == kMaximumContentionCount) 80 if (contention_count == kMaximumContentionCount)
82 break; 81 break;
83 } while (gamepad_hardware_buffer_->sequence.ReadRetry(version)); 82 } while (gamepad_hardware_buffer_->seqlock.ReadRetry(version));
84 UMA_HISTOGRAM_COUNTS("Gamepad.ReadContentionCount", contention_count); 83 UMA_HISTOGRAM_COUNTS("Gamepad.ReadContentionCount", contention_count);
85 84
86 if (contention_count >= kMaximumContentionCount) { 85 if (contention_count >= kMaximumContentionCount) {
87 // We failed to successfully read, presumably because the hardware 86 // We failed to successfully read, presumably because the hardware
88 // thread was taking unusually long. Don't copy the data to the output 87 // thread was taking unusually long. Don't copy the data to the output
89 // buffer, and simply leave what was there before. 88 // buffer, and simply leave what was there before.
90 return; 89 return;
91 } 90 }
92 91
93 // New data was read successfully, copy it into the output buffer. 92 // New data was read successfully, copy it into the output buffer.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } 128 }
130 129
131 void GamepadSharedMemoryReader::OnGamepadDisconnected( 130 void GamepadSharedMemoryReader::OnGamepadDisconnected(
132 int index, 131 int index,
133 const blink::WebGamepad& gamepad) { 132 const blink::WebGamepad& gamepad) {
134 if (listener()) 133 if (listener())
135 listener()->didDisconnectGamepad(index, gamepad); 134 listener()->didDisconnectGamepad(index, gamepad);
136 } 135 }
137 136
138 } // namespace content 137 } // 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