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

Unified Diff: chromeos/network/firewall_hole.cc

Issue 2291983002: chromeos: Remove dbus::FileDescriptor from PermissionBrokerClient (Closed)
Patch Set: Address comments Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromeos/network/firewall_hole.h ('k') | device/hid/hid_service_linux.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/network/firewall_hole.cc
diff --git a/chromeos/network/firewall_hole.cc b/chromeos/network/firewall_hole.cc
index 5dec89d15a7c9d5bf861f49cd89051c287bf53f5..1f43eb77dfde36cd9f19c49662b04e37d9b411b2 100644
--- a/chromeos/network/firewall_hole.cc
+++ b/chromeos/network/firewall_hole.cc
@@ -13,33 +13,15 @@
#include "base/bind.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
+#include "base/threading/thread_task_runner_handle.h"
#include "base/threading/worker_pool.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/permission_broker_client.h"
-#include "dbus/file_descriptor.h"
namespace chromeos {
namespace {
-// Creates a pair of file descriptors that form a "lifeline" between Chrome and
-// firewalld. If this pipe is closed unexpectedly (i.e. Chrome crashes) then
-// firewalld will notice and close the hole in the firewall.
-void CreateValidLifeline(dbus::FileDescriptor* lifeline_local,
- dbus::FileDescriptor* lifeline_remote) {
- int lifeline[2] = {-1, -1};
- if (pipe2(lifeline, O_CLOEXEC) < 0) {
- PLOG(ERROR) << "Failed to create a lifeline pipe";
- return;
- }
-
- lifeline_local->PutValue(lifeline[0]);
- lifeline_local->CheckValidity();
-
- lifeline_remote->PutValue(lifeline[1]);
- lifeline_remote->CheckValidity();
-}
-
const char* PortTypeToString(FirewallHole::PortType type) {
switch (type) {
case FirewallHole::PortType::TCP:
@@ -54,7 +36,7 @@ const char* PortTypeToString(FirewallHole::PortType type) {
void PortReleased(FirewallHole::PortType type,
uint16_t port,
const std::string& interface,
- dbus::ScopedFileDescriptor lifeline_fd,
+ base::ScopedFD lifeline_fd,
bool success) {
if (!success) {
LOG(WARNING) << "Failed to release firewall hole for "
@@ -70,66 +52,49 @@ void FirewallHole::Open(PortType type,
uint16_t port,
const std::string& interface,
const OpenCallback& callback) {
- dbus::ScopedFileDescriptor lifeline_local(new dbus::FileDescriptor());
- dbus::ScopedFileDescriptor lifeline_remote(new dbus::FileDescriptor());
-
- // This closure shares pointers with the one below. PostTaskAndReply
- // guarantees that it will always be deleted first.
- base::Closure create_lifeline_closure = base::Bind(
- &CreateValidLifeline, lifeline_local.get(), lifeline_remote.get());
-
- base::WorkerPool::PostTaskAndReply(
- FROM_HERE, create_lifeline_closure,
- base::Bind(&FirewallHole::RequestPortAccess, type, port, interface,
- base::Passed(&lifeline_local), base::Passed(&lifeline_remote),
- callback),
- false);
-}
+ int lifeline[2] = {-1, -1};
+ if (pipe2(lifeline, O_CLOEXEC) < 0) {
+ PLOG(ERROR) << "Failed to create a lifeline pipe";
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(callback, nullptr));
+ return;
+ }
+ base::ScopedFD lifeline_local(lifeline[0]);
+ base::ScopedFD lifeline_remote(lifeline[1]);
-FirewallHole::~FirewallHole() {
- base::Callback<void(bool)> port_released_closure = base::Bind(
- &PortReleased, type_, port_, interface_, base::Passed(&lifeline_fd_));
+ base::Callback<void(bool)> access_granted_closure =
+ base::Bind(&FirewallHole::PortAccessGranted, type, port, interface,
+ base::Passed(&lifeline_local), callback);
PermissionBrokerClient* client =
DBusThreadManager::Get()->GetPermissionBrokerClient();
DCHECK(client) << "Could not get permission broker client.";
- switch (type_) {
+
+ switch (type) {
case PortType::TCP:
- client->ReleaseTcpPort(port_, interface_, port_released_closure);
+ client->RequestTcpPortAccess(port, interface, lifeline_remote.get(),
+ access_granted_closure);
return;
case PortType::UDP:
- client->ReleaseUdpPort(port_, interface_, port_released_closure);
+ client->RequestUdpPortAccess(port, interface, lifeline_remote.get(),
+ access_granted_closure);
return;
}
}
-void FirewallHole::RequestPortAccess(PortType type,
- uint16_t port,
- const std::string& interface,
- dbus::ScopedFileDescriptor lifeline_local,
- dbus::ScopedFileDescriptor lifeline_remote,
- const OpenCallback& callback) {
- if (!lifeline_local->is_valid() || !lifeline_remote->is_valid()) {
- callback.Run(nullptr);
- return;
- }
-
- base::Callback<void(bool)> access_granted_closure =
- base::Bind(&FirewallHole::PortAccessGranted, type, port, interface,
- base::Passed(&lifeline_local), callback);
+FirewallHole::~FirewallHole() {
+ base::Callback<void(bool)> port_released_closure = base::Bind(
+ &PortReleased, type_, port_, interface_, base::Passed(&lifeline_fd_));
PermissionBrokerClient* client =
DBusThreadManager::Get()->GetPermissionBrokerClient();
DCHECK(client) << "Could not get permission broker client.";
-
- switch (type) {
+ switch (type_) {
case PortType::TCP:
- client->RequestTcpPortAccess(port, interface, *lifeline_remote,
- access_granted_closure);
+ client->ReleaseTcpPort(port_, interface_, port_released_closure);
return;
case PortType::UDP:
- client->RequestUdpPortAccess(port, interface, *lifeline_remote,
- access_granted_closure);
+ client->ReleaseUdpPort(port_, interface_, port_released_closure);
return;
}
}
@@ -137,7 +102,7 @@ void FirewallHole::RequestPortAccess(PortType type,
void FirewallHole::PortAccessGranted(PortType type,
uint16_t port,
const std::string& interface,
- dbus::ScopedFileDescriptor lifeline_fd,
+ base::ScopedFD lifeline_fd,
const FirewallHole::OpenCallback& callback,
bool success) {
if (success) {
@@ -151,7 +116,7 @@ void FirewallHole::PortAccessGranted(PortType type,
FirewallHole::FirewallHole(PortType type,
uint16_t port,
const std::string& interface,
- dbus::ScopedFileDescriptor lifeline_fd)
+ base::ScopedFD lifeline_fd)
: type_(type),
port_(port),
interface_(interface),
« no previous file with comments | « chromeos/network/firewall_hole.h ('k') | device/hid/hid_service_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698