Backed out 1 changesets (bug 1196358) for causing test failures in test_settings_service.xul
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Wed, 23 Sep 2015 12:09:29 +0200
changeset 264000 58db439182adffa677a28be86428c1e3f02bc7f3
parent 263999 bcedf81cd2f4fd147654e35c300a3e2636968566
child 264001 d15626d1167d0c8ad60db77e0ca6f1ef2085863f
push id15328
push userkwierso@gmail.com
push dateWed, 23 Sep 2015 20:26:10 +0000
treeherderfx-team@b48fff4751f5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1196358
milestone44.0a1
backs outa2e4fa843ae5ed310169492c41095d6c4bcf66a4
Backed out 1 changesets (bug 1196358) for causing test failures in test_settings_service.xul Backed out changeset a2e4fa843ae5 (bug 1196358)
dom/settings/tests/test_settings_service.js
dom/system/gonk/AudioManager.cpp
dom/system/gonk/AudioManager.h
--- a/dom/settings/tests/test_settings_service.js
+++ b/dom/settings/tests/test_settings_service.js
@@ -91,21 +91,16 @@ var tests = [
               ok(false, "Event is not mozsettings-changed.");
               return;
             }
             // Data is now stored in subject
             if ("wrappedJSObject" in subject) {
               ok(true, "JS object wrapped into subject");
               subject = subject.wrappedJSObject;
             }
-            if (subject["key"] != TEST_OBSERVER_KEY) {
-              ok(false, "Other setting events.")
-              return;
-            }
-
             function checkProp(name, type, value) {
               ok(name in subject, "subject." + name + " is present");
               is(typeof subject[name], type, "subject." + name + " is " + type);
               is(subject[name], value, "subject." + name + " is " + value);
             }
 
             checkProp("key", "string", TEST_OBSERVER_KEY);
             checkProp("value", "boolean", TEST_OBSERVER_VALUE);
--- a/dom/system/gonk/AudioManager.cpp
+++ b/dom/system/gonk/AudioManager.cpp
@@ -124,33 +124,16 @@ public:
   void Run() override
   {
     mRunnable->Run();
   }
 protected:
   nsCOMPtr<nsIRunnable> mRunnable;
 };
 
-nsCOMPtr<nsISettingsServiceLock>
-GetSettingServiceLock()
-{
-  nsresult rv;
-  nsCOMPtr<nsISettingsService> service = do_GetService(SETTINGS_SERVICE, &rv);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return nullptr;
-  }
-
-  nsCOMPtr<nsISettingsServiceLock> lock;
-  rv = service->CreateLock(nullptr, getter_AddRefs(lock));
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return nullptr;
-  }
-  return lock.forget();
-}
-
 class AudioProfileData final
 {
 public:
   explicit AudioProfileData(AudioOutputProfiles aProfile)
     : mProfile(aProfile)
     , mActive(false)
   {
     for (uint32_t idx = 0; idx < VOLUME_TOTAL_NUMBER; ++idx) {
@@ -512,22 +495,16 @@ AudioManager::Observe(nsISupports* aSubj
     if (!setting.mValue.isNumber()) {
       return NS_OK;
     }
 
     uint32_t volIndex = setting.mValue.toNumber();
     for (uint32_t idx = 0; idx < VOLUME_TOTAL_NUMBER; ++idx) {
       if (setting.mKey.EqualsASCII(gVolumeData[idx].mChannelName)) {
         SetVolumeByCategory(gVolumeData[idx].mCategory, volIndex);
-        nsCOMPtr<nsISettingsServiceLock> lock = GetSettingServiceLock();
-        UpdateVolumeSettingToDatabase(lock.get(),
-                                      AppendProfileToVolumeSetting(
-                                        gVolumeData[idx].mChannelName,
-                                        mPresentProfile).get(),
-                                      volIndex);
         return NS_OK;
       }
     }
   }
 
   NS_WARNING("Unexpected topic in AudioManager");
   return NS_ERROR_FAILURE;
 }
@@ -682,16 +659,19 @@ AudioManager::~AudioManager() {
     NS_WARNING("Failed to remove bluetooth hfp NREC status changed observer!");
   }
   if (NS_FAILED(obs->RemoveObserver(this, MOZ_SETTINGS_CHANGE_ID))) {
     NS_WARNING("Failed to remove mozsettings-changed observer!");
   }
   if (NS_FAILED(obs->RemoveObserver(this,  AUDIO_CHANNEL_PROCESS_CHANGED))) {
     NS_WARNING("Failed to remove audio-channel-process-changed!");
   }
+
+  // Store the present volume setting to setting database.
+  SendVolumeChangeNotification(FindAudioProfileData(mPresentProfile));
 }
 
 static StaticRefPtr<AudioManager> sAudioManager;
 
 already_AddRefed<AudioManager>
 AudioManager::GetInstance()
 {
   // Avoid createing AudioManager from content process.
@@ -1117,16 +1097,17 @@ AudioManager::AppendProfileToVolumeSetti
       topic.Append(".");
       topic.Append(kAudioOutputProfilesTable[idx].tag);
       break;
     }
   }
   return topic;
 }
 
+
 void
 AudioManager::InitVolumeFromDatabase()
 {
   nsresult rv;
   nsCOMPtr<nsISettingsService> service = do_GetService(SETTINGS_SERVICE, &rv);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return;
   }
@@ -1159,43 +1140,43 @@ AudioManager::InitProfileVolumeSucceeded
 
 void
 AudioManager::InitProfileVolumeFailed(const char* aError)
 {
   NS_WARNING(aError);
 }
 
 void
-AudioManager::UpdateVolumeSettingToDatabase(nsISettingsServiceLock* aLock,
-                                            const char* aTopic,
-                                            uint32_t aVolIndex)
-{
-  MOZ_ASSERT(aLock);
-
-  mozilla::AutoSafeJSContext cx;
-  JS::Rooted<JS::Value> value(cx);
-  value.setInt32(aVolIndex);
-  aLock->Set(aTopic, value, nullptr, nullptr);
-}
-
-void
 AudioManager::SendVolumeChangeNotification(AudioProfileData* aProfileData)
 {
   MOZ_ASSERT(aProfileData);
+  nsresult rv;
+  nsCOMPtr<nsISettingsService> service = do_GetService(SETTINGS_SERVICE, &rv);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return;
+  }
 
-  // Change the value of the current volume setting, so that the Gaia can get
-  // correct volume values and update the volume UI. In addition, for reducing
-  // the code dependency, Gaia doesn't need to know the current profile, it
-  // only need to care about different volume categories.
-  nsCOMPtr<nsISettingsServiceLock> lock = GetSettingServiceLock();
+  nsCOMPtr<nsISettingsServiceLock> lock;
+  rv = service->CreateLock(nullptr, getter_AddRefs(lock));
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return;
+  }
+
+  // Send events to update the Gaia volume
+  mozilla::AutoSafeJSContext cx;
+  JS::Rooted<JS::Value> value(cx);
   for (uint32_t idx = 0; idx < VOLUME_TOTAL_NUMBER; ++idx) {
-    uint32_t volSetting = gVolumeData[idx].mCategory;
-    UpdateVolumeSettingToDatabase(lock.get(),
-                                  gVolumeData[idx].mChannelName,
-                                  aProfileData->mVolumeTable[volSetting]);
+    value.setInt32(aProfileData->mVolumeTable[gVolumeData[idx].mCategory]);
+    // For reducing the code dependency, Gaia doesn't need to know the current
+    // profile, it only need to care about different volume categories.
+    // However, we need to send the setting volume to the permanent database,
+    // so that we can store the volume setting even if the phone reboots.
+    lock->Set(gVolumeData[idx].mChannelName, value, nullptr, nullptr);
+    lock->Set(AppendProfileToVolumeSetting(gVolumeData[idx].mChannelName,
+               mPresentProfile).get(), value, nullptr, nullptr);
   }
 }
 
 void
 AudioManager::CreateAudioProfilesData()
 {
   MOZ_ASSERT(mAudioProfiles.IsEmpty(), "mAudioProfiles should be empty!");
   for (uint32_t idx = 0; idx < DEVICE_TOTAL_NUMBER; ++idx) {
--- a/dom/system/gonk/AudioManager.h
+++ b/dom/system/gonk/AudioManager.h
@@ -23,18 +23,16 @@
 #include "nsIObserver.h"
 #include "android_audio/AudioSystem.h"
 
 // {b2b51423-502d-4d77-89b3-7786b562b084}
 #define NS_AUDIOMANAGER_CID {0x94f6fd70, 0x7615, 0x4af9, \
       {0x89, 0x10, 0xf9, 0x3c, 0x55, 0xe6, 0x62, 0xec}}
 #define NS_AUDIOMANAGER_CONTRACTID "@mozilla.org/telephony/audiomanager;1"
 
-class nsISettingsServiceLock;
-
 namespace mozilla {
 namespace hal {
 class SwitchEvent;
 typedef Observer<SwitchEvent> SwitchObserver;
 } // namespace hal
 
 namespace dom {
 namespace gonk {
@@ -164,21 +162,18 @@ private:
   uint32_t GetMaxVolumeByCategory(uint32_t aCategory) const;
 
   AudioProfileData* FindAudioProfileData(AudioOutputProfiles aProfile);
 
   // Append the profile to the volume setting string.
   nsAutoCString AppendProfileToVolumeSetting(const char* aName,
                                              AudioOutputProfiles aProfile);
 
-  // We store the volume setting in the database, these are related functions.
+  // Init volume from the settings database.
   void InitVolumeFromDatabase();
-  void UpdateVolumeSettingToDatabase(nsISettingsServiceLock* aLock,
-                                     const char* aTopic,
-                                     uint32_t aVolIndex);
 
   // Promise functions.
   void InitProfileVolumeSucceeded();
   void InitProfileVolumeFailed(const char* aError);
 
   void UpdateHeadsetConnectionState(hal::SwitchState aState);
 
   AudioManager();