Home | History | Annotate | Download | only in dbus
      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 CHROME_BROWSER_CHROMEOS_DBUS_CROS_DBUS_SERVICE_H_
      6 #define CHROME_BROWSER_CHROMEOS_DBUS_CROS_DBUS_SERVICE_H_
      7 
      8 #include <vector>
      9 
     10 #include "base/memory/ref_counted.h"
     11 #include "base/threading/platform_thread.h"
     12 
     13 namespace dbus {
     14 class Bus;
     15 class ExportedObject;
     16 }
     17 
     18 namespace chromeos {
     19 
     20 // CrosDBusService is used to run a D-Bus service inside Chrome for Chrome
     21 // OS. The service will be registered as follows:
     22 //
     23 // Service name: org.chromium.LibCrosService (kLibCrosServiceName)
     24 // Object path: chromium/LibCrosService (kLibCrosServicePath)
     25 //
     26 // For historical reasons, the rather irrelevant name "LibCrosService" is
     27 // used in the D-Bus constants such as the service name.
     28 //
     29 // CrosDBusService exports D-Bus methods through service provider classes
     30 // that implement CrosDBusService::ServiceProviderInterface.
     31 
     32 class CrosDBusService {
     33  public:
     34   // CrosDBusService consists of service providers that implement this
     35   // interface.
     36   class ServiceProviderInterface {
     37    public:
     38     // Starts the service provider. |exported_object| is used to export
     39     // D-Bus methods.
     40     virtual void Start(
     41         scoped_refptr<dbus::ExportedObject> exported_object) = 0;
     42 
     43     virtual ~ServiceProviderInterface();
     44   };
     45 
     46   // Initializes the global instance.
     47   static void Initialize();
     48   // Destroys the global instance.
     49   static void Shutdown();
     50 
     51  protected:
     52   virtual ~CrosDBusService();
     53 
     54  private:
     55   // Initializes the global instance for testing. Takes ownership of
     56   // |proxy_resolution_service|.
     57   friend class CrosDBusServiceTest;
     58   static void InitializeForTesting(
     59       dbus::Bus* bus,
     60       ServiceProviderInterface* proxy_resolution_service);
     61 };
     62 
     63 }  // namespace
     64 
     65 #endif  // CHROME_BROWSER_CHROMEOS_DBUS_CROS_DBUS_SERVICE_H_
     66