blob: ba2b51ab709ecd6e887952ffde9e546ec24ee2ae [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 Costinasc7d5ad02020-03-09 09:41:51 +010013#include <patchpanel/proto_bindings/patchpanel_service.pb.h>
Andreea Costinas942284d2020-01-28 16:28:40 +010014
15#include "system_proxy/org.chromium.SystemProxy.h"
16
17namespace brillo {
18namespace dbus_utils {
19class DBusObject;
20}
21
22} // namespace brillo
23
24namespace system_proxy {
Andreea Costinasc7d5ad02020-03-09 09:41:51 +010025
26class SandboxedWorker;
27
Andreea Costinas942284d2020-01-28 16:28:40 +010028// Implementation of the SystemProxy D-Bus interface.
29class SystemProxyAdaptor : public org::chromium::SystemProxyAdaptor,
30 public org::chromium::SystemProxyInterface {
31 public:
32 explicit SystemProxyAdaptor(
33 std::unique_ptr<brillo::dbus_utils::DBusObject> dbus_object);
34 SystemProxyAdaptor(const SystemProxyAdaptor&) = delete;
35 SystemProxyAdaptor& operator=(const SystemProxyAdaptor&) = delete;
Andreea Costinasc7d5ad02020-03-09 09:41:51 +010036 virtual ~SystemProxyAdaptor();
Andreea Costinas942284d2020-01-28 16:28:40 +010037
38 // Registers the D-Bus object and interfaces.
39 void RegisterAsync(
40 const brillo::dbus_utils::AsyncEventSequencer::CompletionAction&
41 completion_callback);
42
43 // org::chromium::SystemProxyInterface: (see org.chromium.SystemProxy.xml).
44 std::vector<uint8_t> SetSystemTrafficCredentials(
45 const std::vector<uint8_t>& request_blob) override;
46 std::vector<uint8_t> ShutDown() override;
47
Andreea Costinasc7d5ad02020-03-09 09:41:51 +010048 protected:
49 virtual std::unique_ptr<SandboxedWorker> CreateWorker();
50
Andreea Costinas942284d2020-01-28 16:28:40 +010051 private:
Andreea Costinasc7d5ad02020-03-09 09:41:51 +010052 void SetCredentialsTask(SandboxedWorker* worker,
53 const std::string& username,
54 const std::string& password);
55
56 void ShutDownTask();
57
58 void StartWorker(SandboxedWorker* worker);
59
60 void ConnectNamespace(SandboxedWorker* worker);
61
62 void OnConnectNamespace(SandboxedWorker* worker,
63 const patchpanel::IPv4Subnet& ipv4_subnet);
64
65 // Worker that authenticates and forwards to a remote web proxy traffic
66 // coming form Chrome OS system services.
67 std::unique_ptr<SandboxedWorker> system_services_worker_;
68 // Worker that authenticates and forwards to a remote web proxy traffic
69 // coming form ARC++ apps.
70 std::unique_ptr<SandboxedWorker> arc_worker_;
Andreea Costinas942284d2020-01-28 16:28:40 +010071 std::unique_ptr<brillo::dbus_utils::DBusObject> dbus_object_;
Andreea Costinasc7d5ad02020-03-09 09:41:51 +010072 base::WeakPtrFactory<SystemProxyAdaptor> weak_ptr_factory_;
Andreea Costinas942284d2020-01-28 16:28:40 +010073};
74
75} // namespace system_proxy
76#endif // SYSTEM_PROXY_SYSTEM_PROXY_ADAPTOR_H_