Bug 1006309 - Patch 4/4: Add logs specific for refined WebBluetooth API. r=echou
authorBen Tian <btian@mozilla.com>
Thu, 29 May 2014 17:20:19 +0800
changeset 186064 5183b3c511ef93238e5c7977863cd783edac62f5
parent 186063 cda3f53079c34e51332f428b6d2b9fa16aba27ab
child 186065 30a4f92e48a8d3f9a2bb7813a70c04295a189d60
push id7528
push usercbook@mozilla.com
push dateMon, 02 Jun 2014 07:05:22 +0000
treeherderb2g-inbound@5183b3c511ef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersechou
bugs1006309
milestone32.0a1
Bug 1006309 - Patch 4/4: Add logs specific for refined WebBluetooth API. r=echou
dom/bluetooth2/BluetoothCommon.h
dom/bluetooth2/BluetoothManager.cpp
--- a/dom/bluetooth2/BluetoothCommon.h
+++ b/dom/bluetooth2/BluetoothCommon.h
@@ -53,16 +53,22 @@ extern bool gBluetoothDebugFlag;
     }                                                                \
   } while(0)
 
 #define BT_LOGR(msg, ...) printf("%s: " msg, __FUNCTION__, ##__VA_ARGS__))
 #define BT_WARNING(msg, ...) printf("%s: " msg, __FUNCTION__, ##__VA_ARGS__))
 #endif
 
 /**
+ * Prints 'R'ELEASE build logs for WebBluetooth API v2.
+ */
+#define BT_API2_LOGR(msg, ...)                                       \
+  BT_LOGR("[WEBBT-API2] " msg, ##__VA_ARGS__)
+
+/**
  * Wrap literal name and value into a BluetoothNamedValue
  * and append it to the array.
  */
 #define BT_APPEND_NAMED_VALUE(array, name, value)                    \
   array.AppendElement(BluetoothNamedValue(NS_LITERAL_STRING(name), value))
 
 /**
  * Ensure success of system message broadcast with void return.
--- a/dom/bluetooth2/BluetoothManager.cpp
+++ b/dom/bluetooth2/BluetoothManager.cpp
@@ -56,16 +56,17 @@ class GetAdaptersTask : public Bluetooth
     // Extract the array of all adapters' properties
     const BluetoothValue& adaptersProperties =
       mReply->get_BluetoothReplySuccess().value();
     NS_ENSURE_TRUE(adaptersProperties.type() ==
                    BluetoothValue::TArrayOfBluetoothNamedValue, false);
 
     const InfallibleTArray<BluetoothNamedValue>& adaptersPropertiesArray =
       adaptersProperties.get_ArrayOfBluetoothNamedValue();
+    BT_API2_LOGR("GetAdaptersTask: len[%d]", adaptersPropertiesArray.Length());
 
     // Append a BluetoothAdapter into adapters array for each properties array
     uint32_t numAdapters = adaptersPropertiesArray.Length();
     for (uint32_t i = 0; i < numAdapters; i++) {
       MOZ_ASSERT(adaptersPropertiesArray[i].name().EqualsLiteral("Adapter"));
 
       const BluetoothValue& properties = adaptersPropertiesArray[i].value();
       mManager->AppendAdapter(properties);
@@ -89,16 +90,17 @@ private:
 BluetoothManager::BluetoothManager(nsPIDOMWindow *aWindow)
   : DOMEventTargetHelper(aWindow)
   , mDefaultAdapterIndex(-1)
 {
   MOZ_ASSERT(aWindow);
   MOZ_ASSERT(IsDOMBinding());
 
   ListenToBluetoothSignal(true);
+  BT_API2_LOGR("aWindow %p", aWindow);
 
   // Query adapters list from bluetooth backend
   BluetoothService* bs = BluetoothService::Get();
   NS_ENSURE_TRUE_VOID(bs);
 
   nsRefPtr<BluetoothReplyRunnable> result = new GetAdaptersTask(this);
   NS_ENSURE_SUCCESS_VOID(bs->GetAdaptersInternal(result));
 }
@@ -126,17 +128,19 @@ BluetoothManager::ListenToBluetoothSigna
   } else {
     bs->UnregisterBluetoothSignalHandler(NS_LITERAL_STRING(KEY_MANAGER), this);
   }
 }
 
 BluetoothAdapter*
 BluetoothManager::GetDefaultAdapter()
 {
-  return (DefaultAdapterExists()) ? mAdapters[mDefaultAdapterIndex] : nullptr;
+  BT_API2_LOGR("mDefaultAdapterIndex: %d", mDefaultAdapterIndex);
+
+  return DefaultAdapterExists() ? mAdapters[mDefaultAdapterIndex] : nullptr;
 }
 
 void
 BluetoothManager::AppendAdapter(const BluetoothValue& aValue)
 {
   MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
 
   // Create a new BluetoothAdapter and append it to adapters array
@@ -170,16 +174,17 @@ BluetoothManager::Create(nsPIDOMWindow* 
   nsRefPtr<BluetoothManager> manager = new BluetoothManager(aWindow);
   return manager.forget();
 }
 
 void
 BluetoothManager::HandleAdapterAdded(const BluetoothValue& aValue)
 {
   MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
+  BT_API2_LOGR();
 
   AppendAdapter(aValue);
 
   // Notify application of added adapter
   BluetoothAdapterEventInit init;
   init.mAdapter = mAdapters.LastElement();
   DispatchAdapterEvent(NS_LITERAL_STRING("adapteradded"), init);
 }
@@ -213,35 +218,39 @@ BluetoothManager::HandleAdapterRemoved(c
   DispatchAdapterEvent(NS_LITERAL_STRING("adapterremoved"), init);
 }
 
 void
 BluetoothManager::ReselectDefaultAdapter()
 {
   // Select the first of existing/remaining adapters as default adapter
   mDefaultAdapterIndex = mAdapters.IsEmpty() ? -1 : 0;
+  BT_API2_LOGR("mAdapters length: %d => NEW mDefaultAdapterIndex: %d",
+               mAdapters.Length(), mDefaultAdapterIndex);
 
   // Notify application of default adapter change
   DispatchAttributeEvent();
 }
 
 void
 BluetoothManager::DispatchAdapterEvent(const nsAString& aType,
                                        const BluetoothAdapterEventInit& aInit)
 {
+  BT_API2_LOGR("aType (%s)", NS_ConvertUTF16toUTF8(aType).get());
+
   nsRefPtr<BluetoothAdapterEvent> event =
     BluetoothAdapterEvent::Constructor(this, aType, aInit);
-
   DispatchTrustedEvent(event);
 }
 
 void
 BluetoothManager::DispatchAttributeEvent()
 {
   MOZ_ASSERT(NS_IsMainThread());
+  BT_API2_LOGR();
 
   // Wrap default adapter
   AutoJSContext cx;
   JS::Rooted<JS::Value> value(cx, JS::NullValue());
   if (DefaultAdapterExists()) {
     BluetoothAdapter* adapter = mAdapters[mDefaultAdapterIndex];
     nsCOMPtr<nsIGlobalObject> global =
       do_QueryInterface(adapter->GetParentObject());
@@ -250,16 +259,18 @@ BluetoothManager::DispatchAttributeEvent
     JS::Rooted<JSObject*> scope(cx, global->GetGlobalJSObject());
     NS_ENSURE_TRUE_VOID(scope);
 
     JSAutoCompartment ac(cx, scope);
     if (!ToJSValue(cx, adapter, &value)) {
       JS_ClearPendingException(cx);
       return;
     }
+
+    BT_API2_LOGR("Default adapter is wrapped");
   }
 
   // Notify application of default adapter change
   RootedDictionary<BluetoothAttributeEventInit> init(cx);
   init.mAttr = (uint16_t)BluetoothManagerAttribute::DefaultAdapter;
   init.mValue = value;
   nsRefPtr<BluetoothAttributeEvent> event =
     BluetoothAttributeEvent::Constructor(this,