Bug 1072535 - Pt 1 - Have DownloadDone notify device storage when a new download is available. r=paolo

This commit is contained in:
Dave Hylands 2014-10-14 13:50:57 -07:00
Родитель 0645508260
Коммит 32cc7daac6
2 изменённых файлов: 37 добавлений и 1 удалений

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

@ -7,9 +7,12 @@
#include "nsString.h"
#include "nsIURI.h"
#include "nsIFile.h"
#include "nsIObserverService.h"
#include "nsISupportsPrimitives.h"
#include "nsDirectoryServiceDefs.h"
#include "mozilla/Preferences.h"
#include "mozilla/Services.h"
#define PREF_BDM_ADDTORECENTDOCS "browser.download.manager.addToRecentDocs"
@ -69,7 +72,9 @@ static void gio_set_metadata_done(GObject *source_obj, GAsyncResult *res, gpoint
nsresult DownloadPlatform::DownloadDone(nsIURI* aSource, nsIFile* aTarget,
const nsACString& aContentType, bool aIsPrivate)
{
#if defined(XP_WIN) || defined(XP_MACOSX) || defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GTK)
#if defined(XP_WIN) || defined(XP_MACOSX) || defined(MOZ_WIDGET_ANDROID) \
|| defined(MOZ_WIDGET_GTK) || defined(MOZ_WIDGET_GONK)
nsAutoString path;
if (aTarget && NS_SUCCEEDED(aTarget->GetPath(path))) {
#if defined(XP_WIN) || defined(MOZ_WIDGET_GTK) || defined(MOZ_WIDGET_ANDROID)
@ -120,6 +125,18 @@ nsresult DownloadPlatform::DownloadDone(nsIURI* aSource, nsIFile* aTarget,
observedObject, nullptr, TRUE);
::CFRelease(observedObject);
#endif
if (mozilla::Preferences::GetBool("device.storage.enabled", true)) {
// Tell DeviceStorage that a new file may have been added.
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
nsCOMPtr<nsISupportsString> pathString
= do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID);
if (obs && pathString) {
if (NS_SUCCEEDED(pathString->SetData(path))) {
(void)obs->NotifyObservers(pathString, "download-watcher-notify",
MOZ_UTF16("modified"));
}
}
}
}
#ifdef XP_WIN

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

@ -1733,10 +1733,28 @@ add_task(function test_toSerializable_startTime()
add_task(function test_platform_integration()
{
let downloadFiles = [];
let oldDeviceStorageEnabled = false;
try {
oldDeviceStorageEnabled = Services.prefs.getBoolPref("device.storage.enabled");
} catch (e) {
// This happens if the pref doesn't exist.
}
let downloadWatcherNotified = false;
let observer = {
observe: function(subject, topic, data) {
do_check_eq(topic, "download-watcher-notify");
do_check_eq(data, "modified");
downloadWatcherNotified = true;
}
}
Services.obs.addObserver(observer, "download-watcher-notify", false);
Services.prefs.setBoolPref("device.storage.enabled", true);
function cleanup() {
for (let file of downloadFiles) {
file.remove(true);
}
Services.obs.removeObserver(observer, "download-watcher-notify");
Services.prefs.setBoolPref("device.storage.enabled", oldDeviceStorageEnabled);
}
do_register_cleanup(cleanup);
@ -1770,6 +1788,7 @@ add_task(function test_platform_integration()
// downloadDone should be called before the whenSucceeded promise is resolved.
yield download.whenSucceeded().then(function () {
do_check_true(DownloadIntegration.downloadDoneCalled);
do_check_true(downloadWatcherNotified);
});
// Then, wait for the promise returned by "start" to be resolved.