blob: 3e3a7e0c5a1cce6b51379273cc7f4ed1dca009da [file] [log] [blame]
Andreea Costinas942284d2020-01-28 16:28:40 +01001// Copyright 2020 The Chromium OS 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.
4#ifndef SYSTEM_PROXY_SYSTEM_PROXY_ADAPTOR_H_
5#define SYSTEM_PROXY_SYSTEM_PROXY_ADAPTOR_H_
6
7#include <memory>
Andreea Costinasc7d5ad02020-03-09 09:41:51 +01008#include <string>
Andreea Costinas942284d2020-01-28 16:28:40 +01009#include <vector>
10
Andreea Costinasc7d5ad02020-03-09 09:41:51 +010011#include <base/memory/weak_ptr.h>
Andreea Costinas942284d2020-01-28 16:28:40 +010012#include <brillo/dbus/async_event_sequencer.h>
Andreea Costinas41e06442020-03-09 09:41:51 +010013#include <gtest/gtest_prod.h> // for FRIEND_TEST
Andreea Costinasc7d5ad02020-03-09 09:41:51 +010014#include <patchpanel/proto_bindings/patchpanel_service.pb.h>
Andreea Costinas942284d2020-01-28 16:28:40 +010015
16#include "system_proxy/org.chromium.SystemProxy.h"
17
18namespace brillo {
19namespace dbus_utils {
20class DBusObject;
21}
22
23} // namespace brillo
24
25namespace system_proxy {
Andreea Costinasc7d5ad02020-03-09 09:41:51 +010026
27class SandboxedWorker;
28
Andreea Costinas942284d2020-01-28 16:28:40 +010029// Implementation of the SystemProxy D-Bus interface.
30class SystemProxyAdaptor : public org::chromium::SystemProxyAdaptor,
31 public org::chromium::SystemProxyInterface {
32 public:
33 explicit SystemProxyAdaptor(
34 std::unique_ptr<brillo::dbus_utils::DBusObject> dbus_object);
35 SystemProxyAdaptor(const SystemProxyAdaptor&) = delete;
36 SystemProxyAdaptor& operator=(const SystemProxyAdaptor&) = delete;
Andreea Costinasc7d5ad02020-03-09 09:41:51 +010037 virtual ~SystemProxyAdaptor();
Andreea Costinas942284d2020-01-28 16:28:40 +010038
39 // Registers the D-Bus object and interfaces.
40 void RegisterAsync(
41 const brillo::dbus_utils::AsyncEventSequencer::CompletionAction&
42 completion_callback);
43
44 // org::chromium::SystemProxyInterface: (see org.chromium.SystemProxy.xml).
45 std::vector<uint8_t> SetSystemTrafficCredentials(
46 const std::vector<uint8_t>& request_blob) override;
47 std::vector<uint8_t> ShutDown() override;
48
Andreea Costinasc7d5ad02020-03-09 09:41:51 +010049 protected:
50 virtual std::unique_ptr<SandboxedWorker> CreateWorker();
51
Andreea Costinas942284d2020-01-28 16:28:40 +010052 private:
Andreea Costinas41e06442020-03-09 09:41:51 +010053 friend class SystemProxyAdaptorTest;
54 FRIEND_TEST(SystemProxyAdaptorTest, SetSystemTrafficCredentials);
55 FRIEND_TEST(SystemProxyAdaptorTest, ShutDown);
56
Andreea Costinasc7d5ad02020-03-09 09:41:51 +010057 void SetCredentialsTask(SandboxedWorker* worker,
58 const std::string& username,
59 const std::string& password);
60
61 void ShutDownTask();
62
63 void StartWorker(SandboxedWorker* worker);
64
65 void ConnectNamespace(SandboxedWorker* worker);
66
67 void OnConnectNamespace(SandboxedWorker* worker,
68 const patchpanel::IPv4Subnet& ipv4_subnet);
69
70 // Worker that authenticates and forwards to a remote web proxy traffic
71 // coming form Chrome OS system services.
72 std::unique_ptr<SandboxedWorker> system_services_worker_;
73 // Worker that authenticates and forwards to a remote web proxy traffic
74 // coming form ARC++ apps.
75 std::unique_ptr<SandboxedWorker> arc_worker_;
Andreea Costinas942284d2020-01-28 16:28:40 +010076 std::unique_ptr<brillo::dbus_utils::DBusObject> dbus_object_;
Andreea Costinasc7d5ad02020-03-09 09:41:51 +010077 base::WeakPtrFactory<SystemProxyAdaptor> weak_ptr_factory_;
Andreea Costinas942284d2020-01-28 16:28:40 +010078};
79
80} // namespace system_proxy
81#endif // SYSTEM_PROXY_SYSTEM_PROXY_ADAPTOR_H_