| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2015 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. | |
| 4 #include "chromeos/dbus/arc_bridge_client.h" | |
| 5 | |
| 6 #include "base/bind.h" | |
| 7 #include "base/logging.h" | |
| 8 #include "base/memory/weak_ptr.h" | |
| 9 #include "dbus/bus.h" | |
| 10 #include "dbus/message.h" | |
| 11 #include "dbus/object_path.h" | |
| 12 #include "dbus/object_proxy.h" | |
| 13 | |
| 14 namespace chromeos { | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 // todo(denniskempin): Move constants to the chromiumos platform | |
| 19 // service_constants.h | |
| 20 const char kArcBridgeServicePath[] = "/org/chromium/arc"; | |
| 21 const char kArcBridgeServiceName[] = "org.chromium.arc"; | |
| 22 const char kArcBridgeServiceInterface[] = "org.chromium.arc"; | |
| 23 | |
| 24 const char kPingMethod[] = "Ping"; | |
| 25 | |
| 26 void OnVoidDBusMethod(const VoidDBusMethodCallback& callback, | |
| 27 dbus::Response* response) { | |
| 28 callback.Run(response ? DBUS_METHOD_CALL_SUCCESS : DBUS_METHOD_CALL_FAILURE); | |
| 29 } | |
| 30 | |
| 31 class ArcBridgeClientImpl : public ArcBridgeClient { | |
| 32 public: | |
| 33 ArcBridgeClientImpl() : proxy_(nullptr), weak_ptr_factory_(this) {} | |
| 34 | |
| 35 ~ArcBridgeClientImpl() override {} | |
| 36 | |
| 37 // Calls Ping method. |callback| is called after the method call succeeds. | |
| 38 void Ping(const VoidDBusMethodCallback& callback) override { | |
| 39 DCHECK(proxy_); | |
| 40 | |
| 41 dbus::MethodCall method_call(kArcBridgeServiceInterface, kPingMethod); | |
| 42 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
| 43 base::Bind(&OnVoidDBusMethod, callback)); | |
| 44 } | |
| 45 | |
| 46 protected: | |
| 47 void Init(dbus::Bus* bus) override { | |
| 48 proxy_ = bus->GetObjectProxy(kArcBridgeServiceName, | |
| 49 dbus::ObjectPath(kArcBridgeServicePath)); | |
| 50 DCHECK(proxy_); | |
| 51 } | |
| 52 | |
| 53 private: | |
| 54 dbus::ObjectProxy* proxy_; | |
| 55 | |
| 56 // Note: This should remain the last member so it'll be destroyed and | |
| 57 // invalidate its weak pointers before any other members are destroyed. | |
| 58 base::WeakPtrFactory<ArcBridgeClientImpl> weak_ptr_factory_; | |
| 59 | |
| 60 DISALLOW_COPY_AND_ASSIGN(ArcBridgeClientImpl); | |
| 61 }; | |
| 62 | |
| 63 } // namespace | |
| 64 | |
| 65 //////////////////////////////////////////////////////////////////////////////// | |
| 66 // ArcBridgeClient | |
| 67 | |
| 68 ArcBridgeClient::ArcBridgeClient() {} | |
| 69 | |
| 70 ArcBridgeClient::~ArcBridgeClient() {} | |
| 71 | |
| 72 // static | |
| 73 ArcBridgeClient* ArcBridgeClient::Create() { | |
| 74 return new ArcBridgeClientImpl(); | |
| 75 } | |
| 76 | |
| 77 } // namespace chromeos | |
| OLD | NEW |