summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/api/bluetooth
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/extensions/api/bluetooth')
-rw-r--r--chrome/browser/extensions/api/bluetooth/bluetooth_api.cc9
-rw-r--r--chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc54
-rw-r--r--chrome/browser/extensions/api/bluetooth/bluetooth_event_router.cc22
3 files changed, 38 insertions, 47 deletions
diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc
index 6d4170a..11c91f5 100644
--- a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc
+++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc
@@ -247,7 +247,7 @@ bool BluetoothGetProfilesFunction::DoWork(
bool BluetoothGetAdapterStateFunction::DoWork(
scoped_refptr<BluetoothAdapter> adapter) {
bluetooth::AdapterState state;
- PopulateAdapterState(*adapter, &state);
+ PopulateAdapterState(*adapter.get(), &state);
SetResult(state.ToValue().release());
SendResponse(true);
return true;
@@ -447,7 +447,7 @@ void BluetoothReadFunction::Work() {
return;
scoped_refptr<net::GrowableIOBuffer> buffer(new net::GrowableIOBuffer);
- success_ = socket_->Receive(buffer);
+ success_ = socket_->Receive(buffer.get());
if (success_)
SetResult(base::BinaryValue::CreateWithCopiedBuffer(buffer->StartOfBuffer(),
buffer->offset()));
@@ -501,8 +501,9 @@ void BluetoothWriteFunction::Work() {
scoped_refptr<net::WrappedIOBuffer> wrapped_io_buffer(
new net::WrappedIOBuffer(data_to_write_->GetBuffer()));
scoped_refptr<net::DrainableIOBuffer> drainable_io_buffer(
- new net::DrainableIOBuffer(wrapped_io_buffer, data_to_write_->GetSize()));
- success_ = socket_->Send(drainable_io_buffer);
+ new net::DrainableIOBuffer(wrapped_io_buffer.get(),
+ data_to_write_->GetSize()));
+ success_ = socket_->Send(drainable_io_buffer.get());
if (success_) {
if (drainable_io_buffer->BytesConsumed() > 0)
SetResult(
diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc
index a840e14..f000d5e 100644
--- a/chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc
+++ b/chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc
@@ -168,54 +168,41 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Profiles) {
scoped_refptr<TestBluetoothAddProfileFunction> add_profile_function;
add_profile_function = setupFunction(
new TestBluetoothAddProfileFunction(profile1_.get()));
- std::string error(
- utils::RunFunctionAndReturnError(
- add_profile_function,
- "[{\"uuid\": \"1234\"}]",
- browser()));
+ std::string error(utils::RunFunctionAndReturnError(
+ add_profile_function.get(), "[{\"uuid\": \"1234\"}]", browser()));
ASSERT_TRUE(error.empty());
// Registering the profile for the same uuid again will throw an error.
add_profile_function = setupFunction(
new TestBluetoothAddProfileFunction(profile2_.get()));
error = utils::RunFunctionAndReturnError(
- add_profile_function,
- "[{\"uuid\": \"1234\"}]",
- browser());
+ add_profile_function.get(), "[{\"uuid\": \"1234\"}]", browser());
ASSERT_FALSE(error.empty());
add_profile_function = setupFunction(
new TestBluetoothAddProfileFunction(profile2_.get()));
error = utils::RunFunctionAndReturnError(
- add_profile_function,
- "[{\"uuid\": \"5678\"}]",
- browser());
+ add_profile_function.get(), "[{\"uuid\": \"5678\"}]", browser());
ASSERT_TRUE(error.empty());
scoped_refptr<api::BluetoothRemoveProfileFunction> remove_profile_function;
remove_profile_function = setupFunction(
new api::BluetoothRemoveProfileFunction());
error = utils::RunFunctionAndReturnError(
- remove_profile_function,
- "[{\"uuid\": \"1234\"}]",
- browser());
+ remove_profile_function.get(), "[{\"uuid\": \"1234\"}]", browser());
ASSERT_TRUE(error.empty());
remove_profile_function = setupFunction(
new api::BluetoothRemoveProfileFunction());
error = utils::RunFunctionAndReturnError(
- remove_profile_function,
- "[{\"uuid\": \"5678\"}]",
- browser());
+ remove_profile_function.get(), "[{\"uuid\": \"5678\"}]", browser());
ASSERT_TRUE(error.empty());
// Removing the same profile again will throw an error.
remove_profile_function = setupFunction(
new api::BluetoothRemoveProfileFunction());
error = utils::RunFunctionAndReturnError(
- remove_profile_function,
- "[{\"uuid\": \"5678\"}]",
- browser());
+ remove_profile_function.get(), "[{\"uuid\": \"5678\"}]", browser());
ASSERT_FALSE(error.empty());
}
@@ -235,7 +222,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetAdapterState) {
get_adapter_state = setupFunction(new api::BluetoothGetAdapterStateFunction);
scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
- get_adapter_state, "[]", browser()));
+ get_adapter_state.get(), "[]", browser()));
ASSERT_TRUE(result.get() != NULL);
api::bluetooth::AdapterState state;
ASSERT_TRUE(api::bluetooth::AdapterState::Populate(*result, &state));
@@ -257,7 +244,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetLocalOutOfBandPairingData) {
new api::BluetoothGetLocalOutOfBandPairingDataFunction));
scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
- get_oob_function, "[]", browser()));
+ get_oob_function.get(), "[]", browser()));
base::DictionaryValue* dict;
EXPECT_TRUE(result->GetAsDictionary(&dict));
@@ -280,8 +267,8 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetLocalOutOfBandPairingData) {
get_oob_function =
setupFunction(new api::BluetoothGetLocalOutOfBandPairingDataFunction);
- std::string error(
- utils::RunFunctionAndReturnError(get_oob_function, "[]", browser()));
+ std::string error(utils::RunFunctionAndReturnError(
+ get_oob_function.get(), "[]", browser()));
EXPECT_FALSE(error.empty());
}
@@ -299,8 +286,8 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, SetOutOfBandPairingData) {
set_oob_function = setupFunction(
new api::BluetoothSetOutOfBandPairingDataFunction);
// There isn't actually a result.
- (void)utils::RunFunctionAndReturnSingleResult(
- set_oob_function, params, browser());
+ (void) utils::RunFunctionAndReturnSingleResult(
+ set_oob_function.get(), params, browser());
// Try again with an error
testing::Mock::VerifyAndClearExpectations(mock_adapter_);
@@ -313,8 +300,8 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, SetOutOfBandPairingData) {
set_oob_function = setupFunction(
new api::BluetoothSetOutOfBandPairingDataFunction);
- std::string error(
- utils::RunFunctionAndReturnError(set_oob_function, params, browser()));
+ std::string error(utils::RunFunctionAndReturnError(
+ set_oob_function.get(), params, browser()));
EXPECT_FALSE(error.empty());
// TODO(bryeung): Also test setting the data when there is support for
@@ -331,7 +318,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Discovery) {
scoped_refptr<api::BluetoothStartDiscoveryFunction> start_function;
start_function = setupFunction(new api::BluetoothStartDiscoveryFunction);
std::string error(
- utils::RunFunctionAndReturnError(start_function, "[]", browser()));
+ utils::RunFunctionAndReturnError(start_function.get(), "[]", browser()));
ASSERT_FALSE(error.empty());
// Reset for a successful start
@@ -340,7 +327,8 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Discovery) {
.WillOnce(testing::Invoke(CallDiscoveryCallback));
start_function = setupFunction(new api::BluetoothStartDiscoveryFunction);
- (void)utils::RunFunctionAndReturnError(start_function, "[]", browser());
+ (void)
+ utils::RunFunctionAndReturnError(start_function.get(), "[]", browser());
// Reset to try stopping
testing::Mock::VerifyAndClearExpectations(mock_adapter_);
@@ -350,7 +338,8 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Discovery) {
EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_));
scoped_refptr<api::BluetoothStopDiscoveryFunction> stop_function;
stop_function = setupFunction(new api::BluetoothStopDiscoveryFunction);
- (void)utils::RunFunctionAndReturnSingleResult(stop_function, "[]", browser());
+ (void) utils::RunFunctionAndReturnSingleResult(
+ stop_function.get(), "[]", browser());
// Reset to try stopping with an error
SetUpMockAdapter();
@@ -358,7 +347,8 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Discovery) {
.WillOnce(testing::Invoke(CallDiscoveryErrorCallback));
EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_));
stop_function = setupFunction(new api::BluetoothStopDiscoveryFunction);
- error = utils::RunFunctionAndReturnError(stop_function, "[]", browser());
+ error =
+ utils::RunFunctionAndReturnError(stop_function.get(), "[]", browser());
ASSERT_FALSE(error.empty());
SetUpMockAdapter();
}
diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.cc
index 17f31d7..3a4c2e6 100644
--- a/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.cc
+++ b/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.cc
@@ -37,7 +37,7 @@ ExtensionBluetoothEventRouter::ExtensionBluetoothEventRouter(Profile* profile)
}
ExtensionBluetoothEventRouter::~ExtensionBluetoothEventRouter() {
- if (adapter_) {
+ if (adapter_.get()) {
adapter_->RemoveObserver(this);
adapter_ = NULL;
}
@@ -53,13 +53,13 @@ ExtensionBluetoothEventRouter::~ExtensionBluetoothEventRouter() {
}
bool ExtensionBluetoothEventRouter::IsBluetoothSupported() const {
- return adapter_ ||
+ return adapter_.get() ||
device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable();
}
void ExtensionBluetoothEventRouter::GetAdapter(
const device::BluetoothAdapterFactory::AdapterCallback& callback) {
- if (adapter_) {
+ if (adapter_.get()) {
callback.Run(scoped_refptr<device::BluetoothAdapter>(adapter_));
return;
}
@@ -191,7 +191,7 @@ void ExtensionBluetoothEventRouter::DispatchConnectionEvent(
void ExtensionBluetoothEventRouter::AdapterPresentChanged(
device::BluetoothAdapter* adapter, bool present) {
- if (adapter != adapter_) {
+ if (adapter != adapter_.get()) {
DVLOG(1) << "Ignoring event for adapter " << adapter->GetAddress();
return;
}
@@ -200,7 +200,7 @@ void ExtensionBluetoothEventRouter::AdapterPresentChanged(
void ExtensionBluetoothEventRouter::AdapterPoweredChanged(
device::BluetoothAdapter* adapter, bool has_power) {
- if (adapter != adapter_) {
+ if (adapter != adapter_.get()) {
DVLOG(1) << "Ignoring event for adapter " << adapter->GetAddress();
return;
}
@@ -209,7 +209,7 @@ void ExtensionBluetoothEventRouter::AdapterPoweredChanged(
void ExtensionBluetoothEventRouter::AdapterDiscoveringChanged(
device::BluetoothAdapter* adapter, bool discovering) {
- if (adapter != adapter_) {
+ if (adapter != adapter_.get()) {
DVLOG(1) << "Ignoring event for adapter " << adapter->GetAddress();
return;
}
@@ -226,7 +226,7 @@ void ExtensionBluetoothEventRouter::AdapterDiscoveringChanged(
void ExtensionBluetoothEventRouter::DeviceAdded(
device::BluetoothAdapter* adapter,
device::BluetoothDevice* device) {
- if (adapter != adapter_) {
+ if (adapter != adapter_.get()) {
DVLOG(1) << "Ignoring event for adapter " << adapter->GetAddress();
return;
}
@@ -245,7 +245,7 @@ void ExtensionBluetoothEventRouter::DeviceAdded(
}
void ExtensionBluetoothEventRouter::InitializeAdapterIfNeeded() {
- if (!adapter_) {
+ if (!adapter_.get()) {
GetAdapter(base::Bind(&ExtensionBluetoothEventRouter::InitializeAdapter,
weak_ptr_factory_.GetWeakPtr()));
}
@@ -253,14 +253,14 @@ void ExtensionBluetoothEventRouter::InitializeAdapterIfNeeded() {
void ExtensionBluetoothEventRouter::InitializeAdapter(
scoped_refptr<device::BluetoothAdapter> adapter) {
- if (!adapter_) {
+ if (!adapter_.get()) {
adapter_ = adapter;
adapter_->AddObserver(this);
}
}
void ExtensionBluetoothEventRouter::MaybeReleaseAdapter() {
- if (adapter_ && num_event_listeners_ == 0) {
+ if (adapter_.get() && num_event_listeners_ == 0) {
adapter_->RemoveObserver(this);
adapter_ = NULL;
}
@@ -268,7 +268,7 @@ void ExtensionBluetoothEventRouter::MaybeReleaseAdapter() {
void ExtensionBluetoothEventRouter::DispatchAdapterStateEvent() {
api::bluetooth::AdapterState state;
- PopulateAdapterState(*adapter_, &state);
+ PopulateAdapterState(*adapter_.get(), &state);
scoped_ptr<ListValue> args(new ListValue());
args->Append(state.ToValue().release());