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

Unified Diff: components/arc/input/arc_input_bridge.cc

Issue 1596663002: arc-bridge: Introduce the ArcService class (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@master
Patch Set: Addressed feedback Created 4 years, 11 months 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 side-by-side diff with in-line comments
Download patch
Index: components/arc/input/arc_input_bridge.cc
diff --git a/components/arc/input/arc_input_bridge_impl.cc b/components/arc/input/arc_input_bridge.cc
similarity index 86%
rename from components/arc/input/arc_input_bridge_impl.cc
rename to components/arc/input/arc_input_bridge.cc
index e24aeb866a3364df9fdb6f71be737cf6c328fe64..e3c32e62cff413ea9757245811fb000a322e7fe7 100644
--- a/components/arc/input/arc_input_bridge_impl.cc
+++ b/components/arc/input/arc_input_bridge.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/arc/input/arc_input_bridge_impl.h"
+#include "components/arc/input/arc_input_bridge.h"
#include <linux/input.h>
#include <fcntl.h>
@@ -76,16 +76,21 @@ const int kXkbKeycodeOffset = 8;
namespace arc {
-ArcInputBridgeImpl::ArcInputBridgeImpl(ArcBridgeService* arc_bridge_service)
- : arc_bridge_service_(arc_bridge_service),
+ArcInputBridge::ArcInputBridge(ArcBridgeService* arc_bridge)
+ : arc_bridge_service_(arc_bridge),
offset_x_acc_(0.5f),
offset_y_acc_(0.5f),
current_slot_(-1),
current_slot_tracking_ids_(kMaxSlots, kEmptySlot),
origin_task_runner_(base::ThreadTaskRunnerHandle::Get()),
weak_factory_(this) {
- arc_bridge_service->AddObserver(this);
- if (arc_bridge_service->input_instance())
+ DCHECK(arc_bridge_service_);
+ arc_bridge_service_->AddObserver(this);
+
+ // If InputInstance was ready before we AddObserver(), we won't get
+ // OnInputInstanceReady events. For such case, we have to call it
+ // explicitly.
+ if (arc_bridge_service_->input_instance())
OnInputInstanceReady();
aura::Env* env = aura::Env::GetInstanceDontCreate();
@@ -93,7 +98,7 @@ ArcInputBridgeImpl::ArcInputBridgeImpl(ArcBridgeService* arc_bridge_service)
env->AddObserver(this);
}
-ArcInputBridgeImpl::~ArcInputBridgeImpl() {
+ArcInputBridge::~ArcInputBridge() {
DCHECK(origin_task_runner_->RunsTasksOnCurrentThread());
arc_bridge_service_->RemoveObserver(this);
@@ -106,7 +111,7 @@ ArcInputBridgeImpl::~ArcInputBridgeImpl() {
}
}
-void ArcInputBridgeImpl::OnInputInstanceReady() {
+void ArcInputBridge::OnInputInstanceReady() {
DCHECK(origin_task_runner_->RunsTasksOnCurrentThread());
keyboard_fd_ = CreateBridgeInputDevice("ChromeOS Keyboard", "keyboard");
@@ -118,7 +123,7 @@ void ArcInputBridgeImpl::OnInputInstanceReady() {
// Translates and sends a ui::Event to the appropriate bridge device of the
// ARC instance. If the devices have not yet been initialized, the event
// will be ignored.
-void ArcInputBridgeImpl::OnEvent(ui::Event* event) {
+void ArcInputBridge::OnEvent(ui::Event* event) {
DCHECK(origin_task_runner_->RunsTasksOnCurrentThread());
if (event->IsKeyEvent()) {
SendKeyEvent(static_cast<ui::KeyEvent*>(event));
@@ -130,14 +135,14 @@ void ArcInputBridgeImpl::OnEvent(ui::Event* event) {
}
// Attaches the input bridge to the window if it is marked as an ARC window.
-void ArcInputBridgeImpl::OnWindowInitialized(aura::Window* new_window) {
+void ArcInputBridge::OnWindowInitialized(aura::Window* new_window) {
if (new_window->name() == "ExoSurface") {
arc_windows_.Add(new_window);
new_window->AddPreTargetHandler(this);
}
}
-void ArcInputBridgeImpl::SendKeyEvent(ui::KeyEvent* event) {
+void ArcInputBridge::SendKeyEvent(ui::KeyEvent* event) {
if (keyboard_fd_.get() < 0) {
VLOG(2) << "No keyboard bridge device available.";
return;
@@ -162,7 +167,7 @@ void ArcInputBridgeImpl::SendKeyEvent(ui::KeyEvent* event) {
SendSynReport(keyboard_fd_, time_stamp);
}
-void ArcInputBridgeImpl::SendTouchEvent(ui::TouchEvent* event) {
+void ArcInputBridge::SendTouchEvent(ui::TouchEvent* event) {
if (touchscreen_fd_.get() < 0) {
VLOG(2) << "No touchscreen bridge device available.";
return;
@@ -211,7 +216,7 @@ void ArcInputBridgeImpl::SendTouchEvent(ui::TouchEvent* event) {
SendSynReport(touchscreen_fd_, time_stamp);
}
-void ArcInputBridgeImpl::SendMouseEvent(ui::MouseEvent* event) {
+void ArcInputBridge::SendMouseEvent(ui::MouseEvent* event) {
if (mouse_fd_.get() < 0) {
VLOG(2) << "No mouse bridge device available.";
return;
@@ -263,11 +268,11 @@ void ArcInputBridgeImpl::SendMouseEvent(ui::MouseEvent* event) {
SendSynReport(mouse_fd_, time_stamp);
}
-void ArcInputBridgeImpl::SendKernelEvent(const base::ScopedFD& fd,
- base::TimeDelta time_stamp,
- uint16_t type,
- uint16_t code,
- int value) {
+void ArcInputBridge::SendKernelEvent(const base::ScopedFD& fd,
+ base::TimeDelta time_stamp,
+ uint16_t type,
+ uint16_t code,
+ int value) {
DCHECK(fd.is_valid());
struct input_event32 event;
@@ -285,14 +290,14 @@ void ArcInputBridgeImpl::SendKernelEvent(const base::ScopedFD& fd,
DCHECK_EQ(num_written, sizeof(struct input_event32));
}
-void ArcInputBridgeImpl::SendSynReport(const base::ScopedFD& fd,
- base::TimeDelta time) {
+void ArcInputBridge::SendSynReport(const base::ScopedFD& fd,
+ base::TimeDelta time) {
DCHECK(origin_task_runner_->RunsTasksOnCurrentThread());
SendKernelEvent(fd, time, EV_SYN, SYN_REPORT, 0);
}
-int ArcInputBridgeImpl::AcquireTouchSlot(ui::TouchEvent* event) {
+int ArcInputBridge::AcquireTouchSlot(ui::TouchEvent* event) {
int slot_id;
if (event->type() == ui::ET_TOUCH_PRESSED) {
slot_id = FindTouchSlot(kEmptySlot);
@@ -311,7 +316,7 @@ int ArcInputBridgeImpl::AcquireTouchSlot(ui::TouchEvent* event) {
return slot_id;
}
-int ArcInputBridgeImpl::FindTouchSlot(int tracking_id) {
+int ArcInputBridge::FindTouchSlot(int tracking_id) {
for (int i = 0; i < kMaxSlots; ++i) {
if (current_slot_tracking_ids_[i] == tracking_id) {
return i;
@@ -320,7 +325,7 @@ int ArcInputBridgeImpl::FindTouchSlot(int tracking_id) {
return -1;
}
-uint16_t ArcInputBridgeImpl::DomCodeToEvdevCode(ui::DomCode dom_code) {
+uint16_t ArcInputBridge::DomCodeToEvdevCode(ui::DomCode dom_code) {
int native_code = ui::KeycodeConverter::DomCodeToNativeKeycode(dom_code);
if (native_code == ui::KeycodeConverter::InvalidNativeKeycode())
return KEY_RESERVED;
@@ -328,14 +333,9 @@ uint16_t ArcInputBridgeImpl::DomCodeToEvdevCode(ui::DomCode dom_code) {
return native_code - kXkbKeycodeOffset;
}
-base::ScopedFD ArcInputBridgeImpl::CreateBridgeInputDevice(
+base::ScopedFD ArcInputBridge::CreateBridgeInputDevice(
const std::string& name,
const std::string& device_type) {
- if (!arc_bridge_service_) {
- VLOG(1) << "ArcBridgeService disappeared.";
- return base::ScopedFD();
- }
-
// Create file descriptor pair for communication
int fd[2];
int res = HANDLE_EINTR(pipe(fd));
@@ -379,9 +379,4 @@ base::ScopedFD ArcInputBridgeImpl::CreateBridgeInputDevice(
return write_fd;
}
-scoped_ptr<ArcInputBridge> ArcInputBridge::Create(
- ArcBridgeService* arc_bridge_service) {
- return make_scoped_ptr(new ArcInputBridgeImpl(arc_bridge_service));
-}
-
} // namespace arc

Powered by Google App Engine
This is Rietveld 408576698