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

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

Issue 2475343002: Add UpstartClient (Closed)
Patch Set: Created UpstartClient and moved StartService there 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
OLDNEW
(Empty)
1 // Copyright (c) 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 #include "chromeos/dbus/upstart_client.h"
5
6 #include "base/bind.h"
7 #include "base/memory/weak_ptr.h"
8 #include "dbus/bus.h"
9 #include "dbus/message.h"
10 #include "dbus/object_proxy.h"
11
12 namespace chromeos {
13
14 namespace {
15
16 const char kUpstartServiceName[] = "com.ubuntu.Upstart";
17 const char kUpstartJobInterface[] = "com.ubuntu.Upstart0_6.Job";
18 const char kUpstartStartMethod[] = "Start";
19
20 const char kUpstartAuthPolicyPath[] = "/com/ubuntu/Upstart/jobs/authpolicyd";
21
22 class UpstartClientImpl : public UpstartClient {
23 public:
24 UpstartClientImpl() : weak_ptr_factory_(this) {}
25
26 ~UpstartClientImpl() override {}
27
28 // UpstartClient override.
29 void StartAuthPolicyService() override {
30 dbus::ObjectPath objectPath(kUpstartAuthPolicyPath);
31 dbus::ObjectProxy* proxy =
hashimoto 2016/11/08 20:23:58 Please make proxy_ a member of this class to be co
Roman Sorokin (ftl) 2016/11/09 14:03:30 Hmm, what is the right way to do that? Since this
hashimoto 2016/11/11 03:46:57 Ah, it seems this method is tricky. Where can I lo
hashimoto 2016/11/11 05:30:20 FYI, another possible approach is to let the sessi
Roman Sorokin (ftl) 2016/11/14 13:54:19 The problem is we need to start it from Chrome any
Roman Sorokin (ftl) 2016/11/14 13:54:19 I looked here: http://upstart.ubuntu.com/cookbook/
hashimoto 2016/11/14 22:09:40 Thank you for giving me a pointer!
32 bus_->GetObjectProxy(kUpstartServiceName, objectPath);
33 dbus::MethodCall method_call(kUpstartJobInterface, kUpstartStartMethod);
34 dbus::MessageWriter writer(&method_call);
35 dbus::MessageWriter sub_writer(nullptr);
36 writer.OpenArray("s", &sub_writer);
37 writer.CloseContainer(&sub_writer);
hashimoto 2016/11/08 20:23:59 suggestion: How about writer.AppendArrayOfStrings(
Roman Sorokin (ftl) 2016/11/09 14:03:30 Done.
38 writer.AppendBool(false); // No waiting for response.
hashimoto 2016/11/08 20:23:58 IIUC this parameter changes the timing when the re
Roman Sorokin (ftl) 2016/11/09 14:03:30 I checked both options, but response is null in bo
hashimoto 2016/11/11 03:46:58 IIUC, without waiting, it results in ignoring erro
Roman Sorokin (ftl) 2016/11/14 13:53:15 Done.
39 proxy->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
40 base::Bind(&UpstartClientImpl::HandleUpstartCallback,
41 weak_ptr_factory_.GetWeakPtr()));
42 }
43
44 protected:
45 void Init(dbus::Bus* bus) override { bus_ = bus; }
46
47 private:
48 void HandleUpstartCallback(dbus::Response* response) {
hashimoto 2016/11/08 20:23:58 HandleUpstartCallback sounds ambiguous as basicall
Roman Sorokin (ftl) 2016/11/09 14:03:30 Done.
49 if (!response) {
50 LOG(ERROR) << "Failed to signal Upstart, response is null";
51 return;
hashimoto 2016/11/08 20:23:58 nit: This line is redundant. Probably you should
Roman Sorokin (ftl) 2016/11/09 14:03:30 Done.
52 }
53 }
54
55 dbus::Bus* bus_ = nullptr;
56
57 // Note: This should remain the last member so it'll be destroyed and
58 // invalidate its weak pointers before any other members are destroyed.
59 base::WeakPtrFactory<UpstartClientImpl> weak_ptr_factory_;
60
61 DISALLOW_COPY_AND_ASSIGN(UpstartClientImpl);
62 };
63
64 } // namespace
65
66 UpstartClient::UpstartClient() {}
67
68 UpstartClient::~UpstartClient() {}
69
70 // static
71 UpstartClient* UpstartClient::Create() {
72 return new UpstartClientImpl();
73 }
74
75 } // namespace chromeos
OLDNEW
« chromeos/dbus/fake_upstart_client.h ('K') | « chromeos/dbus/upstart_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698