OLD | NEW |
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_LIVENESS_SERVICE_PROVIDER_H_ | 5 #ifndef CHROMEOS_DBUS_SERVICES_LIVENESS_SERVICE_PROVIDER_H_ |
6 #define CHROMEOS_DBUS_SERVICES_LIVENESS_SERVICE_PROVIDER_H_ | 6 #define CHROMEOS_DBUS_SERVICES_LIVENESS_SERVICE_PROVIDER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "chromeos/chromeos_export.h" | 14 #include "chromeos/chromeos_export.h" |
15 #include "chromeos/dbus/services/cros_dbus_service.h" | 15 #include "chromeos/dbus/services/cros_dbus_service.h" |
16 #include "dbus/exported_object.h" | 16 #include "dbus/exported_object.h" |
17 | 17 |
18 namespace dbus { | 18 namespace dbus { |
19 class MethodCall; | 19 class MethodCall; |
20 } | 20 } |
21 | 21 |
22 namespace chromeos { | 22 namespace chromeos { |
23 | 23 |
24 // This class exports a "CheckLiveness" D-Bus method that the session manager | 24 // This class exports a "CheckLiveness" D-Bus method that the session manager |
25 // calls periodically to confirm that Chrome's UI thread is responsive to D-Bus | 25 // calls periodically to confirm that Chrome's UI thread is responsive to D-Bus |
26 // messages. It can be tested with the following command: | 26 // messages. It can be tested with the following command: |
27 // | 27 // |
28 // % dbus-send --system --type=method_call --print-reply | 28 // % dbus-send --system --type=method_call --print-reply |
29 // --dest=org.chromium.LibCrosService | 29 // --dest=org.chromium.LivenessService |
30 // /org/chromium/LibCrosService | 30 // /org/chromium/LivenessService |
31 // org.chromium.LibCrosServiceInterface.CheckLiveness | 31 // org.chromium.LivenessServiceInterface.CheckLiveness |
32 // | 32 // |
33 // -> method return sender=:1.9 -> dest=:1.27 reply_serial=2 | 33 // -> method return sender=:1.9 -> dest=:1.27 reply_serial=2 |
34 // | 34 // |
35 // (An empty response should be returned.) | 35 // (An empty response should be returned.) |
36 class CHROMEOS_EXPORT LivenessServiceProvider | 36 class CHROMEOS_EXPORT LivenessServiceProvider |
37 : public CrosDBusService::ServiceProviderInterface { | 37 : public CrosDBusService::ServiceProviderInterface { |
38 public: | 38 public: |
39 LivenessServiceProvider(); | 39 // TODO(teravest): Remove the service_interface argument once this is no |
| 40 // longer used by LibCrosService. |
| 41 explicit LivenessServiceProvider(const std::string& service_interface); |
40 ~LivenessServiceProvider() override; | 42 ~LivenessServiceProvider() override; |
41 | 43 |
42 // CrosDBusService::ServiceProviderInterface overrides: | 44 // CrosDBusService::ServiceProviderInterface overrides: |
43 void Start(scoped_refptr<dbus::ExportedObject> exported_object) override; | 45 void Start(scoped_refptr<dbus::ExportedObject> exported_object) override; |
44 | 46 |
45 private: | 47 private: |
46 // Called from ExportedObject when CheckLiveness() is exported as a D-Bus | 48 // Called from ExportedObject when CheckLiveness() is exported as a D-Bus |
47 // method or failed to be exported. | 49 // method or failed to be exported. |
48 void OnExported(const std::string& interface_name, | 50 void OnExported(const std::string& interface_name, |
49 const std::string& method_name, | 51 const std::string& method_name, |
50 bool success); | 52 bool success); |
51 | 53 |
52 // Called on UI thread in response to a D-Bus request. | 54 // Called on UI thread in response to a D-Bus request. |
53 void CheckLiveness(dbus::MethodCall* method_call, | 55 void CheckLiveness(dbus::MethodCall* method_call, |
54 dbus::ExportedObject::ResponseSender response_sender); | 56 dbus::ExportedObject::ResponseSender response_sender); |
55 | 57 |
| 58 std::string service_interface_; |
| 59 |
56 // Keep this last so that all weak pointers will be invalidated at the | 60 // Keep this last so that all weak pointers will be invalidated at the |
57 // beginning of destruction. | 61 // beginning of destruction. |
58 base::WeakPtrFactory<LivenessServiceProvider> weak_ptr_factory_; | 62 base::WeakPtrFactory<LivenessServiceProvider> weak_ptr_factory_; |
59 | 63 |
60 DISALLOW_COPY_AND_ASSIGN(LivenessServiceProvider); | 64 DISALLOW_COPY_AND_ASSIGN(LivenessServiceProvider); |
61 }; | 65 }; |
62 | 66 |
63 } // namespace chromeos | 67 } // namespace chromeos |
64 | 68 |
65 #endif // CHROMEOS_DBUS_SERVICES_LIVENESS_SERVICE_PROVIDER_H_ | 69 #endif // CHROMEOS_DBUS_SERVICES_LIVENESS_SERVICE_PROVIDER_H_ |
OLD | NEW |