summaryrefslogtreecommitdiffstats
path: root/device/bluetooth/bluetooth_profile_win.cc
blob: f0729bb4fb7877c3cbefe4d7d99f341fdaadc033 (plain)
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
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "device/bluetooth/bluetooth_profile_win.h"

#include "base/memory/ref_counted.h"
#include "device/bluetooth/bluetooth_device_win.h"
#include "device/bluetooth/bluetooth_service_record.h"
#include "device/bluetooth/bluetooth_socket_win.h"

namespace device {

BluetoothProfileWin::BluetoothProfileWin(const std::string& uuid,
                                         const std::string& name)
    : BluetoothProfile(), uuid_(uuid), name_(name) {
}

BluetoothProfileWin::~BluetoothProfileWin() {
}

void BluetoothProfileWin::Unregister() {
  delete this;
}

void BluetoothProfileWin::SetConnectionCallback(
    const ConnectionCallback& callback) {
  connection_callback_ = callback;
}

bool BluetoothProfileWin::Connect(const BluetoothDeviceWin* device) {
  if (connection_callback_.is_null())
    return false;

  const BluetoothServiceRecord* record = device->GetServiceRecord(uuid_);
  if (record) {
    scoped_refptr<BluetoothSocket> socket(
        BluetoothSocketWin::CreateBluetoothSocket(*record));
    if (socket.get() != NULL) {
      connection_callback_.Run(device, socket);
      return true;
    }
  }
  return false;
}

}  // namespace device