Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(764)

Side by Side Diff: chromeos/dbus/services/cros_dbus_service.h

Issue 2693243002: chromeos: Make CrosDBusService not be a singleton. (Closed)
Patch Set: whoops, fix reversed logic in IsUsingFakes check Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROMEOS_DBUS_SERVICES_CROS_DBUS_SERVICE_H_ 5 #ifndef CHROMEOS_DBUS_SERVICES_CROS_DBUS_SERVICE_H_
6 #define CHROMEOS_DBUS_SERVICES_CROS_DBUS_SERVICE_H_ 6 #define CHROMEOS_DBUS_SERVICES_CROS_DBUS_SERVICE_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/macros.h"
11 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
12 #include "base/threading/platform_thread.h" 13 #include "base/threading/platform_thread.h"
13 #include "chromeos/chromeos_export.h" 14 #include "chromeos/chromeos_export.h"
14 15
15 namespace dbus { 16 namespace dbus {
16 class Bus; 17 class Bus;
17 class ExportedObject; 18 class ExportedObject;
19 class ObjectPath;
18 } 20 }
19 21
20 namespace chromeos { 22 namespace chromeos {
21 23
22 // CrosDBusService is used to run a D-Bus service inside Chrome for Chrome 24 // CrosDBusService is used to run a D-Bus service inside Chrome for Chrome OS.
23 // OS. The service will be registered as follows: 25 // It exports D-Bus methods through service provider classes that implement
24 // 26 // CrosDBusService::ServiceProviderInterface.
25 // Service name: org.chromium.LibCrosService (kLibCrosServiceName)
26 // Object path: chromium/LibCrosService (kLibCrosServicePath)
27 //
28 // For historical reasons, the rather irrelevant name "LibCrosService" is
29 // used in the D-Bus constants such as the service name.
30 //
31 // CrosDBusService exports D-Bus methods through service provider classes
32 // that implement CrosDBusService::ServiceProviderInterface.
33
34 class CHROMEOS_EXPORT CrosDBusService { 27 class CHROMEOS_EXPORT CrosDBusService {
35 public: 28 public:
36 // CrosDBusService consists of service providers that implement this 29 // CrosDBusService consists of service providers that implement this
37 // interface. 30 // interface.
38 class ServiceProviderInterface { 31 class ServiceProviderInterface {
39 public: 32 public:
40 // Starts the service provider. |exported_object| is used to export 33 // Starts the service provider. |exported_object| is used to export
41 // D-Bus methods. 34 // D-Bus methods.
42 virtual void Start( 35 virtual void Start(
43 scoped_refptr<dbus::ExportedObject> exported_object) = 0; 36 scoped_refptr<dbus::ExportedObject> exported_object) = 0;
44 37
45 virtual ~ServiceProviderInterface(); 38 virtual ~ServiceProviderInterface();
46 }; 39 };
47 40
48 using ServiceProviderList = 41 using ServiceProviderList =
49 std::vector<std::unique_ptr<ServiceProviderInterface>>; 42 std::vector<std::unique_ptr<ServiceProviderInterface>>;
50 43
51 // Initializes the global instance. 44 // Creates, starts, and returns a new instance owning |service_name| and
52 static void Initialize(ServiceProviderList service_providers); 45 // exporting |service_providers|'s methods on |object_path|. Static so a stub
53 // Destroys the global instance. 46 // implementation can be used when not running on a device.
54 static void Shutdown(); 47 static std::unique_ptr<CrosDBusService> Create(
48 const std::string& service_name,
49 const dbus::ObjectPath& object_path,
50 ServiceProviderList service_providers);
51
52 virtual ~CrosDBusService();
55 53
56 protected: 54 protected:
57 virtual ~CrosDBusService(); 55 CrosDBusService();
58 56
59 private: 57 private:
60 friend class CrosDBusServiceTest; 58 friend class CrosDBusServiceTest;
61 59
62 // Initializes the global instance for testing. 60 // Creates, starts, and returns a real implementation of CrosDBusService that
63 static void InitializeForTesting(dbus::Bus* bus, 61 // uses |bus|. Called by Create(), but can also be called directly by tests
64 ServiceProviderList service_providers); 62 // that need a non-stub implementation even when not running on a device.
63 static std::unique_ptr<CrosDBusService> CreateRealImpl(
64 dbus::Bus* bus,
65 const std::string& service_name,
66 const dbus::ObjectPath& object_path,
67 ServiceProviderList service_providers);
68
69 DISALLOW_COPY_AND_ASSIGN(CrosDBusService);
65 }; 70 };
66 71
67 } // namespace chromeos 72 } // namespace chromeos
68 73
69 #endif // CHROMEOS_DBUS_SERVICES_CROS_DBUS_SERVICE_H_ 74 #endif // CHROMEOS_DBUS_SERVICES_CROS_DBUS_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/chrome_browser_main_chromeos.cc ('k') | chromeos/dbus/services/cros_dbus_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698