Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
|
hashimoto
2016/11/14 22:09:40
nit: No (c) after Copyright.
Roman Sorokin (ftl)
2016/11/15 10:04:10
Done.
| |
| 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 = | |
| 32 bus_->GetObjectProxy(kUpstartServiceName, objectPath); | |
| 33 dbus::MethodCall method_call(kUpstartJobInterface, kUpstartStartMethod); | |
| 34 dbus::MessageWriter writer(&method_call); | |
| 35 writer.AppendArrayOfStrings(std::vector<std::string>()); | |
| 36 writer.AppendBool(true); // Wait for response. | |
| 37 proxy->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
| 38 base::Bind(&UpstartClientImpl::HandleStartResponse, | |
| 39 weak_ptr_factory_.GetWeakPtr())); | |
| 40 } | |
| 41 | |
| 42 protected: | |
| 43 void Init(dbus::Bus* bus) override { bus_ = bus; } | |
| 44 | |
| 45 private: | |
| 46 void HandleStartResponse(dbus::Response* response) { | |
| 47 LOG_IF(ERROR, !response) << "Failed to signal Upstart, response is null"; | |
| 48 } | |
| 49 | |
| 50 dbus::Bus* bus_ = nullptr; | |
| 51 | |
| 52 // Note: This should remain the last member so it'll be destroyed and | |
| 53 // invalidate its weak pointers before any other members are destroyed. | |
| 54 base::WeakPtrFactory<UpstartClientImpl> weak_ptr_factory_; | |
| 55 | |
| 56 DISALLOW_COPY_AND_ASSIGN(UpstartClientImpl); | |
| 57 }; | |
| 58 | |
| 59 } // namespace | |
| 60 | |
| 61 UpstartClient::UpstartClient() {} | |
| 62 | |
| 63 UpstartClient::~UpstartClient() {} | |
| 64 | |
| 65 // static | |
| 66 UpstartClient* UpstartClient::Create() { | |
| 67 return new UpstartClientImpl(); | |
| 68 } | |
| 69 | |
| 70 } // namespace chromeos | |
| OLD | NEW |