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.LivenessService | 29 // --dest=org.chromium.LibCrosService |
30 // /org/chromium/LivenessService | 30 // /org/chromium/LibCrosService |
31 // org.chromium.LivenessServiceInterface.CheckLiveness | 31 // org.chromium.LibCrosServiceInterface.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 // TODO(teravest): Remove the service_interface argument once this is no | 39 LivenessServiceProvider(); |
40 // longer used by LibCrosService. | |
41 explicit LivenessServiceProvider(const std::string& service_interface); | |
42 ~LivenessServiceProvider() override; | 40 ~LivenessServiceProvider() override; |
43 | 41 |
44 // CrosDBusService::ServiceProviderInterface overrides: | 42 // CrosDBusService::ServiceProviderInterface overrides: |
45 void Start(scoped_refptr<dbus::ExportedObject> exported_object) override; | 43 void Start(scoped_refptr<dbus::ExportedObject> exported_object) override; |
46 | 44 |
47 private: | 45 private: |
48 // Called from ExportedObject when CheckLiveness() is exported as a D-Bus | 46 // Called from ExportedObject when CheckLiveness() is exported as a D-Bus |
49 // method or failed to be exported. | 47 // method or failed to be exported. |
50 void OnExported(const std::string& interface_name, | 48 void OnExported(const std::string& interface_name, |
51 const std::string& method_name, | 49 const std::string& method_name, |
52 bool success); | 50 bool success); |
53 | 51 |
54 // Called on UI thread in response to a D-Bus request. | 52 // Called on UI thread in response to a D-Bus request. |
55 void CheckLiveness(dbus::MethodCall* method_call, | 53 void CheckLiveness(dbus::MethodCall* method_call, |
56 dbus::ExportedObject::ResponseSender response_sender); | 54 dbus::ExportedObject::ResponseSender response_sender); |
57 | 55 |
58 std::string service_interface_; | |
59 | |
60 // Keep this last so that all weak pointers will be invalidated at the | 56 // Keep this last so that all weak pointers will be invalidated at the |
61 // beginning of destruction. | 57 // beginning of destruction. |
62 base::WeakPtrFactory<LivenessServiceProvider> weak_ptr_factory_; | 58 base::WeakPtrFactory<LivenessServiceProvider> weak_ptr_factory_; |
63 | 59 |
64 DISALLOW_COPY_AND_ASSIGN(LivenessServiceProvider); | 60 DISALLOW_COPY_AND_ASSIGN(LivenessServiceProvider); |
65 }; | 61 }; |
66 | 62 |
67 } // namespace chromeos | 63 } // namespace chromeos |
68 | 64 |
69 #endif // CHROMEOS_DBUS_SERVICES_LIVENESS_SERVICE_PROVIDER_H_ | 65 #endif // CHROMEOS_DBUS_SERVICES_LIVENESS_SERVICE_PROVIDER_H_ |
OLD | NEW |