1 // Copyright 2018 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. 4 5 #ifndef CHROMEOS_SERVICES_SECURE_CHANNEL_PUBLIC_CPP_CLIENT_SECURE_CHANNEL_CLIENT_H_ 6 #define CHROMEOS_SERVICES_SECURE_CHANNEL_PUBLIC_CPP_CLIENT_SECURE_CHANNEL_CLIENT_H_ 7 8 #include <string> 9 10 #include "base/callback_forward.h" 11 #include "base/macros.h" 12 #include "base/observer_list.h" 13 #include "chromeos/components/multidevice/remote_device_ref.h" 14 #include "chromeos/services/secure_channel/public/mojom/secure_channel.mojom.h" 15 16 namespace chromeos { 17 18 namespace secure_channel { 19 20 class ConnectionAttempt; 21 class NearbyConnector; 22 23 // Provides clients access to the SecureChannel API. 24 // 25 // Clients can choose to either initiate a connection to another device, or 26 // listen for an expected connection from another device. Device details are 27 // encapsulated in the RemoteDeviceRef; see the DeviceSync API for information 28 // on how to retrieve this data. 29 // 30 // Calls to initiate or listen for a connection take identical arguments: 31 // 1) |device_to_connect|: 32 // The RemoteDeviceRef which refers to the device a connection should be made 33 // to. 34 // 2) |local_device|: 35 // The RemoteDeviceRef which refers to the local device. |local_device| and 36 // |device_to_connect| must be in the same user account. 37 // 3) |feature|: 38 // A unique string identifier for your feature. If multiple clients make a 39 // a connection request between the same |device_to_connect| and 40 // |local_device| but different features, those clients will share the same 41 // underlying connection, but their messages will be routed to the correct 42 // clients based on the |feature| identifier of the message. 43 // 4) |connection_medium|: 44 // The medium (e.g., BLE) to use. 45 // 5) |connection_priority|: 46 // The priority of this connection request. Please make higher priority 47 // requests only when necessary. 48 // 49 // Calls to initiate or listen for a connection will return a ConnectionAttempt 50 // object. Please see the documentation on ConnectionAttempt to learn how to 51 // correctly use it. 52 // 53 // Note: Right now, the SecureChannel API only offers connections to other 54 // devices over BLE. In the future, more connection mediums will be offered. 55 class SecureChannelClient { 56 public: 57 virtual ~SecureChannelClient() = default; 58 59 virtual std::unique_ptr<ConnectionAttempt> InitiateConnectionToDevice( 60 multidevice::RemoteDeviceRef device_to_connect, 61 multidevice::RemoteDeviceRef local_device, 62 const std::string& feature, 63 ConnectionMedium connection_medium, 64 ConnectionPriority connection_priority) = 0; 65 virtual std::unique_ptr<ConnectionAttempt> ListenForConnectionFromDevice( 66 multidevice::RemoteDeviceRef device_to_connect, 67 multidevice::RemoteDeviceRef local_device, 68 const std::string& feature, 69 ConnectionMedium connection_medium, 70 ConnectionPriority connection_priority) = 0; 71 virtual void SetNearbyConnector(NearbyConnector* nearby_connector) = 0; 72 73 protected: 74 SecureChannelClient() = default; 75 76 private: 77 DISALLOW_COPY_AND_ASSIGN(SecureChannelClient); 78 }; 79 80 } // namespace secure_channel 81 82 } // namespace chromeos 83 84 #endif // CHROMEOS_SERVICES_SECURE_CHANNEL_PUBLIC_CPP_CLIENT_SECURE_CHANNEL_CLIENT_H_ 85