| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromeos/dbus/permission_broker_client.h" | 5 #include "chromeos/dbus/permission_broker_client.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "dbus/bus.h" | 13 #include "dbus/bus.h" |
| 14 #include "dbus/message.h" | 14 #include "dbus/message.h" |
| 15 #include "dbus/object_proxy.h" | 15 #include "dbus/object_proxy.h" |
| 16 #include "third_party/cros_system_api/dbus/service_constants.h" | 16 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 17 | 17 |
| 18 using permission_broker::kCheckPathAccess; | 18 using permission_broker::kCheckPathAccess; |
| 19 using permission_broker::kOpenPath; | 19 using permission_broker::kOpenPath; |
| 20 using permission_broker::kPermissionBrokerInterface; | 20 using permission_broker::kPermissionBrokerInterface; |
| 21 using permission_broker::kPermissionBrokerServiceName; | 21 using permission_broker::kPermissionBrokerServiceName; |
| 22 using permission_broker::kPermissionBrokerServicePath; | 22 using permission_broker::kPermissionBrokerServicePath; |
| 23 using permission_broker::kReleaseTcpPort; | 23 using permission_broker::kReleaseTcpPort; |
| 24 using permission_broker::kReleaseUdpPort; | 24 using permission_broker::kReleaseUdpPort; |
| 25 using permission_broker::kRequestPathAccess; | |
| 26 using permission_broker::kRequestTcpPortAccess; | 25 using permission_broker::kRequestTcpPortAccess; |
| 27 using permission_broker::kRequestUdpPortAccess; | 26 using permission_broker::kRequestUdpPortAccess; |
| 28 | 27 |
| 29 namespace chromeos { | 28 namespace chromeos { |
| 30 | 29 |
| 31 class PermissionBrokerClientImpl : public PermissionBrokerClient { | 30 class PermissionBrokerClientImpl : public PermissionBrokerClient { |
| 32 public: | 31 public: |
| 33 PermissionBrokerClientImpl() : proxy_(NULL), weak_ptr_factory_(this) {} | 32 PermissionBrokerClientImpl() : proxy_(NULL), weak_ptr_factory_(this) {} |
| 34 | 33 |
| 35 void CheckPathAccess(const std::string& path, | 34 void CheckPathAccess(const std::string& path, |
| 36 const ResultCallback& callback) override { | 35 const ResultCallback& callback) override { |
| 37 dbus::MethodCall method_call(kPermissionBrokerInterface, kCheckPathAccess); | 36 dbus::MethodCall method_call(kPermissionBrokerInterface, kCheckPathAccess); |
| 38 dbus::MessageWriter writer(&method_call); | 37 dbus::MessageWriter writer(&method_call); |
| 39 writer.AppendString(path); | 38 writer.AppendString(path); |
| 40 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 39 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 41 base::Bind(&PermissionBrokerClientImpl::OnResponse, | 40 base::Bind(&PermissionBrokerClientImpl::OnResponse, |
| 42 weak_ptr_factory_.GetWeakPtr(), callback)); | 41 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 43 } | 42 } |
| 44 | 43 |
| 45 void RequestPathAccess(const std::string& path, | |
| 46 const int interface_id, | |
| 47 const ResultCallback& callback) override { | |
| 48 dbus::MethodCall method_call(kPermissionBrokerInterface, | |
| 49 kRequestPathAccess); | |
| 50 dbus::MessageWriter writer(&method_call); | |
| 51 writer.AppendString(path); | |
| 52 writer.AppendInt32(interface_id); | |
| 53 proxy_->CallMethod(&method_call, | |
| 54 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
| 55 base::Bind(&PermissionBrokerClientImpl::OnResponse, | |
| 56 weak_ptr_factory_.GetWeakPtr(), callback)); | |
| 57 } | |
| 58 | |
| 59 void OpenPath(const std::string& path, | 44 void OpenPath(const std::string& path, |
| 60 const OpenPathCallback& callback) override { | 45 const OpenPathCallback& callback) override { |
| 61 dbus::MethodCall method_call(kPermissionBrokerInterface, kOpenPath); | 46 dbus::MethodCall method_call(kPermissionBrokerInterface, kOpenPath); |
| 62 dbus::MessageWriter writer(&method_call); | 47 dbus::MessageWriter writer(&method_call); |
| 63 writer.AppendString(path); | 48 writer.AppendString(path); |
| 64 proxy_->CallMethod( | 49 proxy_->CallMethod( |
| 65 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 50 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 66 base::Bind(&PermissionBrokerClientImpl::OnOpenPathResponse, | 51 base::Bind(&PermissionBrokerClientImpl::OnOpenPathResponse, |
| 67 weak_ptr_factory_.GetWeakPtr(), callback)); | 52 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 68 } | 53 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 | 156 |
| 172 PermissionBrokerClient::PermissionBrokerClient() {} | 157 PermissionBrokerClient::PermissionBrokerClient() {} |
| 173 | 158 |
| 174 PermissionBrokerClient::~PermissionBrokerClient() {} | 159 PermissionBrokerClient::~PermissionBrokerClient() {} |
| 175 | 160 |
| 176 PermissionBrokerClient* PermissionBrokerClient::Create() { | 161 PermissionBrokerClient* PermissionBrokerClient::Create() { |
| 177 return new PermissionBrokerClientImpl(); | 162 return new PermissionBrokerClientImpl(); |
| 178 } | 163 } |
| 179 | 164 |
| 180 } // namespace chromeos | 165 } // namespace chromeos |
| OLD | NEW |