Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: components/copresence_endpoints/public/copresence_endpoint.h

Issue 895783002: Remove the Copresence Endpoints API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #ifndef COMPONENTS_COPRESENCE_ENDPOINTS_COPRESENCE_ENDPOINT_H_
6 #define COMPONENTS_COPRESENCE_ENDPOINTS_COPRESENCE_ENDPOINT_H_
7
8 #include <string>
9
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"
18
19 namespace device {
20 class BluetoothAdapter;
21 class BluetoothSocket;
22 }
23
24 namespace copresence_endpoints {
25
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;
36
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);
49
50 virtual ~CopresenceEndpoint();
51
52 // Send's data to the remote device connected to this endpoint.
53 bool Send(const scoped_refptr<net::IOBuffer>& buffer, int buffer_size);
54
55 // This will return a string containing the data needed for a remote endpoint
56 // to connect to this endpoint.
57 std::string GetLocator();
58
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);
63
64 void OnAccept(const device::BluetoothDevice* device,
65 scoped_refptr<device::BluetoothSocket> socket);
66 void OnAcceptError(const std::string& message);
67
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_;
74
75 int endpoint_id_;
76 CreateEndpointCallback create_callback_;
77 base::Closure accept_callback_;
78 CopresenceSocket::ReceiveCallback receive_callback_;
79
80 scoped_ptr<device::BluetoothDevice::PairingDelegate> delegate_;
81
82 base::WeakPtrFactory<CopresenceEndpoint> weak_ptr_factory_;
83
84 DISALLOW_COPY_AND_ASSIGN(CopresenceEndpoint);
85 };
86
87 } // namespace copresence_endpoints
88
89 #endif // COMPONENTS_COPRESENCE_ENDPOINTS_COPRESENCE_ENDPOINT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698