1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef REMOTING_HOST_IPC_KEYBOARD_LAYOUT_MONITOR_H_
6 #define REMOTING_HOST_IPC_KEYBOARD_LAYOUT_MONITOR_H_
7 
8 #include <memory>
9 
10 #include "base/callback.h"
11 #include "base/memory/scoped_refptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "remoting/host/keyboard_layout_monitor.h"
14 
15 namespace remoting {
16 
17 class DesktopSessionProxy;
18 
19 // KeyboardLayoutMonitor implementations are responsible for monitoring the
20 // active keyboard layout within the CRD session on the host, and triggering a
21 // callback whenever it changes.
22 class IpcKeyboardLayoutMonitor : public KeyboardLayoutMonitor {
23  public:
24   IpcKeyboardLayoutMonitor(
25       base::RepeatingCallback<void(const protocol::KeyboardLayout&)> callback,
26       scoped_refptr<DesktopSessionProxy> desktop_session_proxy);
27   ~IpcKeyboardLayoutMonitor() override;
28 
29   IpcKeyboardLayoutMonitor(const IpcKeyboardLayoutMonitor&) = delete;
30   IpcKeyboardLayoutMonitor& operator=(const IpcKeyboardLayoutMonitor&) = delete;
31 
32   // KeyboardLayoutMonitor implementation.
33   void Start() override;
34 
35   // Called when KeyboardChanged IPC message is received.
36   void OnKeyboardChanged(const protocol::KeyboardLayout& layout);
37 
38  private:
39   base::RepeatingCallback<void(const protocol::KeyboardLayout&)> callback_;
40   scoped_refptr<DesktopSessionProxy> desktop_session_proxy_;
41   base::WeakPtrFactory<IpcKeyboardLayoutMonitor> weak_ptr_factory_;
42 };
43 
44 }  // namespace remoting
45 
46 #endif  // REMOTING_HOST_IPC_KEYBOARD_LAYOUT_MONITOR_H_
47