Commit fa3e7760 authored by Marina Ciocea's avatar Marina Ciocea Committed by Commit Bot

Use uint32_t instead of size_t in KeyboardEventCounter.

Needed for sending media::UserInputMonitor::GetKeyPressCount() over IPC.

Bug: https://crbug.com/828864
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: Ifa391e3f6b9c75971616eb7ed6596f73bc9ddec8
Reviewed-on: https://chromium-review.googlesource.com/1025814
Commit-Queue: Marina Ciocea <marinaciocea@chromium.org>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553360}
parent 950748a2
......@@ -109,7 +109,7 @@ class MockUserInputMonitor : public media::UserInputMonitor {
public:
MockUserInputMonitor() {}
size_t GetKeyPressCount() const { return 0; }
uint32_t GetKeyPressCount() const { return 0; }
MOCK_METHOD0(StartKeyboardMonitoring, void());
MOCK_METHOD0(StopKeyboardMonitoring, void());
......
......@@ -87,7 +87,7 @@ class MockUserInputMonitor : public UserInputMonitor {
public:
MockUserInputMonitor() = default;
size_t GetKeyPressCount() const { return 0; }
uint32_t GetKeyPressCount() const { return 0; }
MOCK_METHOD0(StartKeyboardMonitoring, void());
MOCK_METHOD0(StopKeyboardMonitoring, void());
......
......@@ -4,7 +4,6 @@
#include "media/base/keyboard_event_counter.h"
#include "base/atomicops.h"
#include "base/logging.h"
namespace media {
......@@ -20,17 +19,15 @@ void KeyboardEventCounter::OnKeyboardEvent(ui::EventType event,
if (pressed_keys_.find(key_code) != pressed_keys_.end())
return;
pressed_keys_.insert(key_code);
base::subtle::NoBarrier_AtomicIncrement(
reinterpret_cast<base::subtle::AtomicWord*>(&total_key_presses_), 1);
++total_key_presses_;
} else {
DCHECK_EQ(ui::ET_KEY_RELEASED, event);
pressed_keys_.erase(key_code);
}
}
size_t KeyboardEventCounter::GetKeyPressCount() const {
return base::subtle::NoBarrier_Load(
reinterpret_cast<const base::subtle::AtomicWord*>(&total_key_presses_));
uint32_t KeyboardEventCounter::GetKeyPressCount() const {
return total_key_presses_.load();
}
} // namespace media
......@@ -7,10 +7,10 @@
#include <stddef.h>
#include <atomic>
#include <set>
#include "base/macros.h"
#include "base/synchronization/lock.h"
#include "media/base/media_export.h"
#include "ui/events/event_constants.h"
#include "ui/events/keycodes/keyboard_codes.h"
......@@ -28,7 +28,7 @@ class MEDIA_EXPORT KeyboardEventCounter {
// Returns the total number of keypresses since its creation or last Reset()
// call. Can be called on any thread.
size_t GetKeyPressCount() const;
uint32_t GetKeyPressCount() const;
// The client should call this method on key down or key up events.
// Must be called on a single thread.
......@@ -38,7 +38,7 @@ class MEDIA_EXPORT KeyboardEventCounter {
// The set of keys currently held down.
std::set<ui::KeyboardCode> pressed_keys_;
size_t total_key_presses_;
std::atomic<uint32_t> total_key_presses_;
DISALLOW_COPY_AND_ASSIGN(KeyboardEventCounter);
};
......
......@@ -45,7 +45,7 @@ class MEDIA_EXPORT UserInputMonitor {
// use the difference between the values returned at two times to get the
// number of keypresses happened within that time period, but should not make
// any assumption on the initial value.
virtual size_t GetKeyPressCount() const = 0;
virtual uint32_t GetKeyPressCount() const = 0;
private:
virtual void StartKeyboardMonitoring() = 0;
......
......@@ -41,7 +41,7 @@ class UserInputMonitorLinuxCore
// DestructionObserver overrides.
void WillDestroyCurrentMessageLoop() override;
size_t GetKeyPressCount() const;
uint32_t GetKeyPressCount() const;
void StartMonitor();
void StopMonitor();
......@@ -74,7 +74,7 @@ class UserInputMonitorLinux : public UserInputMonitor {
~UserInputMonitorLinux() override;
// Public UserInputMonitor overrides.
size_t GetKeyPressCount() const override;
uint32_t GetKeyPressCount() const override;
private:
// Private UserInputMonitor overrides.
......@@ -107,7 +107,7 @@ void UserInputMonitorLinuxCore::WillDestroyCurrentMessageLoop() {
StopMonitor();
}
size_t UserInputMonitorLinuxCore::GetKeyPressCount() const {
uint32_t UserInputMonitorLinuxCore::GetKeyPressCount() const {
return counter_.GetKeyPressCount();
}
......@@ -268,7 +268,7 @@ UserInputMonitorLinux::~UserInputMonitorLinux() {
delete core_;
}
size_t UserInputMonitorLinux::GetKeyPressCount() const {
uint32_t UserInputMonitorLinux::GetKeyPressCount() const {
return core_->GetKeyPressCount();
}
......
......@@ -18,7 +18,7 @@ class UserInputMonitorMac : public UserInputMonitor {
UserInputMonitorMac();
~UserInputMonitorMac() override;
size_t GetKeyPressCount() const override;
uint32_t GetKeyPressCount() const override;
private:
void StartKeyboardMonitoring() override;
......@@ -31,7 +31,7 @@ UserInputMonitorMac::UserInputMonitorMac() {}
UserInputMonitorMac::~UserInputMonitorMac() {}
size_t UserInputMonitorMac::GetKeyPressCount() const {
uint32_t UserInputMonitorMac::GetKeyPressCount() const {
// Use |kCGEventSourceStateHIDSystemState| since we only want to count
// hardware generated events.
return CGEventSourceCounterForEventType(kCGEventSourceStateHIDSystemState,
......
......@@ -55,7 +55,7 @@ class UserInputMonitorWinCore
// DestructionObserver overrides.
void WillDestroyCurrentMessageLoop() override;
size_t GetKeyPressCount() const;
uint32_t GetKeyPressCount() const;
void StartMonitor();
void StopMonitor();
......@@ -85,7 +85,7 @@ class UserInputMonitorWin : public UserInputMonitor {
~UserInputMonitorWin() override;
// Public UserInputMonitor overrides.
size_t GetKeyPressCount() const override;
uint32_t GetKeyPressCount() const override;
private:
// Private UserInputMonitor overrides.
......@@ -111,7 +111,7 @@ void UserInputMonitorWinCore::WillDestroyCurrentMessageLoop() {
StopMonitor();
}
size_t UserInputMonitorWinCore::GetKeyPressCount() const {
uint32_t UserInputMonitorWinCore::GetKeyPressCount() const {
return counter_.GetKeyPressCount();
}
......@@ -231,7 +231,7 @@ UserInputMonitorWin::~UserInputMonitorWin() {
delete core_;
}
size_t UserInputMonitorWin::GetKeyPressCount() const {
uint32_t UserInputMonitorWin::GetKeyPressCount() const {
return core_->GetKeyPressCount();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment