diff options
author | youngki@chromium.org <youngki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-01 23:32:42 +0000 |
---|---|---|
committer | youngki@chromium.org <youngki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-01 23:32:42 +0000 |
commit | ec00099f34a3df350e87c81e8840ca15ee7a19dc (patch) | |
tree | 7d55f522ce91cb4fe099db7def58d1987f7a7b1e /device | |
parent | af8fae78c93952c5bf1cfde0fc138ef245092add (diff) | |
download | chromium_src-ec00099f34a3df350e87c81e8840ca15ee7a19dc.zip chromium_src-ec00099f34a3df350e87c81e8840ca15ee7a19dc.tar.gz chromium_src-ec00099f34a3df350e87c81e8840ca15ee7a19dc.tar.bz2 |
Relanding addProfile/removeProfile patch with heapchecker fix.
This is a relanding of r197554 with heapchecker fix.
Some profile-dependent services depend on UI thread to clean up, so I had to add
UI message loop in bluetooth_event_router_unittest.cc to make sure that all the
objects are released at the end of test.
I verified with valgrind that this patch does not introduce any new memory leak.
BUG=229636
Review URL: https://chromiumcodereview.appspot.com/14569007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@197741 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'device')
-rw-r--r-- | device/bluetooth/bluetooth_profile.h | 9 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_profile_mac.h | 5 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_profile_mac.mm | 7 | ||||
-rw-r--r-- | device/bluetooth/test/mock_bluetooth_profile.cc | 15 | ||||
-rw-r--r-- | device/bluetooth/test/mock_bluetooth_profile.h | 25 | ||||
-rw-r--r-- | device/device.gyp | 2 |
6 files changed, 56 insertions, 7 deletions
diff --git a/device/bluetooth/bluetooth_profile.h b/device/bluetooth/bluetooth_profile.h index 466bdf2..46200b3 100644 --- a/device/bluetooth/bluetooth_profile.h +++ b/device/bluetooth/bluetooth_profile.h @@ -12,8 +12,10 @@ namespace device { +class BluetoothDevice; class BluetoothProfileMac; class BluetoothSocket; +class MockBluetoothProfile; // BluetoothProfile represents an implementation of either a client or server // of a particular specified profile (aka service or protocol in other @@ -92,11 +94,14 @@ class BluetoothProfile { // The socket will be closed when all references are released; none of the // BluetoothProfile, or BluetoothAdapter or BluetoothDevice objects are // guaranteed to hold a reference so this may outlive all of them. - typedef base::Callback<void(scoped_refptr<BluetoothSocket>)> SocketCallback; - virtual void SetConnectionCallback(const SocketCallback& callback) = 0; + typedef base::Callback<void( + const BluetoothDevice*, + scoped_refptr<BluetoothSocket>)> ConnectionCallback; + virtual void SetConnectionCallback(const ConnectionCallback& callback) = 0; private: friend class BluetoothProfileMac; + friend class MockBluetoothProfile; BluetoothProfile(); virtual ~BluetoothProfile(); diff --git a/device/bluetooth/bluetooth_profile_mac.h b/device/bluetooth/bluetooth_profile_mac.h index 34b6b34..0085efd 100644 --- a/device/bluetooth/bluetooth_profile_mac.h +++ b/device/bluetooth/bluetooth_profile_mac.h @@ -23,7 +23,8 @@ class BluetoothProfileMac : public BluetoothProfile { public: // BluetoothProfile override. virtual void Unregister() OVERRIDE; - virtual void SetConnectionCallback(const SocketCallback& callback) OVERRIDE; + virtual void SetConnectionCallback( + const ConnectionCallback& callback) OVERRIDE; // Makes an outgoing connection to |device|. // This method runs |socket_callback_| with the socket and returns true if the @@ -38,7 +39,7 @@ class BluetoothProfileMac : public BluetoothProfile { const std::string uuid_; const std::string name_; - SocketCallback socket_callback_; + ConnectionCallback connection_callback_; }; } // namespace device diff --git a/device/bluetooth/bluetooth_profile_mac.mm b/device/bluetooth/bluetooth_profile_mac.mm index ca50f06..c0658a9 100644 --- a/device/bluetooth/bluetooth_profile_mac.mm +++ b/device/bluetooth/bluetooth_profile_mac.mm @@ -59,8 +59,8 @@ void BluetoothProfileMac::Unregister() { } void BluetoothProfileMac::SetConnectionCallback( - const SocketCallback& callback) { - socket_callback_ = callback; + const ConnectionCallback& callback) { + connection_callback_ = callback; } bool BluetoothProfileMac::Connect(IOBluetoothDevice* device) { @@ -70,7 +70,8 @@ bool BluetoothProfileMac::Connect(IOBluetoothDevice* device) { scoped_refptr<BluetoothSocket> socket( BluetoothSocketMac::CreateBluetoothSocket(record)); if (socket.get() != NULL) { - socket_callback_.Run(socket); + BluetoothDeviceMac device_mac(device); + connection_callback_.Run(&device_mac, socket); return true; } } diff --git a/device/bluetooth/test/mock_bluetooth_profile.cc b/device/bluetooth/test/mock_bluetooth_profile.cc new file mode 100644 index 0000000..bf2af21 --- /dev/null +++ b/device/bluetooth/test/mock_bluetooth_profile.cc @@ -0,0 +1,15 @@ +// 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/test/mock_bluetooth_profile.h" + +namespace device { + +MockBluetoothProfile::MockBluetoothProfile() { +} + +MockBluetoothProfile::~MockBluetoothProfile() { +} + +} // namespace device diff --git a/device/bluetooth/test/mock_bluetooth_profile.h b/device/bluetooth/test/mock_bluetooth_profile.h new file mode 100644 index 0000000..92b7505 --- /dev/null +++ b/device/bluetooth/test/mock_bluetooth_profile.h @@ -0,0 +1,25 @@ +// 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. + +#ifndef DEVICE_BLUETOOTH_TEST_MOCK_BLUETOOTH_PROFILE_H_ +#define DEVICE_BLUETOOTH_TEST_MOCK_BLUETOOTH_PROFILE_H_ + +#include "device/bluetooth/bluetooth_profile.h" +#include "testing/gmock/include/gmock/gmock.h" + +namespace device { + +class MockBluetoothProfile : public BluetoothProfile { + public: + MockBluetoothProfile(); + virtual ~MockBluetoothProfile(); + + MOCK_METHOD0(Unregister, void()); + MOCK_METHOD1(SetConnectionCallback, + void(const BluetoothProfile::ConnectionCallback&)); +}; + +} // namespace device + +#endif // DEVICE_BLUETOOTH_TEST_MOCK_BLUETOOTH_PROFILE_H_ diff --git a/device/device.gyp b/device/device.gyp index 3f3d010..6afb8a0 100644 --- a/device/device.gyp +++ b/device/device.gyp @@ -110,6 +110,8 @@ 'bluetooth/test/mock_bluetooth_adapter.h', 'bluetooth/test/mock_bluetooth_device.cc', 'bluetooth/test/mock_bluetooth_device.h', + 'bluetooth/test/mock_bluetooth_profile.cc', + 'bluetooth/test/mock_bluetooth_profile.h', 'bluetooth/test/mock_bluetooth_socket.cc', 'bluetooth/test/mock_bluetooth_socket.h', ], |