summaryrefslogtreecommitdiffstats
path: root/chromeos/dbus/services/cros_dbus_service.h
blob: 50d22979195bfb7025eb199c9516f306da06744a (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_DBUS_SERVICES_CROS_DBUS_SERVICE_H_
#define CHROMEOS_DBUS_SERVICES_CROS_DBUS_SERVICE_H_

#include <vector>

#include "base/memory/ref_counted.h"
#include "base/memory/scoped_vector.h"
#include "base/threading/platform_thread.h"
#include "chromeos/chromeos_export.h"

namespace dbus {
class Bus;
class ExportedObject;
}

namespace chromeos {

// CrosDBusService is used to run a D-Bus service inside Chrome for Chrome
// OS. The service will be registered as follows:
//
// Service name: org.chromium.LibCrosService (kLibCrosServiceName)
// Object path: chromium/LibCrosService (kLibCrosServicePath)
//
// For historical reasons, the rather irrelevant name "LibCrosService" is
// used in the D-Bus constants such as the service name.
//
// CrosDBusService exports D-Bus methods through service provider classes
// that implement CrosDBusService::ServiceProviderInterface.

class CHROMEOS_EXPORT CrosDBusService {
 public:
  // CrosDBusService consists of service providers that implement this
  // interface.
  class ServiceProviderInterface {
   public:
    // Starts the service provider. |exported_object| is used to export
    // D-Bus methods.
    virtual void Start(
        scoped_refptr<dbus::ExportedObject> exported_object) = 0;

    virtual ~ServiceProviderInterface();
  };

  // Initializes the global instance.
  static void Initialize(
      ScopedVector<ServiceProviderInterface> service_providers);
  // Destroys the global instance.
  static void Shutdown();

 protected:
  virtual ~CrosDBusService();

 private:
  friend class CrosDBusServiceTest;

  // Initializes the global instance for testing.
  static void InitializeForTesting(
      dbus::Bus* bus,
      ScopedVector<ServiceProviderInterface> service_providers);
};

}  // namespace chromeos

#endif  // CHROMEOS_DBUS_SERVICES_CROS_DBUS_SERVICE_H_