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

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

Issue 2475343002: Add UpstartClient (Closed)
Patch Set: Rebase Created 4 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
« no previous file with comments | « chromeos/dbus/upstart_client.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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
5 #include "chromeos/dbus/upstart_client.h"
6
7 #include "base/bind.h"
8 #include "base/memory/weak_ptr.h"
9 #include "dbus/bus.h"
10 #include "dbus/message.h"
11 #include "dbus/object_proxy.h"
12
13 namespace chromeos {
14
15 namespace {
16
17 const char kUpstartServiceName[] = "com.ubuntu.Upstart";
18 const char kUpstartJobInterface[] = "com.ubuntu.Upstart0_6.Job";
19 const char kUpstartStartMethod[] = "Start";
20
21 const char kUpstartAuthPolicyPath[] = "/com/ubuntu/Upstart/jobs/authpolicyd";
22
23 class UpstartClientImpl : public UpstartClient {
24 public:
25 UpstartClientImpl() : weak_ptr_factory_(this) {}
26
27 ~UpstartClientImpl() override {}
28
29 // UpstartClient override.
30 void StartAuthPolicyService() override {
31 dbus::ObjectPath objectPath(kUpstartAuthPolicyPath);
32 dbus::ObjectProxy* proxy =
33 bus_->GetObjectProxy(kUpstartServiceName, objectPath);
34 dbus::MethodCall method_call(kUpstartJobInterface, kUpstartStartMethod);
35 dbus::MessageWriter writer(&method_call);
36 writer.AppendArrayOfStrings(std::vector<std::string>());
37 writer.AppendBool(true); // Wait for response.
38 proxy->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
39 base::Bind(&UpstartClientImpl::HandleStartResponse,
40 weak_ptr_factory_.GetWeakPtr()));
41 }
42
43 protected:
44 void Init(dbus::Bus* bus) override { bus_ = bus; }
45
46 private:
47 void HandleStartResponse(dbus::Response* response) {
48 LOG_IF(ERROR, !response) << "Failed to signal Upstart, response is null";
49 }
50
51 dbus::Bus* bus_ = nullptr;
52
53 // Note: This should remain the last member so it'll be destroyed and
54 // invalidate its weak pointers before any other members are destroyed.
55 base::WeakPtrFactory<UpstartClientImpl> weak_ptr_factory_;
56
57 DISALLOW_COPY_AND_ASSIGN(UpstartClientImpl);
58 };
59
60 } // namespace
61
62 UpstartClient::UpstartClient() {}
63
64 UpstartClient::~UpstartClient() {}
65
66 // static
67 UpstartClient* UpstartClient::Create() {
68 return new UpstartClientImpl();
69 }
70
71 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/upstart_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698