File: secure_channel_host_connection.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (123 lines) | stat: -rw-r--r-- 5,267 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_ASH_COMPONENTS_TETHER_SECURE_CHANNEL_HOST_CONNECTION_H_
#define CHROMEOS_ASH_COMPONENTS_TETHER_SECURE_CHANNEL_HOST_CONNECTION_H_

#include "base/uuid.h"
#include "chromeos/ash/components/tether/host_connection.h"
#include "chromeos/ash/components/tether/tether_host_fetcher.h"
#include "chromeos/ash/services/device_sync/public/cpp/device_sync_client.h"
#include "chromeos/ash/services/secure_channel/public/cpp/client/client_channel.h"
#include "chromeos/ash/services/secure_channel/public/cpp/client/connection_attempt.h"
#include "chromeos/ash/services/secure_channel/public/cpp/client/secure_channel_client.h"

namespace ash::tether {

class SecureChannelHostConnection
    : public HostConnection,
      public secure_channel::ClientChannel::Observer {
 public:
  class Factory : public HostConnection::Factory {
   public:
    Factory(raw_ptr<device_sync::DeviceSyncClient> device_sync_client,
            raw_ptr<secure_channel::SecureChannelClient> secure_channel_client,
            raw_ptr<TetherHostFetcher> tether_host_fetcher);
    ~Factory() override;
    Factory(Factory&) = delete;
    Factory& operator=(Factory&) = delete;

    // HostConnection::Factory:
    void ScanForTetherHostAndCreateConnection(
        const std::string& device_id,
        ConnectionPriority connection_priority,
        raw_ptr<HostConnection::PayloadListener> payload_listener,
        HostConnection::OnDisconnectionCallback on_disconnection,
        HostConnection::Factory::OnConnectionCreatedCallback
            on_connection_created) override;
    void Create(const TetherHost& tether_host,
                ConnectionPriority connection_priority,
                raw_ptr<HostConnection::PayloadListener> payload_listener,
                HostConnection::OnDisconnectionCallback on_disconnection,
                HostConnection::Factory::OnConnectionCreatedCallback
                    on_connection_created) override;

   private:
    class ConnectionAttemptDelegateImpl
        : public secure_channel::ConnectionAttempt::Delegate {
     public:
      using OnConnectionAttemptDelegateFinishedCallback =
          base::OnceCallback<void(
              std::unique_ptr<HostConnection> host_connection)>;

      ConnectionAttemptDelegateImpl(
          const multidevice::RemoteDeviceRef& local_device,
          const multidevice::RemoteDeviceRef& remote_device,
          secure_channel::SecureChannelClient* secure_channel_client,
          HostConnection::PayloadListener* payload_listener,
          HostConnection::OnDisconnectionCallback on_disconnection);
      ~ConnectionAttemptDelegateImpl() override;

      void Start(
          secure_channel::ConnectionPriority connection_priority,
          OnConnectionAttemptDelegateFinishedCallback on_connection_created);

     private:
      // secure_channel::ConnectionAttempt::Delegate:
      void OnConnectionAttemptFailure(
          secure_channel::mojom::ConnectionAttemptFailureReason reason)
          override;
      void OnConnection(
          std::unique_ptr<secure_channel::ClientChannel> channel) override;

      const multidevice::RemoteDeviceRef local_device_;
      const multidevice::RemoteDeviceRef remote_device_;
      raw_ptr<HostConnection::PayloadListener> payload_listener_;
      HostConnection::OnDisconnectionCallback on_disconnection_;
      std::unique_ptr<secure_channel::ConnectionAttempt> connection_attempt_;
      raw_ptr<secure_channel::SecureChannelClient> secure_channel_client_;
      OnConnectionAttemptDelegateFinishedCallback
          on_connection_attempt_delegate_finished_;
    };

    void OnConnectionAttemptFinished(
        base::Uuid connection_attempt_id,
        HostConnection::Factory::OnConnectionCreatedCallback
            on_connection_created,
        std::unique_ptr<HostConnection> host_connection);

    std::map<base::Uuid, std::unique_ptr<ConnectionAttemptDelegateImpl>>
        active_connection_attempts_;
    raw_ptr<device_sync::DeviceSyncClient> device_sync_client_;
    raw_ptr<secure_channel::SecureChannelClient> secure_channel_client_;
    raw_ptr<TetherHostFetcher> tether_host_fetcher_;

    base::WeakPtrFactory<Factory> weak_ptr_factory_{this};
  };

  ~SecureChannelHostConnection() override;
  SecureChannelHostConnection(SecureChannelHostConnection&) = delete;
  SecureChannelHostConnection& operator=(SecureChannelHostConnection&) = delete;

  // HostConnection:
  void SendMessage(std::unique_ptr<MessageWrapper> message,
                   OnMessageSentCallback on_message_sent_callback) override;

 protected:
  // secure_channel::ClientChannel::Observer:
  void OnMessageReceived(const std::string& message) override;
  void OnDisconnected() override;

 private:
  SecureChannelHostConnection(
      raw_ptr<HostConnection::PayloadListener> listener,
      HostConnection::OnDisconnectionCallback on_disconnection,
      std::unique_ptr<secure_channel::ClientChannel> client_channel);

  std::unique_ptr<secure_channel::ClientChannel> client_channel_;
};

}  // namespace ash::tether

#endif  // CHROMEOS_ASH_COMPONENTS_TETHER_SECURE_CHANNEL_HOST_CONNECTION_H_