Home | History | Annotate | Download | only in ime
      1 // Copyright (c) 2012 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 CHROMEOS_IME_IBUS_DAEMON_CONTROLLER_H_
      6 #define CHROMEOS_IME_IBUS_DAEMON_CONTROLLER_H_
      7 
      8 #include "base/memory/ref_counted.h"
      9 #include "base/sequenced_task_runner.h"
     10 #include "chromeos/chromeos_export.h"
     11 
     12 namespace chromeos {
     13 
     14 // IBusDaemonController is used to start/stop ibus-daemon process. This class is
     15 // also watching ibus-daemon process and if it is crashed, re-launch it
     16 // automatically. This class is managed as Singleton.
     17 class CHROMEOS_EXPORT IBusDaemonController {
     18  public:
     19   class Observer {
     20    public:
     21     // Called when the connection with ibus-daemon is established.
     22     virtual void OnConnected() = 0;
     23 
     24     // Called when the connection with ibus-daemon is lost.
     25     virtual void OnDisconnected() = 0;
     26   };
     27 
     28   // Initializes IBusDaemonController. ibus-daemon related file handling is
     29   // posted to |file_task_runner|. This function must be called before any
     30   // GetInstance() function call.
     31   static void Initialize(
     32       const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner,
     33       const scoped_refptr<base::SequencedTaskRunner>& file_task_runner);
     34 
     35   // Similar to Initialize(), but can inject alternative IBusDaemonController
     36   // such as MockIBusDaemonController for testing. The injected object object
     37   // will be owned by the internal pointer and deleted by Shutdown().
     38   static void InitializeForTesting(IBusDaemonController* controller);
     39 
     40   // Destroys the global instance.
     41   static void Shutdown();
     42 
     43   // Returns actual implementation of IBusDaemonController. If the browser is
     44   // not running on the Chrome OS device, this function returns stub
     45   // implementation.
     46   static CHROMEOS_EXPORT IBusDaemonController* GetInstance();
     47 
     48   virtual ~IBusDaemonController();
     49 
     50   virtual void AddObserver(Observer* observer) = 0;
     51   virtual void RemoveObserver(Observer* observer) = 0;
     52 
     53   // Starts ibus-daemon.
     54   virtual bool Start() = 0;
     55 
     56   // Stops ibus-daemon.
     57   virtual bool Stop() = 0;
     58 
     59  protected:
     60   // IBusDaemonController is managed as singleton. Use GetInstance instead.
     61   IBusDaemonController();
     62 
     63   DISALLOW_COPY_AND_ASSIGN(IBusDaemonController);
     64 };
     65 
     66 }  // namespace chromeos
     67 
     68 #endif  // CHROMEOS_IME_IBUS_DAEMON_CONTROLLER_H_
     69