Bug 929376 - Part 2: Move 'IsConnected' from BluetoothManager to BluetoothAdapter and allow it to be used on content process. r=shawnjohnjr

This commit is contained in:
Jamin Liu 2014-08-26 18:50:35 +08:00
Родитель 48d1b8f345
Коммит 20138f94c9
14 изменённых файлов: 104 добавлений и 49 удалений

Просмотреть файл

@ -123,10 +123,10 @@ private:
nsRefPtr<BluetoothAdapter> mAdapterPtr;
};
class GetScoConnectionStatusTask : public BluetoothReplyRunnable
class GetConnectionStatusTask : public BluetoothReplyRunnable
{
public:
GetScoConnectionStatusTask(nsIDOMDOMRequest* aReq) :
GetConnectionStatusTask(nsIDOMDOMRequest* aReq) :
BluetoothReplyRunnable(aReq)
{
MOZ_ASSERT(aReq);
@ -683,7 +683,7 @@ BluetoothAdapter::SetPairingConfirmation(const nsAString& aDeviceAddress,
already_AddRefed<DOMRequest>
BluetoothAdapter::Connect(BluetoothDevice& aDevice,
const Optional<short unsigned int>& aServiceUuid,
const Optional<uint16_t>& aServiceUuid,
ErrorResult& aRv)
{
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
@ -716,7 +716,7 @@ BluetoothAdapter::Connect(BluetoothDevice& aDevice,
already_AddRefed<DOMRequest>
BluetoothAdapter::Disconnect(BluetoothDevice& aDevice,
const Optional<short unsigned int>& aServiceUuid,
const Optional<uint16_t>& aServiceUuid,
ErrorResult& aRv)
{
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
@ -746,6 +746,29 @@ BluetoothAdapter::Disconnect(BluetoothDevice& aDevice,
return request.forget();
}
already_AddRefed<DOMRequest>
BluetoothAdapter::IsConnected(const uint16_t aServiceUuid, ErrorResult& aRv)
{
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
if (!win) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsRefPtr<DOMRequest> request = new DOMRequest(win);
nsRefPtr<BluetoothReplyRunnable> results =
new GetConnectionStatusTask(request);
BluetoothService* bs = BluetoothService::Get();
if (!bs) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
bs->IsConnected(aServiceUuid, results);
return request.forget();
}
already_AddRefed<DOMRequest>
BluetoothAdapter::SendFile(const nsAString& aDeviceAddress,
nsIDOMBlob* aBlob, ErrorResult& aRv)
@ -892,7 +915,7 @@ BluetoothAdapter::IsScoConnected(ErrorResult& aRv)
nsRefPtr<DOMRequest> request = new DOMRequest(win);
nsRefPtr<BluetoothReplyRunnable> results =
new GetScoConnectionStatusTask(request);
new GetConnectionStatusTask(request);
BluetoothService* bs = BluetoothService::Get();
if (!bs) {

Просмотреть файл

@ -119,11 +119,16 @@ public:
already_AddRefed<DOMRequest>
Connect(BluetoothDevice& aDevice,
const Optional<short unsigned int>& aServiceUuid, ErrorResult& aRv);
const Optional<uint16_t>& aServiceUuid, ErrorResult& aRv);
already_AddRefed<DOMRequest>
Disconnect(BluetoothDevice& aDevice,
const Optional<short unsigned int>& aServiceUuid,
const Optional<uint16_t>& aServiceUuid,
ErrorResult& aRv);
already_AddRefed<DOMRequest>
IsConnected(const uint16_t aServiceUuid,
ErrorResult& aRv);
already_AddRefed<DOMRequest>
GetConnectedDevices(uint16_t aServiceUuid, ErrorResult& aRv);

Просмотреть файл

@ -210,18 +210,6 @@ BluetoothManager::Notify(const BluetoothSignal& aData)
}
}
bool
BluetoothManager::IsConnected(uint16_t aProfileId, ErrorResult& aRv)
{
BluetoothService* bs = BluetoothService::Get();
if (!bs) {
aRv.Throw(NS_ERROR_FAILURE);
return false;
}
return bs->IsConnected(aProfileId);
}
JSObject*
BluetoothManager::WrapObject(JSContext* aCx)
{

Просмотреть файл

@ -39,7 +39,6 @@ public:
virtual void SetPropertyByValue(const BluetoothNamedValue& aValue) MOZ_OVERRIDE;
bool GetEnabled(ErrorResult& aRv);
bool IsConnected(uint16_t aProfileId, ErrorResult& aRv);
already_AddRefed<DOMRequest> GetDefaultAdapter(ErrorResult& aRv);

Просмотреть файл

@ -229,8 +229,8 @@ public:
Disconnect(const nsAString& aDeviceAddress, uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable) = 0;
virtual bool
IsConnected(uint16_t aServiceUuid) = 0;
virtual void
IsConnected(const uint16_t aServiceUuid, BluetoothReplyRunnable* aRunnable) = 0;
virtual void
SendFile(const nsAString& aDeviceAddress,

Просмотреть файл

@ -1004,12 +1004,6 @@ BluetoothServiceBluedroid::Connect(const nsAString& aDeviceAddress,
ConnectDisconnect(true, aDeviceAddress, aRunnable, aServiceUuid, aCod);
}
bool
BluetoothServiceBluedroid::IsConnected(uint16_t aProfileId)
{
return true;
}
void
BluetoothServiceBluedroid::Disconnect(
const nsAString& aDeviceAddress, uint16_t aServiceUuid,
@ -1018,6 +1012,23 @@ BluetoothServiceBluedroid::Disconnect(
ConnectDisconnect(false, aDeviceAddress, aRunnable, aServiceUuid);
}
void
BluetoothServiceBluedroid::IsConnected(const uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aRunnable);
BluetoothProfileManagerBase* profile =
BluetoothUuidHelper::GetBluetoothProfileManager(aServiceUuid);
if (profile) {
DispatchBluetoothReply(aRunnable, profile->IsConnected(), EmptyString());
} else {
BT_WARNING("Can't find profile manager with uuid: %x", aServiceUuid);
DispatchBluetoothReply(aRunnable, false, EmptyString());
}
}
void
BluetoothServiceBluedroid::SendFile(const nsAString& aDeviceAddress,
BlobParent* aBlobParent,

Просмотреть файл

@ -84,13 +84,14 @@ public:
uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable);
virtual bool
IsConnected(uint16_t aProfileId);
virtual void
Disconnect(const nsAString& aDeviceAddress, uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable);
virtual void
IsConnected(const uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual void
SendFile(const nsAString& aDeviceAddress,
BlobParent* aBlobParent,

Просмотреть файл

@ -3457,20 +3457,21 @@ BluetoothDBusService::Disconnect(const nsAString& aDeviceAddress,
ConnectDisconnect(false, aDeviceAddress, aRunnable, aServiceUuid);
}
bool
BluetoothDBusService::IsConnected(const uint16_t aServiceUuid)
void
BluetoothDBusService::IsConnected(const uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aRunnable);
BluetoothProfileManagerBase* profile =
BluetoothUuidHelper::GetBluetoothProfileManager(aServiceUuid);
if (!profile) {
BT_WARNING(ERR_UNKNOWN_PROFILE);
return false;
if (profile) {
DispatchBluetoothReply(aRunnable, profile->IsConnected(), EmptyString());
} else {
BT_WARNING("Can't find profile manager with uuid: %x", aServiceUuid);
DispatchBluetoothReply(aRunnable, false, EmptyString());
}
NS_ENSURE_TRUE(profile, false);
return profile->IsConnected();
}
#ifdef MOZ_B2G_RIL

Просмотреть файл

@ -106,8 +106,9 @@ public:
uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual bool
IsConnected(uint16_t aServiceUuid) MOZ_OVERRIDE;
virtual void
IsConnected(const uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual void
Disconnect(const nsAString& aDeviceAddress, uint16_t aServiceUuid,

Просмотреть файл

@ -218,6 +218,8 @@ BluetoothParent::RecvPBluetoothRequestConstructor(
return actor->DoRequest(aRequest.get_ConnectRequest());
case Request::TDisconnectRequest:
return actor->DoRequest(aRequest.get_DisconnectRequest());
case Request::TIsConnectedRequest:
return actor->DoRequest(aRequest.get_IsConnectedRequest());
case Request::TSendFileRequest:
return actor->DoRequest(aRequest.get_SendFileRequest());
case Request::TStopSendingFileRequest:
@ -509,6 +511,18 @@ BluetoothRequestParent::DoRequest(const DisconnectRequest& aRequest)
return true;
}
bool
BluetoothRequestParent::DoRequest(const IsConnectedRequest& aRequest)
{
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TIsConnectedRequest);
mService->IsConnected(aRequest.serviceUuid(),
mReplyRunnable.get());
return true;
}
bool
BluetoothRequestParent::DoRequest(const SendFileRequest& aRequest)
{

Просмотреть файл

@ -169,6 +169,9 @@ protected:
bool
DoRequest(const DisconnectRequest& aRequest);
bool
DoRequest(const IsConnectedRequest& aRequest);
bool
DoRequest(const SendFileRequest& aRequest);

Просмотреть файл

@ -245,6 +245,14 @@ BluetoothServiceChildProcess::Disconnect(
DisconnectRequest(nsString(aDeviceAddress), aServiceUuid));
}
void
BluetoothServiceChildProcess::IsConnected(
const uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable, IsConnectedRequest(aServiceUuid));
}
void
BluetoothServiceChildProcess::SendFile(
const nsAString& aDeviceAddress,
@ -389,12 +397,6 @@ BluetoothServiceChildProcess::StopInternal()
MOZ_CRASH("This should never be called!");
}
bool
BluetoothServiceChildProcess::IsConnected(uint16_t aServiceUuid)
{
MOZ_CRASH("This should never be called!");
}
nsresult
BluetoothServiceChildProcess::SendSinkMessage(const nsAString& aDeviceAddresses,
const nsAString& aMessage)

Просмотреть файл

@ -111,8 +111,9 @@ public:
uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual bool
IsConnected(uint16_t aServiceUuid) MOZ_OVERRIDE;
virtual void
IsConnected(const uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual void
SendFile(const nsAString& aDeviceAddress,

Просмотреть файл

@ -101,6 +101,11 @@ struct DisconnectRequest
uint16_t serviceUuid;
};
struct IsConnectedRequest
{
uint16_t serviceUuid;
};
struct SendFileRequest
{
nsString devicePath;
@ -180,6 +185,7 @@ union Request
PairedDevicePropertiesRequest;
ConnectRequest;
DisconnectRequest;
IsConnectedRequest;
SendFileRequest;
StopSendingFileRequest;
ConfirmReceivingFileRequest;