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 { ...@@ -109,7 +109,7 @@ class MockUserInputMonitor : public media::UserInputMonitor {
public: public:
MockUserInputMonitor() {} MockUserInputMonitor() {}
size_t GetKeyPressCount() const { return 0; } uint32_t GetKeyPressCount() const { return 0; }
MOCK_METHOD0(StartKeyboardMonitoring, void()); MOCK_METHOD0(StartKeyboardMonitoring, void());
MOCK_METHOD0(StopKeyboardMonitoring, void()); MOCK_METHOD0(StopKeyboardMonitoring, void());
......
...@@ -87,7 +87,7 @@ class MockUserInputMonitor : public UserInputMonitor { ...@@ -87,7 +87,7 @@ class MockUserInputMonitor : public UserInputMonitor {
public: public:
MockUserInputMonitor() = default; MockUserInputMonitor() = default;
size_t GetKeyPressCount() const { return 0; } uint32_t GetKeyPressCount() const { return 0; }
MOCK_METHOD0(StartKeyboardMonitoring, void()); MOCK_METHOD0(StartKeyboardMonitoring, void());
MOCK_METHOD0(StopKeyboardMonitoring, void()); MOCK_METHOD0(StopKeyboardMonitoring, void());
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
#include "media/base/keyboard_event_counter.h" #include "media/base/keyboard_event_counter.h"
#include "base/atomicops.h"
#include "base/logging.h" #include "base/logging.h"
namespace media { namespace media {
...@@ -20,17 +19,15 @@ void KeyboardEventCounter::OnKeyboardEvent(ui::EventType event, ...@@ -20,17 +19,15 @@ void KeyboardEventCounter::OnKeyboardEvent(ui::EventType event,
if (pressed_keys_.find(key_code) != pressed_keys_.end()) if (pressed_keys_.find(key_code) != pressed_keys_.end())
return; return;
pressed_keys_.insert(key_code); pressed_keys_.insert(key_code);
base::subtle::NoBarrier_AtomicIncrement( ++total_key_presses_;
reinterpret_cast<base::subtle::AtomicWord*>(&total_key_presses_), 1);
} else { } else {
DCHECK_EQ(ui::ET_KEY_RELEASED, event); DCHECK_EQ(ui::ET_KEY_RELEASED, event);
pressed_keys_.erase(key_code); pressed_keys_.erase(key_code);
} }
} }
size_t KeyboardEventCounter::GetKeyPressCount() const { uint32_t KeyboardEventCounter::GetKeyPressCount() const {
return base::subtle::NoBarrier_Load( return total_key_presses_.load();
reinterpret_cast<const base::subtle::AtomicWord*>(&total_key_presses_));
} }
} // namespace media } // namespace media
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
#include <stddef.h> #include <stddef.h>
#include <atomic>
#include <set> #include <set>
#include "base/macros.h" #include "base/macros.h"
#include "base/synchronization/lock.h"
#include "media/base/media_export.h" #include "media/base/media_export.h"
#include "ui/events/event_constants.h" #include "ui/events/event_constants.h"
#include "ui/events/keycodes/keyboard_codes.h" #include "ui/events/keycodes/keyboard_codes.h"
...@@ -28,7 +28,7 @@ class MEDIA_EXPORT KeyboardEventCounter { ...@@ -28,7 +28,7 @@ class MEDIA_EXPORT KeyboardEventCounter {
// Returns the total number of keypresses since its creation or last Reset() // Returns the total number of keypresses since its creation or last Reset()
// call. Can be called on any thread. // 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. // The client should call this method on key down or key up events.
// Must be called on a single thread. // Must be called on a single thread.
...@@ -38,7 +38,7 @@ class MEDIA_EXPORT KeyboardEventCounter { ...@@ -38,7 +38,7 @@ class MEDIA_EXPORT KeyboardEventCounter {
// The set of keys currently held down. // The set of keys currently held down.
std::set<ui::KeyboardCode> pressed_keys_; std::set<ui::KeyboardCode> pressed_keys_;
size_t total_key_presses_; std::atomic<uint32_t> total_key_presses_;
DISALLOW_COPY_AND_ASSIGN(KeyboardEventCounter); DISALLOW_COPY_AND_ASSIGN(KeyboardEventCounter);
}; };
......
...@@ -45,7 +45,7 @@ class MEDIA_EXPORT UserInputMonitor { ...@@ -45,7 +45,7 @@ class MEDIA_EXPORT UserInputMonitor {
// use the difference between the values returned at two times to get the // 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 // number of keypresses happened within that time period, but should not make
// any assumption on the initial value. // any assumption on the initial value.
virtual size_t GetKeyPressCount() const = 0; virtual uint32_t GetKeyPressCount() const = 0;
private: private:
virtual void StartKeyboardMonitoring() = 0; virtual void StartKeyboardMonitoring() = 0;
......
...@@ -41,7 +41,7 @@ class UserInputMonitorLinuxCore ...@@ -41,7 +41,7 @@ class UserInputMonitorLinuxCore
// DestructionObserver overrides. // DestructionObserver overrides.
void WillDestroyCurrentMessageLoop() override; void WillDestroyCurrentMessageLoop() override;
size_t GetKeyPressCount() const; uint32_t GetKeyPressCount() const;
void StartMonitor(); void StartMonitor();
void StopMonitor(); void StopMonitor();
...@@ -74,7 +74,7 @@ class UserInputMonitorLinux : public UserInputMonitor { ...@@ -74,7 +74,7 @@ class UserInputMonitorLinux : public UserInputMonitor {
~UserInputMonitorLinux() override; ~UserInputMonitorLinux() override;
// Public UserInputMonitor overrides. // Public UserInputMonitor overrides.
size_t GetKeyPressCount() const override; uint32_t GetKeyPressCount() const override;
private: private:
// Private UserInputMonitor overrides. // Private UserInputMonitor overrides.
...@@ -107,7 +107,7 @@ void UserInputMonitorLinuxCore::WillDestroyCurrentMessageLoop() { ...@@ -107,7 +107,7 @@ void UserInputMonitorLinuxCore::WillDestroyCurrentMessageLoop() {
StopMonitor(); StopMonitor();
} }
size_t UserInputMonitorLinuxCore::GetKeyPressCount() const { uint32_t UserInputMonitorLinuxCore::GetKeyPressCount() const {
return counter_.GetKeyPressCount(); return counter_.GetKeyPressCount();
} }
...@@ -268,7 +268,7 @@ UserInputMonitorLinux::~UserInputMonitorLinux() { ...@@ -268,7 +268,7 @@ UserInputMonitorLinux::~UserInputMonitorLinux() {
delete core_; delete core_;
} }
size_t UserInputMonitorLinux::GetKeyPressCount() const { uint32_t UserInputMonitorLinux::GetKeyPressCount() const {
return core_->GetKeyPressCount(); return core_->GetKeyPressCount();
} }
......
...@@ -18,7 +18,7 @@ class UserInputMonitorMac : public UserInputMonitor { ...@@ -18,7 +18,7 @@ class UserInputMonitorMac : public UserInputMonitor {
UserInputMonitorMac(); UserInputMonitorMac();
~UserInputMonitorMac() override; ~UserInputMonitorMac() override;
size_t GetKeyPressCount() const override; uint32_t GetKeyPressCount() const override;
private: private:
void StartKeyboardMonitoring() override; void StartKeyboardMonitoring() override;
...@@ -31,7 +31,7 @@ UserInputMonitorMac::UserInputMonitorMac() {} ...@@ -31,7 +31,7 @@ UserInputMonitorMac::UserInputMonitorMac() {}
UserInputMonitorMac::~UserInputMonitorMac() {} UserInputMonitorMac::~UserInputMonitorMac() {}
size_t UserInputMonitorMac::GetKeyPressCount() const { uint32_t UserInputMonitorMac::GetKeyPressCount() const {
// Use |kCGEventSourceStateHIDSystemState| since we only want to count // Use |kCGEventSourceStateHIDSystemState| since we only want to count
// hardware generated events. // hardware generated events.
return CGEventSourceCounterForEventType(kCGEventSourceStateHIDSystemState, return CGEventSourceCounterForEventType(kCGEventSourceStateHIDSystemState,
......
...@@ -55,7 +55,7 @@ class UserInputMonitorWinCore ...@@ -55,7 +55,7 @@ class UserInputMonitorWinCore
// DestructionObserver overrides. // DestructionObserver overrides.
void WillDestroyCurrentMessageLoop() override; void WillDestroyCurrentMessageLoop() override;
size_t GetKeyPressCount() const; uint32_t GetKeyPressCount() const;
void StartMonitor(); void StartMonitor();
void StopMonitor(); void StopMonitor();
...@@ -85,7 +85,7 @@ class UserInputMonitorWin : public UserInputMonitor { ...@@ -85,7 +85,7 @@ class UserInputMonitorWin : public UserInputMonitor {
~UserInputMonitorWin() override; ~UserInputMonitorWin() override;
// Public UserInputMonitor overrides. // Public UserInputMonitor overrides.
size_t GetKeyPressCount() const override; uint32_t GetKeyPressCount() const override;
private: private:
// Private UserInputMonitor overrides. // Private UserInputMonitor overrides.
...@@ -111,7 +111,7 @@ void UserInputMonitorWinCore::WillDestroyCurrentMessageLoop() { ...@@ -111,7 +111,7 @@ void UserInputMonitorWinCore::WillDestroyCurrentMessageLoop() {
StopMonitor(); StopMonitor();
} }
size_t UserInputMonitorWinCore::GetKeyPressCount() const { uint32_t UserInputMonitorWinCore::GetKeyPressCount() const {
return counter_.GetKeyPressCount(); return counter_.GetKeyPressCount();
} }
...@@ -231,7 +231,7 @@ UserInputMonitorWin::~UserInputMonitorWin() { ...@@ -231,7 +231,7 @@ UserInputMonitorWin::~UserInputMonitorWin() {
delete core_; delete core_;
} }
size_t UserInputMonitorWin::GetKeyPressCount() const { uint32_t UserInputMonitorWin::GetKeyPressCount() const {
return core_->GetKeyPressCount(); 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