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

Side by Side Diff: chromeos/dbus/arc_instance_client.cc

Issue 1421023002: Remove the ARC Bridge Service (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@master
Patch Set: Removed the bool callback for StartInstance Created 5 years, 1 month 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
(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_instance_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 kArcInstanceServicePath[] = "/org/chromium/arc/instanceservice";
21 const char kArcInstanceServiceName[] = "org.chromium.arc.InstanceService";
22 const char kArcInstanceServiceInterface[] = "org.chromium.arc.InstanceService";
23
24 const char kStartInstanceMethod[] = "StartInstance";
25 const char kStopInstanceMethod[] = "StopInstance";
26
27 void OnVoidDBusMethod(const VoidDBusMethodCallback& callback,
28 dbus::Response* response) {
29 callback.Run(response ? DBUS_METHOD_CALL_SUCCESS : DBUS_METHOD_CALL_FAILURE);
30 }
31
32 class ArcInstanceClientImpl : public ArcInstanceClient {
33 public:
34 ArcInstanceClientImpl() : proxy_(nullptr), weak_ptr_factory_(this) {}
35
36 ~ArcInstanceClientImpl() override {}
37
38 // Start an instance of ARC. |callback| is called after the method call
39 // succeeds.
40 void StartInstance(const std::string& socket_path,
41 const VoidDBusMethodCallback& callback) override {
42 DCHECK(proxy_);
43
44 dbus::MethodCall method_call(kArcInstanceServiceInterface,
45 kStartInstanceMethod);
46 dbus::MessageWriter builder(&method_call);
47 builder.AppendString(socket_path);
48 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
49 base::Bind(&OnVoidDBusMethod, callback));
50 }
51
52 // Stop a currently running instance of ARC. |callback| is called after the
53 // method call succeeds.
54 void StopInstance(const VoidDBusMethodCallback& callback) override {
55 DCHECK(proxy_);
56
57 dbus::MethodCall method_call(kArcInstanceServiceInterface,
58 kStopInstanceMethod);
59 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
60 base::Bind(&OnVoidDBusMethod, callback));
61 }
62
63 protected:
64 void Init(dbus::Bus* bus) override {
65 proxy_ = bus->GetObjectProxy(kArcInstanceServiceName,
66 dbus::ObjectPath(kArcInstanceServicePath));
67 DCHECK(proxy_);
68 }
69
70 private:
71 dbus::ObjectProxy* proxy_;
72
73 // Note: This should remain the last member so it'll be destroyed and
74 // invalidate its weak pointers before any other members are destroyed.
75 base::WeakPtrFactory<ArcInstanceClientImpl> weak_ptr_factory_;
76
77 DISALLOW_COPY_AND_ASSIGN(ArcInstanceClientImpl);
78 };
79
80 } // namespace
81
82 ////////////////////////////////////////////////////////////////////////////////
83 // ArcInstanceClient
84
85 ArcInstanceClient::ArcInstanceClient() {}
86
87 ArcInstanceClient::~ArcInstanceClient() {}
88
89 // static
90 ArcInstanceClient* ArcInstanceClient::Create() {
91 return new ArcInstanceClientImpl();
92 }
93
94 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698