Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chromeos / dbus / services / cros_dbus_service.h
blob50d22979195bfb7025eb199c9516f306da06744a
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.
5 #ifndef CHROMEOS_DBUS_SERVICES_CROS_DBUS_SERVICE_H_
6 #define CHROMEOS_DBUS_SERVICES_CROS_DBUS_SERVICE_H_
8 #include <vector>
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_vector.h"
12 #include "base/threading/platform_thread.h"
13 #include "chromeos/chromeos_export.h"
15 namespace dbus {
16 class Bus;
17 class ExportedObject;
20 namespace chromeos {
22 // CrosDBusService is used to run a D-Bus service inside Chrome for Chrome
23 // OS. The service will be registered as follows:
25 // Service name: org.chromium.LibCrosService (kLibCrosServiceName)
26 // Object path: chromium/LibCrosService (kLibCrosServicePath)
28 // For historical reasons, the rather irrelevant name "LibCrosService" is
29 // used in the D-Bus constants such as the service name.
31 // CrosDBusService exports D-Bus methods through service provider classes
32 // that implement CrosDBusService::ServiceProviderInterface.
34 class CHROMEOS_EXPORT CrosDBusService {
35 public:
36 // CrosDBusService consists of service providers that implement this
37 // interface.
38 class ServiceProviderInterface {
39 public:
40 // Starts the service provider. |exported_object| is used to export
41 // D-Bus methods.
42 virtual void Start(
43 scoped_refptr<dbus::ExportedObject> exported_object) = 0;
45 virtual ~ServiceProviderInterface();
48 // Initializes the global instance.
49 static void Initialize(
50 ScopedVector<ServiceProviderInterface> service_providers);
51 // Destroys the global instance.
52 static void Shutdown();
54 protected:
55 virtual ~CrosDBusService();
57 private:
58 friend class CrosDBusServiceTest;
60 // Initializes the global instance for testing.
61 static void InitializeForTesting(
62 dbus::Bus* bus,
63 ScopedVector<ServiceProviderInterface> service_providers);
66 } // namespace chromeos
68 #endif // CHROMEOS_DBUS_SERVICES_CROS_DBUS_SERVICE_H_