Add some instrumentation for jank in URLRequest::Start.
[chromium-blink-merge.git] / chromeos / network / firewall_hole.h
blob2bd678813210ee0f142e2c1e90590b903a3132a6
1 // Copyright 2015 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.
5 #ifndef CHROMEOS_NETWORK_FIREWALL_HOLE_H_
6 #define CHROMEOS_NETWORK_FIREWALL_HOLE_H_
8 #include <stdint.h>
9 #include <string>
11 #include "base/callback_forward.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "chromeos/chromeos_export.h"
15 namespace dbus {
16 class FileDescriptor;
19 namespace chromeos {
21 // This class works with the Chrome OS permission broker to open a port in the
22 // system firewall. It is closed on destruction.
23 class CHROMEOS_EXPORT FirewallHole {
24 public:
25 enum class PortType {
26 UDP,
27 TCP,
30 typedef base::Callback<void(scoped_ptr<FirewallHole>)> OpenCallback;
32 // This provides a simple way to pass around file descriptors since they must
33 // be closed on a thread that is allowed to perform I/O.
34 struct FileDescriptorDeleter {
35 void CHROMEOS_EXPORT operator()(dbus::FileDescriptor* fd);
37 typedef scoped_ptr<dbus::FileDescriptor, FileDescriptorDeleter>
38 ScopedFileDescriptor;
40 // Opens a port on the system firewall for the given network interface (or all
41 // interfaces if |interface| is ""). The hole will be closed when the object
42 // provided to the callback is destroyed.
43 static void Open(PortType type,
44 uint16_t port,
45 const std::string& interface,
46 const OpenCallback& callback);
48 ~FirewallHole();
50 private:
51 static void RequestPortAccess(PortType type,
52 uint16_t port,
53 const std::string& interface,
54 ScopedFileDescriptor lifeline_local,
55 ScopedFileDescriptor lifeline_remote,
56 const OpenCallback& callback);
58 static void PortAccessGranted(PortType type,
59 uint16_t port,
60 const std::string& interface,
61 ScopedFileDescriptor lifeline_fd,
62 const FirewallHole::OpenCallback& callback,
63 bool success);
65 FirewallHole(PortType type,
66 uint16_t port,
67 const std::string& interface,
68 ScopedFileDescriptor lifeline_fd);
70 const PortType type_;
71 const uint16_t port_;
72 const std::string interface_;
74 // A file descriptor used by firewalld to track the lifetime of this process.
75 ScopedFileDescriptor lifeline_fd_;
78 } // namespace chromeos
80 #endif // CHROMEOS_NETWORK_FIREWALL_HOLE_H_