From 9e8687b1e02ede1660f81057ab746cafe738fbba Mon Sep 17 00:00:00 2001 From: Ben Tian Date: Mon, 16 Jun 2014 15:50:45 +0800 Subject: [PATCH] Bug 1016196 - Patch 2/2: Add logs for Promise in BluetoothReplyRunnable, r=echou --- dom/bluetooth2/BluetoothAdapter.cpp | 7 ++++++- dom/bluetooth2/BluetoothReplyRunnable.cpp | 18 ++++++++++++++---- dom/bluetooth2/BluetoothReplyRunnable.h | 7 +++++-- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/dom/bluetooth2/BluetoothAdapter.cpp b/dom/bluetooth2/BluetoothAdapter.cpp index 13585e67021c..fa0408951869 100644 --- a/dom/bluetooth2/BluetoothAdapter.cpp +++ b/dom/bluetooth2/BluetoothAdapter.cpp @@ -686,12 +686,14 @@ BluetoothAdapter::EnableDisable(bool aEnable) return promise.forget(); } + nsString methodName; if (aEnable) { // Enable local adapter if (mState != BluetoothAdapterState::Disabled) { promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR); return promise.forget(); } + methodName.AssignLiteral("Enable"); mState = BluetoothAdapterState::Enabling; } else { // Disable local adapter @@ -699,12 +701,15 @@ BluetoothAdapter::EnableDisable(bool aEnable) promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR); return promise.forget(); } + methodName.AssignLiteral("Disable"); mState = BluetoothAdapterState::Disabling; } // TODO: Fire attr changed event for this state change nsRefPtr result = - new BluetoothVoidReplyRunnable(nullptr /* DOMRequest */, promise); + new BluetoothVoidReplyRunnable(nullptr, /* DOMRequest */ + promise, + methodName); if(NS_FAILED(bs->EnableDisable(aEnable, result))) { promise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR); diff --git a/dom/bluetooth2/BluetoothReplyRunnable.cpp b/dom/bluetooth2/BluetoothReplyRunnable.cpp index ec8902ac51b8..d1ede83d4648 100644 --- a/dom/bluetooth2/BluetoothReplyRunnable.cpp +++ b/dom/bluetooth2/BluetoothReplyRunnable.cpp @@ -16,10 +16,16 @@ using namespace mozilla::dom; USING_BLUETOOTH_NAMESPACE BluetoothReplyRunnable::BluetoothReplyRunnable(nsIDOMDOMRequest* aReq, - Promise* aPromise) + Promise* aPromise, + const nsAString& aName) : mDOMRequest(aReq) , mPromise(aPromise) -{} + , mName(aName) +{ + if (aPromise) { + BT_API2_LOGR("<%s>", NS_ConvertUTF16toUTF8(mName).get()); + } +} void BluetoothReplyRunnable::SetReply(BluetoothReply* aReply) @@ -53,6 +59,7 @@ BluetoothReplyRunnable::FireReplySuccess(JS::Handle aVal) // Promise if (mPromise) { + BT_API2_LOGR("<%s>", NS_ConvertUTF16toUTF8(mName).get()); mPromise->MaybeResolve(aVal); } @@ -73,6 +80,8 @@ BluetoothReplyRunnable::FireErrorString() // Promise if (mPromise) { + BT_API2_LOGR("<%s>", NS_ConvertUTF16toUTF8(mName).get()); + /** * Always reject with NS_ERROR_DOM_OPERATION_ERR. * @@ -120,8 +129,9 @@ BluetoothReplyRunnable::Run() } BluetoothVoidReplyRunnable::BluetoothVoidReplyRunnable(nsIDOMDOMRequest* aReq, - Promise* aPromise) - : BluetoothReplyRunnable(aReq, aPromise) + Promise* aPromise, + const nsAString& aName) + : BluetoothReplyRunnable(aReq, aPromise, aName) {} BluetoothVoidReplyRunnable::~BluetoothVoidReplyRunnable() diff --git a/dom/bluetooth2/BluetoothReplyRunnable.h b/dom/bluetooth2/BluetoothReplyRunnable.h index 0c4ba5190986..d2bb81b12a1f 100644 --- a/dom/bluetooth2/BluetoothReplyRunnable.h +++ b/dom/bluetooth2/BluetoothReplyRunnable.h @@ -30,7 +30,8 @@ public: NS_DECL_NSIRUNNABLE BluetoothReplyRunnable(nsIDOMDOMRequest* aReq, - Promise* aPromise = nullptr); + Promise* aPromise = nullptr, + const nsAString& aName = EmptyString()); void SetReply(BluetoothReply* aReply); @@ -67,13 +68,15 @@ private: nsRefPtr mPromise; nsString mErrorString; + nsString mName; // for debugging }; class BluetoothVoidReplyRunnable : public BluetoothReplyRunnable { public: BluetoothVoidReplyRunnable(nsIDOMDOMRequest* aReq, - Promise* aPromise = nullptr); + Promise* aPromise = nullptr, + const nsAString& aName = EmptyString()); ~BluetoothVoidReplyRunnable(); protected: