Delete chrome.mediaGalleriesPrivate because the functionality unique to it has since...
[chromium-blink-merge.git] / components / copresence_endpoints / public / copresence_endpoint.h
blobc0b7bc5552d649871e12845b6451f21d5007d29e
1 // Copyright 2014 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 COMPONENTS_COPRESENCE_ENDPOINTS_COPRESENCE_ENDPOINT_H_
6 #define COMPONENTS_COPRESENCE_ENDPOINTS_COPRESENCE_ENDPOINT_H_
8 #include <string>
10 #include "base/callback.h"
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "components/copresence_endpoints/copresence_socket.h"
16 #include "device/bluetooth/bluetooth_device.h"
17 #include "device/bluetooth/bluetooth_uuid.h"
19 namespace device {
20 class BluetoothAdapter;
21 class BluetoothSocket;
24 namespace copresence_endpoints {
26 // A CopresenceEndpoint is an object that can be used for communication with
27 // remote endpoints. Creating this object will create a server that will listen
28 // on Bluetooth (currently) and accept connections. Once a connection is
29 // accepted, the endpoint continuously listens for data on the accepted
30 // connection(s).
31 class CopresenceEndpoint {
32 public:
33 // Callback with the locator data for the created peer. On a failed create,
34 // the locator string will be empty.
35 typedef base::Callback<void(const std::string&)> CreateEndpointCallback;
37 // Create a CopresenceEndpoint and start listening for connections. Once the
38 // endpoint object is created, the locator data for the object is returned via
39 // create_callback. This locator data can be used to connect to this peer by
40 // a remote endpoint.
41 // endpoint_id is the id that this endpoint will use to identify itself.
42 // create_callback is called when the endpoint creation is complete.
43 // accept_callback is called when we receive an incoming connection.
44 // receive_callback is called when we receive data on this endpoint.
45 CopresenceEndpoint(int endpoint_id,
46 const CreateEndpointCallback& create_callback,
47 const base::Closure& accept_callback,
48 const CopresenceSocket::ReceiveCallback& receive_callback);
50 virtual ~CopresenceEndpoint();
52 // Send's data to the remote device connected to this endpoint.
53 bool Send(const scoped_refptr<net::IOBuffer>& buffer, int buffer_size);
55 // This will return a string containing the data needed for a remote endpoint
56 // to connect to this endpoint.
57 std::string GetLocator();
59 private:
60 void OnGetAdapter(scoped_refptr<device::BluetoothAdapter> adapter);
61 void OnCreateService(scoped_refptr<device::BluetoothSocket> socket);
62 void OnCreateServiceError(const std::string& message);
64 void OnAccept(const device::BluetoothDevice* device,
65 scoped_refptr<device::BluetoothSocket> socket);
66 void OnAcceptError(const std::string& message);
68 scoped_refptr<device::BluetoothAdapter> adapter_;
69 scoped_refptr<device::BluetoothSocket> server_socket_;
70 // TODO(rkc): Eventually an endpoint will be able to accept multiple
71 // connections. Whenever the API supports one-to-many connections, fix this
72 // code to do so too.
73 scoped_ptr<CopresenceSocket> client_socket_;
75 int endpoint_id_;
76 CreateEndpointCallback create_callback_;
77 base::Closure accept_callback_;
78 CopresenceSocket::ReceiveCallback receive_callback_;
80 scoped_ptr<device::BluetoothDevice::PairingDelegate> delegate_;
82 base::WeakPtrFactory<CopresenceEndpoint> weak_ptr_factory_;
84 DISALLOW_COPY_AND_ASSIGN(CopresenceEndpoint);
87 } // namespace copresence_endpoints
89 #endif // COMPONENTS_COPRESENCE_ENDPOINTS_COPRESENCE_ENDPOINT_H_