| Index: chromeos/dbus/arc_instance_client.cc
|
| diff --git a/chromeos/dbus/arc_instance_client.cc b/chromeos/dbus/arc_instance_client.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1c8c5252aa247df91c1e10daec6133473ad15736
|
| --- /dev/null
|
| +++ b/chromeos/dbus/arc_instance_client.cc
|
| @@ -0,0 +1,94 @@
|
| +// Copyright (c) 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +#include "chromeos/dbus/arc_instance_client.h"
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/logging.h"
|
| +#include "base/memory/weak_ptr.h"
|
| +#include "dbus/bus.h"
|
| +#include "dbus/message.h"
|
| +#include "dbus/object_path.h"
|
| +#include "dbus/object_proxy.h"
|
| +
|
| +namespace chromeos {
|
| +
|
| +namespace {
|
| +
|
| +// todo(denniskempin): Move constants to the chromiumos platform
|
| +// service_constants.h
|
| +const char kArcInstanceServicePath[] = "/org/chromium/arc/instanceservice";
|
| +const char kArcInstanceServiceName[] = "org.chromium.arc.InstanceService";
|
| +const char kArcInstanceServiceInterface[] = "org.chromium.arc.InstanceService";
|
| +
|
| +const char kStartInstanceMethod[] = "StartInstance";
|
| +const char kStopInstanceMethod[] = "StopInstance";
|
| +
|
| +void OnVoidDBusMethod(const VoidDBusMethodCallback& callback,
|
| + dbus::Response* response) {
|
| + callback.Run(response ? DBUS_METHOD_CALL_SUCCESS : DBUS_METHOD_CALL_FAILURE);
|
| +}
|
| +
|
| +class ArcInstanceClientImpl : public ArcInstanceClient {
|
| + public:
|
| + ArcInstanceClientImpl() : proxy_(nullptr), weak_ptr_factory_(this) {}
|
| +
|
| + ~ArcInstanceClientImpl() override {}
|
| +
|
| + // Start an instance of ARC. |callback| is called after the method call
|
| + // succeeds.
|
| + void StartInstance(const std::string& socket_path,
|
| + const VoidDBusMethodCallback& callback) override {
|
| + DCHECK(proxy_);
|
| +
|
| + dbus::MethodCall method_call(kArcInstanceServiceInterface,
|
| + kStartInstanceMethod);
|
| + dbus::MessageWriter builder(&method_call);
|
| + builder.AppendString(socket_path);
|
| + proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
|
| + base::Bind(&OnVoidDBusMethod, callback));
|
| + }
|
| +
|
| + // Stop a currently running instance of ARC. |callback| is called after the
|
| + // method call succeeds.
|
| + void StopInstance(const VoidDBusMethodCallback& callback) override {
|
| + DCHECK(proxy_);
|
| +
|
| + dbus::MethodCall method_call(kArcInstanceServiceInterface,
|
| + kStopInstanceMethod);
|
| + proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
|
| + base::Bind(&OnVoidDBusMethod, callback));
|
| + }
|
| +
|
| + protected:
|
| + void Init(dbus::Bus* bus) override {
|
| + proxy_ = bus->GetObjectProxy(kArcInstanceServiceName,
|
| + dbus::ObjectPath(kArcInstanceServicePath));
|
| + DCHECK(proxy_);
|
| + }
|
| +
|
| + private:
|
| + dbus::ObjectProxy* proxy_;
|
| +
|
| + // Note: This should remain the last member so it'll be destroyed and
|
| + // invalidate its weak pointers before any other members are destroyed.
|
| + base::WeakPtrFactory<ArcInstanceClientImpl> weak_ptr_factory_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(ArcInstanceClientImpl);
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// ArcInstanceClient
|
| +
|
| +ArcInstanceClient::ArcInstanceClient() {}
|
| +
|
| +ArcInstanceClient::~ArcInstanceClient() {}
|
| +
|
| +// static
|
| +ArcInstanceClient* ArcInstanceClient::Create() {
|
| + return new ArcInstanceClientImpl();
|
| +}
|
| +
|
| +} // namespace chromeos
|
|
|