Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / device / bluetooth / bluetooth_profile_win.h
index a102bf5..0222bfd 100644 (file)
@@ -7,30 +7,79 @@
 
 #include <string>
 
+#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
 #include "device/bluetooth/bluetooth_profile.h"
+#include "device/bluetooth/bluetooth_uuid.h"
+#include "net/base/net_log.h"
+#include "net/socket/tcp_socket.h"
+
+namespace net {
+class IPEndPoint;
+}
 
 namespace device {
 
+class BluetoothAdapter;
+class BluetoothAdapterWin;
 class BluetoothDeviceWin;
+class BluetoothSocketThread;
+class BluetoothSocketWin;
 
 class BluetoothProfileWin : public BluetoothProfile {
  public:
+  typedef base::Callback<void(const std::string&)> ErrorCallback;
+
   // BluetoothProfile override.
   virtual void Unregister() OVERRIDE;
   virtual void SetConnectionCallback(
       const ConnectionCallback& callback) OVERRIDE;
 
-  bool Connect(const BluetoothDeviceWin* device);
+  // Called by BluetoothProfile::Register to initialize the profile object
+  // asynchronously.
+  void Init(const BluetoothUUID& uuid,
+            const device::BluetoothProfile::Options& options,
+            const ProfileCallback& callback);
+
+  void Connect(const BluetoothDeviceWin* device,
+               scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
+               scoped_refptr<BluetoothSocketThread> socket_thread,
+               net::NetLog* net_log,
+               const net::NetLog::Source& source,
+               const base::Closure& callback,
+               const ErrorCallback& error_callback);
 
  private:
   friend BluetoothProfile;
 
-  BluetoothProfileWin(const std::string& uuid, const std::string& name);
+  BluetoothProfileWin();
   virtual ~BluetoothProfileWin();
 
-  const std::string uuid_;
-  const std::string name_;
+  // Internal method run to get the adapter object during initialization.
+  void OnGetAdapter(const ProfileCallback& callback,
+                    scoped_refptr<BluetoothAdapter> adapter);
+
+  // Callbacks for |profile_socket_|'s StartService call.
+  void OnRegisterProfileSuccess(const ProfileCallback& callback);
+  void OnRegisterProfileError(const ProfileCallback& callback,
+                              const std::string& error_message);
+
+  // Callback when |profile_socket_| accepts a connection.
+  void OnNewConnection(scoped_refptr<BluetoothSocketWin> connected,
+                       const net::IPEndPoint& peer_address);
+
+  BluetoothAdapterWin* adapter() const;
+
+  BluetoothUUID uuid_;
+  std::string name_;
+  int rfcomm_channel_;
   ConnectionCallback connection_callback_;
+
+  scoped_refptr<BluetoothAdapter> adapter_;
+  scoped_refptr<BluetoothSocketWin> profile_socket_;
+  base::WeakPtrFactory<BluetoothProfileWin> weak_ptr_factory_;
+
+  DISALLOW_COPY_AND_ASSIGN(BluetoothProfileWin);
 };
 
 }  // namespace device