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

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

Issue 1681383002: Add path open errors from the permission broker to the device log. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_request_access
Patch Set: Created 4 years, 10 months 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
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"
(...skipping 24 matching lines...) Expand all
35 const ResultCallback& callback) override { 35 const ResultCallback& callback) override {
36 dbus::MethodCall method_call(kPermissionBrokerInterface, kCheckPathAccess); 36 dbus::MethodCall method_call(kPermissionBrokerInterface, kCheckPathAccess);
37 dbus::MessageWriter writer(&method_call); 37 dbus::MessageWriter writer(&method_call);
38 writer.AppendString(path); 38 writer.AppendString(path);
39 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 39 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
40 base::Bind(&PermissionBrokerClientImpl::OnResponse, 40 base::Bind(&PermissionBrokerClientImpl::OnResponse,
41 weak_ptr_factory_.GetWeakPtr(), callback)); 41 weak_ptr_factory_.GetWeakPtr(), callback));
42 } 42 }
43 43
44 void OpenPath(const std::string& path, 44 void OpenPath(const std::string& path,
45 const OpenPathCallback& callback) override { 45 const OpenPathCallback& callback,
46 const ErrorCallback& error_callback) override {
46 dbus::MethodCall method_call(kPermissionBrokerInterface, kOpenPath); 47 dbus::MethodCall method_call(kPermissionBrokerInterface, kOpenPath);
47 dbus::MessageWriter writer(&method_call); 48 dbus::MessageWriter writer(&method_call);
48 writer.AppendString(path); 49 writer.AppendString(path);
49 proxy_->CallMethod( 50 proxy_->CallMethodWithErrorCallback(
50 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 51 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
51 base::Bind(&PermissionBrokerClientImpl::OnOpenPathResponse, 52 base::Bind(&PermissionBrokerClientImpl::OnOpenPathResponse,
52 weak_ptr_factory_.GetWeakPtr(), callback)); 53 weak_ptr_factory_.GetWeakPtr(), callback),
54 base::Bind(&PermissionBrokerClientImpl::OnError,
55 weak_ptr_factory_.GetWeakPtr(), error_callback));
53 } 56 }
54 57
55 void RequestTcpPortAccess(uint16_t port, 58 void RequestTcpPortAccess(uint16_t port,
56 const std::string& interface, 59 const std::string& interface,
57 const dbus::FileDescriptor& lifeline_fd, 60 const dbus::FileDescriptor& lifeline_fd,
58 const ResultCallback& callback) override { 61 const ResultCallback& callback) override {
59 dbus::MethodCall method_call(kPermissionBrokerInterface, 62 dbus::MethodCall method_call(kPermissionBrokerInterface,
60 kRequestTcpPortAccess); 63 kRequestTcpPortAccess);
61 dbus::MessageWriter writer(&method_call); 64 dbus::MessageWriter writer(&method_call);
62 writer.AppendUint16(port); 65 writer.AppendUint16(port);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 bool result = false; 129 bool result = false;
127 dbus::MessageReader reader(response); 130 dbus::MessageReader reader(response);
128 if (!reader.PopBool(&result)) 131 if (!reader.PopBool(&result))
129 LOG(WARNING) << "Could not parse response: " << response->ToString(); 132 LOG(WARNING) << "Could not parse response: " << response->ToString();
130 callback.Run(result); 133 callback.Run(result);
131 } 134 }
132 135
133 void OnOpenPathResponse(const OpenPathCallback& callback, 136 void OnOpenPathResponse(const OpenPathCallback& callback,
134 dbus::Response* response) { 137 dbus::Response* response) {
135 dbus::FileDescriptor fd; 138 dbus::FileDescriptor fd;
136 if (response) { 139 dbus::MessageReader reader(response);
137 dbus::MessageReader reader(response); 140 if (!reader.PopFileDescriptor(&fd))
138 if (!reader.PopFileDescriptor(&fd)) 141 LOG(WARNING) << "Could not parse response: " << response->ToString();
139 LOG(WARNING) << "Could not parse response: " << response->ToString();
140 } else {
141 LOG(WARNING) << "Access request method call failed.";
142 }
143
144 callback.Run(std::move(fd)); 142 callback.Run(std::move(fd));
145 } 143 }
146 144
145 void OnError(const ErrorCallback& callback, dbus::ErrorResponse* response) {
146 std::string error_name;
147 std::string error_message;
148 if (response) {
149 dbus::MessageReader reader(response);
150 error_name = response->GetErrorName();
151 reader.PopString(&error_message);
152 } else {
153 error_name = "org.chromium.Error.NoResponse";
stevenjb 2016/02/10 00:01:02 nit: define at the top of the file: const char kN
Reilly Grant (use Gerrit) 2016/02/10 00:16:32 Done.
154 }
155 callback.Run(error_name, error_message);
156 }
157
147 dbus::ObjectProxy* proxy_; 158 dbus::ObjectProxy* proxy_;
148 159
149 // Note: This should remain the last member so that it will be destroyed 160 // Note: This should remain the last member so that it will be destroyed
150 // first, invalidating its weak pointers, before the other members are 161 // first, invalidating its weak pointers, before the other members are
151 // destroyed. 162 // destroyed.
152 base::WeakPtrFactory<PermissionBrokerClientImpl> weak_ptr_factory_; 163 base::WeakPtrFactory<PermissionBrokerClientImpl> weak_ptr_factory_;
153 164
154 DISALLOW_COPY_AND_ASSIGN(PermissionBrokerClientImpl); 165 DISALLOW_COPY_AND_ASSIGN(PermissionBrokerClientImpl);
155 }; 166 };
156 167
157 PermissionBrokerClient::PermissionBrokerClient() {} 168 PermissionBrokerClient::PermissionBrokerClient() {}
158 169
159 PermissionBrokerClient::~PermissionBrokerClient() {} 170 PermissionBrokerClient::~PermissionBrokerClient() {}
160 171
161 PermissionBrokerClient* PermissionBrokerClient::Create() { 172 PermissionBrokerClient* PermissionBrokerClient::Create() {
162 return new PermissionBrokerClientImpl(); 173 return new PermissionBrokerClientImpl();
163 } 174 }
164 175
165 } // namespace chromeos 176 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698