summaryrefslogtreecommitdiffstats
path: root/chromeos/ime/ibus_daemon_controller.h
blob: aa9d91c1189284388d6aa22f788e96c9fd35409d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) 2012 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 CHROMEOS_IME_IBUS_DAEMON_CONTROLLER_H_
#define CHROMEOS_IME_IBUS_DAEMON_CONTROLLER_H_

#include "base/memory/ref_counted.h"
#include "base/sequenced_task_runner.h"
#include "chromeos/chromeos_export.h"

namespace chromeos {

// IBusDaemonController is used to start/stop ibus-daemon process. This class is
// also watching ibus-daemon process and if it is crashed, re-launch it
// automatically. This class is managed as Singleton.
class CHROMEOS_EXPORT IBusDaemonController {
 public:
  class Observer {
   public:
    // Called when the connection with ibus-daemon is established.
    virtual void OnConnected() = 0;

    // Called when the connection with ibus-daemon is lost.
    virtual void OnDisconnected() = 0;
  };

  // Initializes IBusDaemonController. ibus-daemon related file handling is
  // posted to |file_task_runner|. This function must be called before any
  // GetInstance() function call.
  static void Initialize(
      const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner,
      const scoped_refptr<base::SequencedTaskRunner>& file_task_runner);

  // Similar to Initialize(), but can inject alternative IBusDaemonController
  // such as MockIBusDaemonController for testing. The injected object object
  // will be owned by the internal pointer and deleted by Shutdown().
  static void InitializeForTesting(IBusDaemonController* controller);

  // Destroys the global instance.
  static void Shutdown();

  // Returns actual implementation of IBusDaemonController. If the browser is
  // not running on the Chrome OS device, this function returns stub
  // implementation.
  static CHROMEOS_EXPORT IBusDaemonController* GetInstance();

  virtual ~IBusDaemonController();

  virtual void AddObserver(Observer* observer) = 0;
  virtual void RemoveObserver(Observer* observer) = 0;

  // Starts ibus-daemon.
  virtual bool Start() = 0;

  // Stops ibus-daemon.
  virtual bool Stop() = 0;

 protected:
  // IBusDaemonController is managed as singleton. Use GetInstance instead.
  IBusDaemonController();

  DISALLOW_COPY_AND_ASSIGN(IBusDaemonController);
};

}  // namespace chromeos

#endif  // CHROMEOS_IME_IBUS_DAEMON_CONTROLLER_H_