diff options
author | lhchavez <lhchavez@chromium.org> | 2016-01-21 15:27:25 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-21 23:30:17 +0000 |
commit | 811769ba67bef5ff1e0a120146c0d593a6ebe5db (patch) | |
tree | 8b6350309843da6c9209af01abf1a186e6572f38 /components/arc | |
parent | a1b6ab993b5e0570d251198085002bb04e735015 (diff) | |
download | chromium_src-811769ba67bef5ff1e0a120146c0d593a6ebe5db.zip chromium_src-811769ba67bef5ff1e0a120146c0d593a6ebe5db.tar.gz chromium_src-811769ba67bef5ff1e0a120146c0d593a6ebe5db.tar.bz2 |
arc-bridge: Introduce the ArcService class
Several services managed by ARC were introducing empty, opaque classes
just to be able to be constructed outside of components/. This was
becoming ugly, so introduce just one interface that all services must
implement and whose lifecycle will be managed by ArcServiceManager.
BUG=None
TEST=trybots
Review URL: https://codereview.chromium.org/1596663002
Cr-Commit-Position: refs/heads/master@{#370825}
Diffstat (limited to 'components/arc')
22 files changed, 281 insertions, 388 deletions
diff --git a/components/arc/BUILD.gn b/components/arc/BUILD.gn index 5151d5a..0a5501d 100644 --- a/components/arc/BUILD.gn +++ b/components/arc/BUILD.gn @@ -12,9 +12,10 @@ static_library("arc") { "arc_bridge_service.h", "arc_bridge_service_impl.cc", "arc_bridge_service_impl.h", + "arc_service.cc", + "arc_service.h", "arc_service_manager.cc", "arc_service_manager.h", - "auth/arc_auth_service.h", "clipboard/arc_clipboard_bridge.cc", "clipboard/arc_clipboard_bridge.h", "ime/arc_ime_bridge.cc", @@ -22,15 +23,10 @@ static_library("arc") { "ime/arc_ime_ipc_host.h", "ime/arc_ime_ipc_host_impl.cc", "ime/arc_ime_ipc_host_impl.h", + "input/arc_input_bridge.cc", "input/arc_input_bridge.h", - "input/arc_input_bridge_impl.cc", - "input/arc_input_bridge_impl.h", - "intent_helper/arc_intent_helper_bridge.cc", - "intent_helper/arc_intent_helper_bridge.h", "power/arc_power_bridge.cc", "power/arc_power_bridge.h", - "settings/arc_settings_bridge.cc", - "settings/arc_settings_bridge.h", "video/arc_video_bridge.cc", "video/arc_video_bridge.h", "video/video_host_delegate.h", diff --git a/components/arc/arc_bridge_service.cc b/components/arc/arc_bridge_service.cc index d3448c5..844f5c8 100644 --- a/components/arc/arc_bridge_service.cc +++ b/components/arc/arc_bridge_service.cc @@ -49,6 +49,30 @@ bool ArcBridgeService::GetEnabled(const base::CommandLine* command_line) { void ArcBridgeService::AddObserver(Observer* observer) { DCHECK(CalledOnValidThread()); observer_list_.AddObserver(observer); + + // If any of the instances were ready before the call to AddObserver(), the + // |observer| won't get any readiness events. For such cases, we have to call + // them explicitly now to avoid a race. + if (app_instance()) + observer->OnAppInstanceReady(); + if (auth_instance()) + observer->OnAuthInstanceReady(); + if (clipboard_instance()) + observer->OnClipboardInstanceReady(); + if (ime_instance()) + observer->OnImeInstanceReady(); + if (input_instance()) + observer->OnInputInstanceReady(); + if (notifications_instance()) + observer->OnNotificationsInstanceReady(); + if (power_instance()) + observer->OnPowerInstanceReady(); + if (process_instance()) + observer->OnProcessInstanceReady(); + if (settings_instance()) + observer->OnSettingsInstanceReady(); + if (video_instance()) + observer->OnVideoInstanceReady(); } void ArcBridgeService::RemoveObserver(Observer* observer) { diff --git a/components/arc/arc_service.cc b/components/arc/arc_service.cc new file mode 100644 index 0000000..e40cc4d --- /dev/null +++ b/components/arc/arc_service.cc @@ -0,0 +1,18 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/arc/arc_service.h" + +#include "components/arc/arc_bridge_service.h" + +namespace arc { + +ArcService::ArcService(ArcBridgeService* bridge_service) + : arc_bridge_service_(bridge_service) { + DCHECK(arc_bridge_service()); +} + +ArcService::~ArcService() {} + +} // namespace arc diff --git a/components/arc/arc_service.h b/components/arc/arc_service.h new file mode 100644 index 0000000..d952417 --- /dev/null +++ b/components/arc/arc_service.h @@ -0,0 +1,35 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_ARC_ARC_SERVICE_H_ +#define COMPONENTS_ARC_ARC_SERVICE_H_ + +#include "base/macros.h" + +namespace arc { + +class ArcBridgeService; + +// Abstract class whose lifecycle will be managed by the ArcServiceManager. It +// is guaranteed that once the ownership of an ArcService has been transferred +// to ArcServiceManager, it will outlive the ArcBridgeService, so it is safe to +// keep a weak reference to it. +class ArcService { + public: + virtual ~ArcService(); + + ArcBridgeService* arc_bridge_service() const { return arc_bridge_service_; } + + protected: + explicit ArcService(ArcBridgeService* arc_bridge_service); + + private: + ArcBridgeService* const arc_bridge_service_; // owned by ArcServiceManager. + + DISALLOW_COPY_AND_ASSIGN(ArcService); +}; + +} // namespace arc + +#endif // COMPONENTS_ARC_ARC_SERVICE_H_ diff --git a/components/arc/arc_service_manager.cc b/components/arc/arc_service_manager.cc index f6eace9..85f52fe 100644 --- a/components/arc/arc_service_manager.cc +++ b/components/arc/arc_service_manager.cc @@ -10,14 +10,10 @@ #include "base/thread_task_runner_handle.h" #include "components/arc/arc_bridge_bootstrap.h" #include "components/arc/arc_bridge_service_impl.h" -#include "components/arc/auth/arc_auth_service.h" #include "components/arc/clipboard/arc_clipboard_bridge.h" #include "components/arc/ime/arc_ime_bridge.h" #include "components/arc/input/arc_input_bridge.h" -#include "components/arc/intent_helper/arc_intent_helper_bridge.h" #include "components/arc/power/arc_power_bridge.h" -#include "components/arc/settings/arc_settings_bridge.h" -#include "components/arc/video/arc_video_bridge.h" #include "ui/arc/notification/arc_notification_manager.h" namespace arc { @@ -29,28 +25,16 @@ ArcServiceManager* g_arc_service_manager = nullptr; } // namespace -ArcServiceManager::ArcServiceManager( - scoped_ptr<ArcAuthService> auth_service, - scoped_ptr<ArcIntentHelperBridge> intent_helper_bridge, - scoped_ptr<ArcSettingsBridge> settings_bridge, - scoped_ptr<ArcVideoBridge> video_bridge) +ArcServiceManager::ArcServiceManager() : arc_bridge_service_( - new ArcBridgeServiceImpl(ArcBridgeBootstrap::Create())), - arc_auth_service_(std::move(auth_service)), - arc_clipboard_bridge_(new ArcClipboardBridge(arc_bridge_service_.get())), - arc_ime_bridge_(new ArcImeBridge(arc_bridge_service_.get())), - arc_input_bridge_(ArcInputBridge::Create(arc_bridge_service_.get())), - arc_intent_helper_bridge_(std::move(intent_helper_bridge)), - arc_settings_bridge_(std::move(settings_bridge)), - arc_power_bridge_(new ArcPowerBridge(arc_bridge_service_.get())), - arc_video_bridge_(std::move(video_bridge)) { + new ArcBridgeServiceImpl(ArcBridgeBootstrap::Create())) { DCHECK(!g_arc_service_manager); g_arc_service_manager = this; - arc_settings_bridge_->StartObservingBridgeServiceChanges(); - arc_auth_service_->StartObservingBridgeServiceChanges(); - arc_intent_helper_bridge_->StartObservingBridgeServiceChanges(); - arc_video_bridge_->StartObservingBridgeServiceChanges(); + AddService(make_scoped_ptr(new ArcClipboardBridge(arc_bridge_service()))); + AddService(make_scoped_ptr(new ArcImeBridge(arc_bridge_service()))); + AddService(make_scoped_ptr(new ArcInputBridge(arc_bridge_service()))); + AddService(make_scoped_ptr(new ArcPowerBridge(arc_bridge_service()))); } ArcServiceManager::~ArcServiceManager() { @@ -71,12 +55,18 @@ ArcBridgeService* ArcServiceManager::arc_bridge_service() { return arc_bridge_service_.get(); } +void ArcServiceManager::AddService(scoped_ptr<ArcService> service) { + DCHECK(thread_checker_.CalledOnValidThread()); + + services_.emplace_back(std::move(service)); +} + void ArcServiceManager::OnPrimaryUserProfilePrepared( const AccountId& account_id) { DCHECK(thread_checker_.CalledOnValidThread()); - arc_notification_manager_.reset( - new ArcNotificationManager(arc_bridge_service(), account_id)); + AddService(make_scoped_ptr( + new ArcNotificationManager(arc_bridge_service(), account_id))); } } // namespace arc diff --git a/components/arc/arc_service_manager.h b/components/arc/arc_service_manager.h index 205eb7b..b3a1a6d 100644 --- a/components/arc/arc_service_manager.h +++ b/components/arc/arc_service_manager.h @@ -5,6 +5,8 @@ #ifndef COMPONENTS_ARC_ARC_SERVICE_MANAGER_H_ #define COMPONENTS_ARC_ARC_SERVICE_MANAGER_H_ +#include <vector> + #include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/threading/thread_checker.h" @@ -12,31 +14,23 @@ namespace arc { -class ArcAuthService; class ArcBridgeService; -class ArcClipboardBridge; -class ArcImeBridge; -class ArcInputBridge; -class ArcIntentHelperBridge; -class ArcNotificationManager; -class ArcPowerBridge; -class ArcSettingsBridge; -class ArcVideoBridge; +class ArcService; // Manages creation and destruction of services that communicate with the ARC // instance via the ArcBridgeService. class ArcServiceManager { public: - ArcServiceManager(scoped_ptr<ArcAuthService> auth_service, - scoped_ptr<ArcIntentHelperBridge> intent_helper_bridge, - scoped_ptr<ArcSettingsBridge> settings_bridge, - scoped_ptr<ArcVideoBridge> video_bridge); + ArcServiceManager(); virtual ~ArcServiceManager(); // |arc_bridge_service| can only be accessed on the thread that this // class was created on. ArcBridgeService* arc_bridge_service(); + // Adds a service to the managed services list. + void AddService(scoped_ptr<ArcService> service); + // Gets the global instance of the ARC Service Manager. This can only be // called on the thread that this class was created on. static ArcServiceManager* Get(); @@ -47,17 +41,7 @@ class ArcServiceManager { private: base::ThreadChecker thread_checker_; scoped_ptr<ArcBridgeService> arc_bridge_service_; - - // Individual services - scoped_ptr<ArcAuthService> arc_auth_service_; - scoped_ptr<ArcClipboardBridge> arc_clipboard_bridge_; - scoped_ptr<ArcImeBridge> arc_ime_bridge_; - scoped_ptr<ArcInputBridge> arc_input_bridge_; - scoped_ptr<ArcIntentHelperBridge> arc_intent_helper_bridge_; - scoped_ptr<ArcNotificationManager> arc_notification_manager_; - scoped_ptr<ArcSettingsBridge> arc_settings_bridge_; - scoped_ptr<ArcPowerBridge> arc_power_bridge_; - scoped_ptr<ArcVideoBridge> arc_video_bridge_; + std::vector<scoped_ptr<ArcService>> services_; DISALLOW_COPY_AND_ASSIGN(ArcServiceManager); }; diff --git a/components/arc/auth/arc_auth_service.h b/components/arc/auth/arc_auth_service.h deleted file mode 100644 index d26288e..0000000 --- a/components/arc/auth/arc_auth_service.h +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef COMPONENTS_ARC_AUTH_ARC_AUTH_SERVICE_H_ -#define COMPONENTS_ARC_AUTH_ARC_AUTH_SERVICE_H_ - -namespace arc { - -class ArcAuthService { - public: - virtual ~ArcAuthService() {} - - // Starts listening to state changes of the ArcBridgeService. - virtual void StartObservingBridgeServiceChanges() = 0; -}; - -} // namespace arc - -#endif // COMPONENTS_ARC_AUTH_ARC_AUTH_SERVICE_H_ diff --git a/components/arc/clipboard/arc_clipboard_bridge.cc b/components/arc/clipboard/arc_clipboard_bridge.cc index 06e39fb..24ef3d7 100644 --- a/components/arc/clipboard/arc_clipboard_bridge.cc +++ b/components/arc/clipboard/arc_clipboard_bridge.cc @@ -28,17 +28,18 @@ static mojo::String ConvertString16ToMojoString(const base::string16& input) { namespace arc { ArcClipboardBridge::ArcClipboardBridge(ArcBridgeService* bridge_service) - : bridge_service_(bridge_service), binding_(this) { - bridge_service_->AddObserver(this); + : ArcService(bridge_service), binding_(this) { + arc_bridge_service()->AddObserver(this); } ArcClipboardBridge::~ArcClipboardBridge() { DCHECK(CalledOnValidThread()); - bridge_service_->RemoveObserver(this); + arc_bridge_service()->RemoveObserver(this); } void ArcClipboardBridge::OnClipboardInstanceReady() { - ClipboardInstance* clipboard_instance = bridge_service_->clipboard_instance(); + ClipboardInstance* clipboard_instance = + arc_bridge_service()->clipboard_instance(); if (!clipboard_instance) { LOG(ERROR) << "OnClipboardInstanceReady called, " << "but no clipboard instance found"; @@ -63,7 +64,8 @@ void ArcClipboardBridge::GetTextContent() { ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &text); - ClipboardInstance* clipboard_instance = bridge_service_->clipboard_instance(); + ClipboardInstance* clipboard_instance = + arc_bridge_service()->clipboard_instance(); clipboard_instance->OnGetTextContent(ConvertString16ToMojoString(text)); } diff --git a/components/arc/clipboard/arc_clipboard_bridge.h b/components/arc/clipboard/arc_clipboard_bridge.h index d458f63..1392993 100644 --- a/components/arc/clipboard/arc_clipboard_bridge.h +++ b/components/arc/clipboard/arc_clipboard_bridge.h @@ -9,11 +9,13 @@ #include "base/macros.h" #include "components/arc/arc_bridge_service.h" +#include "components/arc/arc_service.h" #include "mojo/public/cpp/bindings/binding.h" namespace arc { -class ArcClipboardBridge : public ArcBridgeService::Observer, +class ArcClipboardBridge : public ArcService, + public ArcBridgeService::Observer, public ClipboardHost { public: explicit ArcClipboardBridge(ArcBridgeService* bridge_service); @@ -29,8 +31,6 @@ class ArcClipboardBridge : public ArcBridgeService::Observer, private: bool CalledOnValidThread(); - ArcBridgeService* bridge_service_; - mojo::Binding<ClipboardHost> binding_; base::ThreadChecker thread_checker_; diff --git a/components/arc/ime/arc_ime_bridge.cc b/components/arc/ime/arc_ime_bridge.cc index ad03084..e98fde3 100644 --- a/components/arc/ime/arc_ime_bridge.cc +++ b/components/arc/ime/arc_ime_bridge.cc @@ -31,8 +31,9 @@ bool IsArcWindow(const aura::Window* window) { //////////////////////////////////////////////////////////////////////////////// // ArcImeBridge main implementation: -ArcImeBridge::ArcImeBridge(ArcBridgeService* arc_bridge_service) - : ipc_host_(new ArcImeIpcHostImpl(this, arc_bridge_service)), +ArcImeBridge::ArcImeBridge(ArcBridgeService* bridge_service) + : ArcService(bridge_service), + ipc_host_(new ArcImeIpcHostImpl(this, bridge_service)), ime_type_(ui::TEXT_INPUT_TYPE_NONE), has_composition_text_(false) { aura::Env* env = aura::Env::GetInstanceDontCreate(); diff --git a/components/arc/ime/arc_ime_bridge.h b/components/arc/ime/arc_ime_bridge.h index 4886d2a..7c969b3 100644 --- a/components/arc/ime/arc_ime_bridge.h +++ b/components/arc/ime/arc_ime_bridge.h @@ -7,6 +7,7 @@ #include "base/macros.h" #include "base/memory/scoped_ptr.h" +#include "components/arc/arc_service.h" #include "components/arc/ime/arc_ime_ipc_host.h" #include "ui/aura/client/focus_change_observer.h" #include "ui/aura/env_observer.h" @@ -31,13 +32,14 @@ class ArcBridgeService; // This class implements ui::TextInputClient and makes ARC windows behave // as a text input target in Chrome OS environment. -class ArcImeBridge : public ArcImeIpcHost::Delegate, +class ArcImeBridge : public ArcService, + public ArcImeIpcHost::Delegate, public aura::EnvObserver, public aura::WindowObserver, public aura::client::FocusChangeObserver, public ui::TextInputClient { public: - explicit ArcImeBridge(ArcBridgeService* arc_bridge_service); + explicit ArcImeBridge(ArcBridgeService* bridge_service); ~ArcImeBridge() override; // Injects the custom IPC host object for testing purpose only. diff --git a/components/arc/input/arc_input_bridge_impl.cc b/components/arc/input/arc_input_bridge.cc index e24aeb8..74bd7a4 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,26 +76,24 @@ const int kXkbKeycodeOffset = 8; namespace arc { -ArcInputBridgeImpl::ArcInputBridgeImpl(ArcBridgeService* arc_bridge_service) - : arc_bridge_service_(arc_bridge_service), +ArcInputBridge::ArcInputBridge(ArcBridgeService* bridge_service) + : ArcService(bridge_service), 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()) - OnInputInstanceReady(); + arc_bridge_service()->AddObserver(this); aura::Env* env = aura::Env::GetInstanceDontCreate(); if (env) env->AddObserver(this); } -ArcInputBridgeImpl::~ArcInputBridgeImpl() { +ArcInputBridge::~ArcInputBridge() { DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); - arc_bridge_service_->RemoveObserver(this); + arc_bridge_service()->RemoveObserver(this); aura::Env* env = aura::Env::GetInstanceDontCreate(); if (env) @@ -106,7 +104,7 @@ ArcInputBridgeImpl::~ArcInputBridgeImpl() { } } -void ArcInputBridgeImpl::OnInputInstanceReady() { +void ArcInputBridge::OnInputInstanceReady() { DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); keyboard_fd_ = CreateBridgeInputDevice("ChromeOS Keyboard", "keyboard"); @@ -118,7 +116,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 +128,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 +160,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 +209,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 +261,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 +283,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 +309,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 +318,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 +326,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)); @@ -347,7 +340,7 @@ base::ScopedFD ArcInputBridgeImpl::CreateBridgeInputDevice( base::ScopedFD write_fd(fd[1]); // The read end is sent to the instance, ownership of fd transfers. - InputInstance* input_instance = arc_bridge_service_->input_instance(); + InputInstance* input_instance = arc_bridge_service()->input_instance(); if (!input_instance) { VLOG(1) << "ArcBridgeService InputInstance disappeared."; return base::ScopedFD(); @@ -379,9 +372,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 diff --git a/components/arc/input/arc_input_bridge.h b/components/arc/input/arc_input_bridge.h index 1082dc4..be44676 100644 --- a/components/arc/input/arc_input_bridge.h +++ b/components/arc/input/arc_input_bridge.h @@ -2,18 +2,36 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef COMPONENTS_EXO_ARC_INPUT_ARC_INPUT_BRIDGE_H_ -#define COMPONENTS_EXO_ARC_INPUT_ARC_INPUT_BRIDGE_H_ +#ifndef COMPONENTS_ARC_INPUT_ARC_INPUT_BRIDGE_H_ +#define COMPONENTS_ARC_INPUT_ARC_INPUT_BRIDGE_H_ +#include <stdint.h> +#include <string> +#include <vector> + +#include "base/files/scoped_file.h" #include "base/macros.h" #include "components/arc/arc_bridge_service.h" +#include "components/arc/arc_service.h" +#include "ui/aura/env_observer.h" +#include "ui/aura/window_tracker.h" +#include "ui/events/event_handler.h" + +namespace aura { +class Window; +} + +namespace ui { +enum class DomCode; +class Event; +} namespace arc { class ArcBridgeService; -// The ArcInputBridge is responsible for sending input events from ARC windows -// to the ARC instance. +// The ArcInputBridge is responsible for sending input events from ARC +// windows to the ARC instance. // It hooks into aura::Env to watch for ExoSurface windows that are running ARC // applications. On those windows the input bridge will attach an EventPreTarget // to capture all input events. @@ -22,22 +40,102 @@ class ArcBridgeService; // we can send linux input_event's. // ui::Events to the ARC windows are translated to linux input_event's, which // are then sent through the respective file descriptor. -class ArcInputBridge { +class ArcInputBridge : public ArcService, + public ArcBridgeService::Observer, + public aura::EnvObserver, + public ui::EventHandler { public: - virtual ~ArcInputBridge() {} + // The constructor will register an Observer with aura::Env and the + // ArcBridgeService. From then on, no further interaction with this class + // is needed. + explicit ArcInputBridge(ArcBridgeService* bridge_service); + ~ArcInputBridge() override; - // Creates a new instance of ArcInputBridge. It will register an Observer - // with aura::Env and the ArcBridgeService. - static scoped_ptr<ArcInputBridge> Create( - ArcBridgeService* arc_bridge_service); + // Overridden from ui::EventHandler: + void OnEvent(ui::Event* event) override; - protected: - ArcInputBridge() {} + // Overridden from aura::EnvObserver: + void OnWindowInitialized(aura::Window* new_window) override; + + // Overridden from ArcBridgeService::Observer: + void OnInputInstanceReady() override; private: + // Specialized method to translate and send events to the right file + // descriptor. + void SendKeyEvent(ui::KeyEvent* event); + void SendTouchEvent(ui::TouchEvent* event); + void SendMouseEvent(ui::MouseEvent* event); + + // Helper method to send a struct input_event to the file descriptor. This + // method is to be called on the ui thread and will post a request to send + // the event to the io thread. + // The parameters map directly to the members of input_event as + // defined by the evdev protocol. + // |type| is the type of event to sent, such as EV_SYN, EV_KEY, EV_ABS. + // |code| is either interpreted as axis (ABS_X, ABS_Y, ...) or as key-code + // (KEY_A, KEY_B, ...). + // |value| is either the value of that axis or the boolean value of the key + // as in 0 (released), 1 (pressed) or 2 (repeated press). + void SendKernelEvent(const base::ScopedFD& fd, + base::TimeDelta timestamp, + uint16_t type, + uint16_t code, + int value); + + // Shorthand for sending EV_SYN/SYN_REPORT + void SendSynReport(const base::ScopedFD& fd, base::TimeDelta timestamp); + + // Return existing or new slot for this event. + int AcquireTouchSlot(ui::TouchEvent* event); + + // Return touch slot for tracking id. + int FindTouchSlot(int tracking_id); + + // Maps DOM key codes to evdev key codes + uint16_t DomCodeToEvdevCode(ui::DomCode dom_code); + + // Setup bridge devices on the instance side. This needs to be called after + // the InstanceBootPhase::SYSTEM_SERVICES_READY has been reached. + void SetupBridgeDevices(); + + // Creates and registers file descriptor pair with the ARC bridge service, + // the write end is returned while the read end is sent through the bridge + // to the ARC instance. + // TODO(denniskempin): Make this interface more typesafe. + // |name| should be the displayable name of the emulated device (e.g. "Chrome + // OS Keyboard"), |device_type| the name of the device type (e.g. "keyboard") + // and |fd| a file descriptor that emulates the kernel events of the device. + // This can only be called on the thread that this class was created on. + base::ScopedFD CreateBridgeInputDevice(const std::string& name, + const std::string& device_type); + + // File descriptors for the different device types. + base::ScopedFD keyboard_fd_; + base::ScopedFD mouse_fd_; + base::ScopedFD touchscreen_fd_; + + // Scroll accumlator. + float offset_x_acc_; + float offset_y_acc_; + + // Currently selected slot for multi-touch events. + int current_slot_; + + // List of touch tracking id to slot assignments. + std::vector<int> current_slot_tracking_ids_; + + scoped_refptr<base::SequencedTaskRunner> origin_task_runner_; + + // List of windows we are hooked into + aura::WindowTracker arc_windows_; + + // WeakPtrFactory to use for callbacks. + base::WeakPtrFactory<ArcInputBridge> weak_factory_; + DISALLOW_COPY_AND_ASSIGN(ArcInputBridge); }; } // namespace arc -#endif // COMPONENTS_EXO_ARC_INPUT_ARC_INPUT_BRIDGE_H_ +#endif // COMPONENTS_ARC_INPUT_ARC_INPUT_BRIDGE_H_ diff --git a/components/arc/input/arc_input_bridge_impl.h b/components/arc/input/arc_input_bridge_impl.h deleted file mode 100644 index 0d6acb5..0000000 --- a/components/arc/input/arc_input_bridge_impl.h +++ /dev/null @@ -1,136 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef COMPONENTS_ARC_INPUT_ARC_INPUT_BRIDGE_IMPL_H_ -#define COMPONENTS_ARC_INPUT_ARC_INPUT_BRIDGE_IMPL_H_ - -#include <stdint.h> -#include <string> -#include <vector> - -#include "base/files/scoped_file.h" -#include "base/macros.h" -#include "components/arc/input/arc_input_bridge.h" -#include "ui/aura/env.h" -#include "ui/aura/env_observer.h" -#include "ui/aura/window_tracker.h" -#include "ui/events/event.h" -#include "ui/events/event_handler.h" - -namespace aura { -class Window; -} - -namespace ui { -enum class DomCode; -} - -namespace arc { - -class ArcBridgeService; - -// Private implementation of ArcInputBridge -class ArcInputBridgeImpl : public ArcInputBridge, - public ArcBridgeService::Observer, - public aura::EnvObserver, - public ui::EventHandler { - public: - // The constructor will register an Observer with aura::Env and the - // ArcBridgeService. From then on, no further interaction with this class - // is needed. - explicit ArcInputBridgeImpl(ArcBridgeService* arc_bridge_service); - ~ArcInputBridgeImpl() override; - - // Overridden from ui::EventHandler: - void OnEvent(ui::Event* event) override; - - // Overridden from aura::EnvObserver: - void OnWindowInitialized(aura::Window* new_window) override; - - // Overridden from ArcBridgeService::Observer: - void OnInputInstanceReady() override; - - private: - // Specialized method to translate and send events to the right file - // descriptor. - void SendKeyEvent(ui::KeyEvent* event); - void SendTouchEvent(ui::TouchEvent* event); - void SendMouseEvent(ui::MouseEvent* event); - - // Helper method to send a struct input_event to the file descriptor. This - // method is to be called on the ui thread and will post a request to send - // the event to the io thread. - // The parameters map directly to the members of input_event as - // defined by the evdev protocol. - // |type| is the type of event to sent, such as EV_SYN, EV_KEY, EV_ABS. - // |code| is either interpreted as axis (ABS_X, ABS_Y, ...) or as key-code - // (KEY_A, KEY_B, ...). - // |value| is either the value of that axis or the boolean value of the key - // as in 0 (released), 1 (pressed) or 2 (repeated press). - void SendKernelEvent(const base::ScopedFD& fd, - base::TimeDelta timestamp, - uint16_t type, - uint16_t code, - int value); - - // Shorthand for sending EV_SYN/SYN_REPORT - void SendSynReport(const base::ScopedFD& fd, base::TimeDelta timestamp); - - // Return existing or new slot for this event. - int AcquireTouchSlot(ui::TouchEvent* event); - - // Return touch slot for tracking id. - int FindTouchSlot(int tracking_id); - - // Maps DOM key codes to evdev key codes - uint16_t DomCodeToEvdevCode(ui::DomCode dom_code); - - // Setup bridge devices on the instance side. This needs to be called after - // the InstanceBootPhase::SYSTEM_SERVICES_READY has been reached. - void SetupBridgeDevices(); - - // Creates and registers file descriptor pair with the ARC bridge service, - // the write end is returned while the read end is sent through the bridge - // to the ARC instance. - // TODO(denniskempin): Make this interface more typesafe. - // |name| should be the displayable name of the emulated device (e.g. "Chrome - // OS Keyboard"), |device_type| the name of the device type (e.g. "keyboard") - // and |fd| a file descriptor that emulates the kernel events of the device. - // This can only be called on the thread that this class was created on. - base::ScopedFD CreateBridgeInputDevice(const std::string& name, - const std::string& device_type); - - // Owned by ArcServiceManager which makes sure ArcBridgeService is destroyed - // after ArcInputBridge. - ArcBridgeService* arc_bridge_service_; - - // File descriptors for the different device types. - base::ScopedFD keyboard_fd_; - base::ScopedFD mouse_fd_; - base::ScopedFD touchscreen_fd_; - - // Scroll accumlator. - float offset_x_acc_; - float offset_y_acc_; - - // Currently selected slot for multi-touch events. - int current_slot_; - - // List of touch tracking id to slot assignments. - std::vector<int> current_slot_tracking_ids_; - - scoped_refptr<base::SequencedTaskRunner> origin_task_runner_; - - // List of windows we are hooked into - aura::WindowTracker arc_windows_; - - // WeakPtrFactory to use for callbacks. - base::WeakPtrFactory<ArcInputBridgeImpl> weak_factory_; - - DISALLOW_COPY_AND_ASSIGN(ArcInputBridgeImpl); -}; - -} // namespace arc - -#endif // COMPONENTS_ARC_INPUT_ARC_INPUT_BRIDGE_IMPL_H_ diff --git a/components/arc/intent_helper/arc_intent_helper_bridge.cc b/components/arc/intent_helper/arc_intent_helper_bridge.cc deleted file mode 100644 index 60a2d4f..0000000 --- a/components/arc/intent_helper/arc_intent_helper_bridge.cc +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "components/arc/intent_helper/arc_intent_helper_bridge.h" - -namespace arc { - -ArcIntentHelperBridge::~ArcIntentHelperBridge() {} - -} // namespace arc diff --git a/components/arc/intent_helper/arc_intent_helper_bridge.h b/components/arc/intent_helper/arc_intent_helper_bridge.h deleted file mode 100644 index 4b8c983..0000000 --- a/components/arc/intent_helper/arc_intent_helper_bridge.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef COMPONENTS_ARC_HELPER_ARC_HELPER_BRIDGE_H_ -#define COMPONENTS_ARC_HELPER_ARC_HELPER_BRIDGE_H_ - -namespace arc { - -// We want ArcServiceManager to own the ArcIntentHelperBridge but -// ArcIntentHelperBridge depends on code in chrome/ which is not accessible from -// components/. Since ArcIntentHelperBridge interacts with the bridge through -// the global Get function, session manager only needs to see a limited -// interface. Full implementation at -// chrome/browser/chromeos/arc/arc_intent_helper_bridge_impl.h -class ArcIntentHelperBridge { - public: - virtual ~ArcIntentHelperBridge(); - - // Starts listening to state changes of the ArcBridgeService. - virtual void StartObservingBridgeServiceChanges() = 0; -}; - -} // namespace arc - -#endif // COMPONENTS_ARC_HELPER_ARC_HELPER_BRIDGE_H_ diff --git a/components/arc/power/arc_power_bridge.cc b/components/arc/power/arc_power_bridge.cc index 172d8fe..05b438b 100644 --- a/components/arc/power/arc_power_bridge.cc +++ b/components/arc/power/arc_power_bridge.cc @@ -13,15 +13,13 @@ namespace arc { -ArcPowerBridge::ArcPowerBridge(ArcBridgeService* arc_bridge_service) - : arc_bridge_service_(arc_bridge_service), binding_(this) { - arc_bridge_service->AddObserver(this); - if (arc_bridge_service->power_instance()) - OnPowerInstanceReady(); +ArcPowerBridge::ArcPowerBridge(ArcBridgeService* bridge_service) + : ArcService(bridge_service), binding_(this) { + arc_bridge_service()->AddObserver(this); } ArcPowerBridge::~ArcPowerBridge() { - arc_bridge_service_->RemoveObserver(this); + arc_bridge_service()->RemoveObserver(this); ReleaseAllDisplayWakeLocks(); } @@ -31,7 +29,7 @@ void ArcPowerBridge::OnStateChanged(ArcBridgeService::State state) { } void ArcPowerBridge::OnPowerInstanceReady() { - PowerInstance* power_instance = arc_bridge_service_->power_instance(); + PowerInstance* power_instance = arc_bridge_service()->power_instance(); if (!power_instance) { LOG(ERROR) << "OnPowerInstanceReady called, but no power instance found"; return; diff --git a/components/arc/power/arc_power_bridge.h b/components/arc/power/arc_power_bridge.h index 77c0263..a2f7b58 100644 --- a/components/arc/power/arc_power_bridge.h +++ b/components/arc/power/arc_power_bridge.h @@ -2,23 +2,25 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef COMPONENTS_ARC_POWER_ARC_POWER_SERVICE_H_ -#define COMPONENTS_ARC_POWER_ARC_POWER_SERVICE_H_ +#ifndef COMPONENTS_ARC_POWER_ARC_POWER_BRIDGE_H_ +#define COMPONENTS_ARC_POWER_ARC_POWER_BRIDGE_H_ #include <map> #include "base/macros.h" #include "components/arc/arc_bridge_service.h" +#include "components/arc/arc_service.h" #include "mojo/public/cpp/bindings/binding.h" namespace arc { // ARC Power Client sets power management policy based on requests from // ARC instances. -class ArcPowerBridge : public ArcBridgeService::Observer, +class ArcPowerBridge : public ArcService, + public ArcBridgeService::Observer, public PowerHost { public: - explicit ArcPowerBridge(ArcBridgeService* arc_bridge_service); + explicit ArcPowerBridge(ArcBridgeService* bridge_service); ~ArcPowerBridge() override; // ArcBridgeService::Observer overrides. @@ -32,8 +34,6 @@ class ArcPowerBridge : public ArcBridgeService::Observer, private: void ReleaseAllDisplayWakeLocks(); - ArcBridgeService* arc_bridge_service_; // weak - mojo::Binding<PowerHost> binding_; // Stores a mapping of type -> wake lock ID for all wake locks @@ -45,4 +45,4 @@ class ArcPowerBridge : public ArcBridgeService::Observer, } // namespace arc -#endif // COMPONENTS_ARC_POWER_ARC_POWER_SERVICE_H_ +#endif // COMPONENTS_ARC_POWER_ARC_POWER_BRIDGE_H_ diff --git a/components/arc/settings/arc_settings_bridge.cc b/components/arc/settings/arc_settings_bridge.cc deleted file mode 100644 index 649ddbe..0000000 --- a/components/arc/settings/arc_settings_bridge.cc +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "components/arc/settings/arc_settings_bridge.h" - -namespace arc { - -ArcSettingsBridge::~ArcSettingsBridge() {} - -} // namespace arc diff --git a/components/arc/settings/arc_settings_bridge.h b/components/arc/settings/arc_settings_bridge.h deleted file mode 100644 index ba774c1..0000000 --- a/components/arc/settings/arc_settings_bridge.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef COMPONENTS_ARC_SETTINGS_ARC_SETTINGS_BRIDGE_H_ -#define COMPONENTS_ARC_SETTINGS_ARC_SETTINGS_BRIDGE_H_ - -namespace arc { - -// We want ArcServiceManager to own the ArcSettingsBridge but ArcSettingsBridge -// depends on code in chrome/ which is not accessible from components/. Since -// ArcSettingsBridge interacts with the bridge through the global Get function, -// session manager only needs to see a limited interface. -// -// Full implementation at chrome/browser/chromeos/arc/arc_settings_bridge_impl.h -class ArcSettingsBridge { - public: - virtual ~ArcSettingsBridge() = 0; - - // Starts listening to state changes of the ArcBridgeService - virtual void StartObservingBridgeServiceChanges() = 0; -}; - -} // namespace arc - -#endif // COMPONENTS_ARC_SETTINGS_ARC_SETTINGS_BRIDGE_H_ diff --git a/components/arc/video/arc_video_bridge.cc b/components/arc/video/arc_video_bridge.cc index dddbb39..a57f775 100644 --- a/components/arc/video/arc_video_bridge.cc +++ b/components/arc/video/arc_video_bridge.cc @@ -9,25 +9,16 @@ namespace arc { ArcVideoBridge::ArcVideoBridge( + ArcBridgeService* bridge_service, scoped_ptr<VideoHostDelegate> video_host_delegate) - : video_host_delegate_(std::move(video_host_delegate)), - binding_(video_host_delegate_.get()) {} - -ArcVideoBridge::~ArcVideoBridge() { - arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); - DCHECK(bridge_service); - bridge_service->RemoveObserver(this); + : ArcService(bridge_service), + video_host_delegate_(std::move(video_host_delegate)), + binding_(video_host_delegate_.get()) { + arc_bridge_service()->AddObserver(this); } -void ArcVideoBridge::StartObservingBridgeServiceChanges() { - arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); - DCHECK(bridge_service); - bridge_service->AddObserver(this); - - // If VideoInstance was ready before we AddObserver(), we won't get - // OnVideoInstanceReady events. For such case, we have to call it explicitly. - if (bridge_service->video_instance()) - OnVideoInstanceReady(); +ArcVideoBridge::~ArcVideoBridge() { + arc_bridge_service()->RemoveObserver(this); } void ArcVideoBridge::OnStateChanged(arc::ArcBridgeService::State state) { @@ -41,12 +32,9 @@ void ArcVideoBridge::OnStateChanged(arc::ArcBridgeService::State state) { } void ArcVideoBridge::OnVideoInstanceReady() { - arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); - DCHECK(bridge_service); - arc::VideoHostPtr host; binding_.Bind(mojo::GetProxy(&host)); - bridge_service->video_instance()->Init(std::move(host)); + arc_bridge_service()->video_instance()->Init(std::move(host)); } } // namespace arc diff --git a/components/arc/video/arc_video_bridge.h b/components/arc/video/arc_video_bridge.h index f781a5e..bf1bd38 100644 --- a/components/arc/video/arc_video_bridge.h +++ b/components/arc/video/arc_video_bridge.h @@ -2,12 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef COMPONENTS_ARC_VIDEO_ARC_VIDEO_BRIDGE_H -#define COMPONENTS_ARC_VIDEO_ARC_VIDEO_BRIDGE_H +#ifndef COMPONENTS_ARC_VIDEO_ARC_VIDEO_BRIDGE_H_ +#define COMPONENTS_ARC_VIDEO_ARC_VIDEO_BRIDGE_H_ #include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "components/arc/arc_bridge_service.h" +#include "components/arc/arc_service.h" #include "components/arc/video/video_host_delegate.h" #include "mojo/public/cpp/bindings/binding.h" @@ -17,14 +18,12 @@ class VideoHostDelegate; // ArcVideoBridge bridges ArcBridgeService and VideoHostDelegate. It observes // ArcBridgeService events and pass VideoHost proxy to VideoInstance. -class ArcVideoBridge : public ArcBridgeService::Observer { +class ArcVideoBridge : public ArcService, public ArcBridgeService::Observer { public: - explicit ArcVideoBridge(scoped_ptr<VideoHostDelegate> video_host_delegate); + ArcVideoBridge(ArcBridgeService* bridge_service, + scoped_ptr<VideoHostDelegate> video_host_delegate); ~ArcVideoBridge() override; - // Starts listening to state changes of the ArcBridgeService. - void StartObservingBridgeServiceChanges(); - // arc::ArcBridgeService::Observer implementation. void OnStateChanged(arc::ArcBridgeService::State state) override; void OnVideoInstanceReady() override; @@ -38,4 +37,4 @@ class ArcVideoBridge : public ArcBridgeService::Observer { } // namespace arc -#endif // COMPONENTS_ARC_VIDEO_ARC_VIDEO_BRIDGE_H +#endif // COMPONENTS_ARC_VIDEO_ARC_VIDEO_BRIDGE_H_ |