Bug 781692: Always fire DOMRequests for Set functions in BluetoothAdapter
authorKyle Machulis <kyle@nonpolynomial.com>
Mon, 13 Aug 2012 17:57:54 -0700
changeset 102250 4b26b044d57d99dfbc21201ba116d1c1e9afcea6
parent 102249 a80bf450ed280e1a32ca3374b3ccce7b3893a595
child 102251 376a20e68396f0224fd1634b9b0d71af130dce08
push id13384
push userkmachulis@mozilla.com
push dateTue, 14 Aug 2012 00:57:55 +0000
treeherdermozilla-inbound@4b26b044d57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs781692
milestone17.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 781692: Always fire DOMRequests for Set functions in BluetoothAdapter
dom/bluetooth/BluetoothAdapter.cpp
dom/bluetooth/BluetoothPropertyContainer.cpp
dom/bluetooth/BluetoothPropertyContainer.h
--- a/dom/bluetooth/BluetoothAdapter.cpp
+++ b/dom/bluetooth/BluetoothAdapter.cpp
@@ -59,16 +59,21 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(BluetoothAdapter)
 NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
 
 NS_IMPL_ADDREF_INHERITED(BluetoothAdapter, nsDOMEventTargetHelper)
 NS_IMPL_RELEASE_INHERITED(BluetoothAdapter, nsDOMEventTargetHelper)
 
 BluetoothAdapter::BluetoothAdapter(nsPIDOMWindow* aOwner, const BluetoothValue& aValue)
     : BluetoothPropertyContainer(BluetoothObjectType::TYPE_ADAPTER)
+    , mEnabled(false)
+    , mDiscoverable(false)
+    , mDiscovering(false)
+    , mPairable(false)
+    , mPowered(false)
     , mJsUuids(nullptr)
     , mJsDeviceAddresses(nullptr)
     , mIsRooted(false)
 {
   BindToOwner(aOwner);
   const InfallibleTArray<BluetoothNamedValue>& values =
     aValue.get_ArrayOfBluetoothNamedValue();
   for (uint32_t i = 0; i < values.Length(); ++i) {
@@ -353,42 +358,42 @@ BluetoothAdapter::GetUuids(JSContext* aC
   return NS_OK;
 }
 
 NS_IMETHODIMP
 BluetoothAdapter::SetName(const nsAString& aName,
                           nsIDOMDOMRequest** aRequest)
 {
   if (mName.Equals(aName)) {
-    return NS_OK;
+    return FirePropertyAlreadySet(GetOwner(), aRequest);
   }
   nsString name(aName);
   BluetoothValue value(name);
   BluetoothNamedValue property(NS_LITERAL_STRING("Name"), value);
   return SetProperty(GetOwner(), property, aRequest);
 }
  
 NS_IMETHODIMP
 BluetoothAdapter::SetDiscoverable(const bool aDiscoverable,
                                   nsIDOMDOMRequest** aRequest)
 {
   if (aDiscoverable == mDiscoverable) {
-    return NS_OK;
+    return FirePropertyAlreadySet(GetOwner(), aRequest);
   }
   BluetoothValue value(aDiscoverable);
   BluetoothNamedValue property(NS_LITERAL_STRING("Discoverable"), value);
   return SetProperty(GetOwner(), property, aRequest);
 }
  
 NS_IMETHODIMP
 BluetoothAdapter::SetDiscoverableTimeout(const PRUint32 aDiscoverableTimeout,
                                          nsIDOMDOMRequest** aRequest)
 {
   if (aDiscoverableTimeout == mDiscoverableTimeout) {
-    return NS_OK;
+    return FirePropertyAlreadySet(GetOwner(), aRequest);
   }
   BluetoothValue value(aDiscoverableTimeout);
   BluetoothNamedValue property(NS_LITERAL_STRING("DiscoverableTimeout"), value);
   return SetProperty(GetOwner(), property, aRequest);
 }
 
 NS_IMPL_EVENT_HANDLER(BluetoothAdapter, propertychanged)
 NS_IMPL_EVENT_HANDLER(BluetoothAdapter, devicefound)
--- a/dom/bluetooth/BluetoothPropertyContainer.cpp
+++ b/dom/bluetooth/BluetoothPropertyContainer.cpp
@@ -8,25 +8,36 @@
 #include "BluetoothPropertyContainer.h"
 #include "BluetoothService.h"
 #include "BluetoothTypes.h"
 #include "nsIDOMDOMRequest.h"
 
 USING_BLUETOOTH_NAMESPACE
 
 nsresult
-BluetoothPropertyContainer::GetProperties()
+BluetoothPropertyContainer::FirePropertyAlreadySet(nsIDOMWindow* aOwner,
+                                                   nsIDOMDOMRequest** aRequest)
 {
-  BluetoothService* bs = BluetoothService::Get();
-  if (!bs) {
-    NS_WARNING("Bluetooth service not available!");
+  nsCOMPtr<nsIDOMRequestService> rs = do_GetService("@mozilla.org/dom/dom-request-service;1");
+    
+  if (!rs) {
+    NS_WARNING("No DOMRequest Service!");
     return NS_ERROR_FAILURE;
   }
-  nsRefPtr<BluetoothReplyRunnable> task = new GetPropertiesTask(this, NULL);
-  return bs->GetProperties(mObjectType, mPath, task);
+
+  nsCOMPtr<nsIDOMDOMRequest> req;
+  nsresult rv = rs->CreateRequest(aOwner, getter_AddRefs(req));
+  if (NS_FAILED(rv)) {
+    NS_WARNING("Can't create DOMRequest!");
+    return NS_ERROR_FAILURE;
+  }
+  rs->FireSuccess(req, JSVAL_VOID);
+  req.forget(aRequest);
+
+  return NS_OK;
 }
 
 nsresult
 BluetoothPropertyContainer::SetProperty(nsIDOMWindow* aOwner,
                                         const BluetoothNamedValue& aProperty,
                                         nsIDOMDOMRequest** aRequest)
 {
   BluetoothService* bs = BluetoothService::Get();
@@ -51,26 +62,8 @@ BluetoothPropertyContainer::SetProperty(
   nsRefPtr<BluetoothReplyRunnable> task = new BluetoothVoidReplyRunnable(req);
   
   rv = bs->SetProperty(mObjectType, mPath, aProperty, task);
   NS_ENSURE_SUCCESS(rv, rv);
   
   req.forget(aRequest);
   return NS_OK;
 }
-
-
-bool
-BluetoothPropertyContainer::GetPropertiesTask::ParseSuccessfulReply(jsval* aValue)
-{
-  *aValue = JSVAL_VOID;
-  BluetoothValue& v = mReply->get_BluetoothReplySuccess().value();
-  if (v.type() != BluetoothValue::TArrayOfBluetoothNamedValue) {
-    NS_WARNING("Not a BluetoothNamedValue array!");
-    return false;
-  }
-  const InfallibleTArray<BluetoothNamedValue>& values =
-    mReply->get_BluetoothReplySuccess().value().get_ArrayOfBluetoothNamedValue();
-  for (uint32_t i = 0; i < values.Length(); ++i) {
-    mPropObjPtr->SetPropertyByValue(values[i]);
-  }
-  return true;
-}
--- a/dom/bluetooth/BluetoothPropertyContainer.h
+++ b/dom/bluetooth/BluetoothPropertyContainer.h
@@ -15,17 +15,18 @@ class nsIDOMWindow;
 
 BEGIN_BLUETOOTH_NAMESPACE
 
 class BluetoothNamedValue;
 
 class BluetoothPropertyContainer
 {
 public:
-  nsresult GetProperties();
+  nsresult FirePropertyAlreadySet(nsIDOMWindow* aOwner,
+                                  nsIDOMDOMRequest** aRequest);
   nsresult SetProperty(nsIDOMWindow* aOwner,
                        const BluetoothNamedValue& aProperty,
                        nsIDOMDOMRequest** aRequest);
   virtual void SetPropertyByValue(const BluetoothNamedValue& aValue) = 0;
   nsString GetPath()
   {
     return mPath;
   }
@@ -37,39 +38,16 @@ public:
 
 protected:
   BluetoothPropertyContainer(BluetoothObjectType aType) :
     mObjectType(aType)
   {}
 
   ~BluetoothPropertyContainer()
   {}
-  
-  class GetPropertiesTask : public BluetoothReplyRunnable
-  {
-  public:
-    GetPropertiesTask(BluetoothPropertyContainer* aPropObj, nsIDOMDOMRequest* aReq) :
-      BluetoothReplyRunnable(aReq),
-      mPropObjPtr(aPropObj)
-    {
-      MOZ_ASSERT(aReq && aPropObj);
-    }
-
-    virtual bool ParseSuccessfulReply(jsval* aValue);
-    
-    void
-    ReleaseMembers()
-    {
-      BluetoothReplyRunnable::ReleaseMembers();
-      mPropObjPtr = nullptr;
-    }
-    
-  private:
-    BluetoothPropertyContainer* mPropObjPtr;    
-  };
 
   nsString mPath;
   BluetoothObjectType mObjectType;
 };
 
 END_BLUETOOTH_NAMESPACE
 
 #endif