Bug 860213 - Use async version of set metadata. r=Neil
authorJan Horak <jhorak@redhat.com>
Mon, 06 May 2013 09:04:16 -0400
changeset 141919 8ec71524c28c01d01c304da0592a3c29ef8d1f9c
parent 141918 e3e7f9657fcdfb99a2f0de60fd3452cf1c99b75c
child 141920 a0974c8e1e5317e36d0c69b1f51d88b9c940fdc7
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersNeil
bugs860213
milestone23.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 860213 - Use async version of set metadata. r=Neil
toolkit/components/downloads/nsDownloadManager.cpp
--- a/toolkit/components/downloads/nsDownloadManager.cpp
+++ b/toolkit/components/downloads/nsDownloadManager.cpp
@@ -2520,16 +2520,30 @@ nsDownload::nsDownload() : mDownloadStat
                            mAutoResume(DONT_RESUME)
 {
 }
 
 nsDownload::~nsDownload()
 {
 }
 
+#ifdef MOZ_ENABLE_GIO
+static void gio_set_metadata_done(GObject *source_obj, GAsyncResult *res, gpointer user_data)
+{
+  GError *err = NULL;
+  g_file_set_attributes_finish(G_FILE(source_obj), res, NULL, &err);
+  if (err) {
+#ifdef DEBUG
+    NS_DebugBreak(NS_DEBUG_WARNING, "Set file metadata failed: ", err->message, __FILE__, __LINE__);
+#endif
+    g_error_free(err);
+  }
+}
+#endif
+
 nsresult
 nsDownload::SetState(DownloadState aState)
 {
   NS_ASSERTION(mDownloadState != aState,
                "Trying to set the download state to what it already is set to!");
 
   int16_t oldState = mDownloadState;
   mDownloadState = aState;
@@ -2665,21 +2679,24 @@ nsDownload::SetState(DownloadState aStat
             }
 #endif
           }
 #ifdef MOZ_ENABLE_GIO
           // Use GIO to store the source URI for later display in the file manager.
           GFile* gio_file = g_file_new_for_path(NS_ConvertUTF16toUTF8(path).get());
           nsCString source_uri;
           mSource->GetSpec(source_uri);
-
-          g_file_set_attribute(gio_file, "metadata::download-uri",
-                               G_FILE_ATTRIBUTE_TYPE_STRING,
-                               (gpointer)source_uri.get(),
-                               G_FILE_QUERY_INFO_NONE, NULL, NULL);
+          GFileInfo *file_info = g_file_info_new();
+          g_file_info_set_attribute_string(file_info, "metadata::download-uri", source_uri.get());
+          g_file_set_attributes_async(gio_file,
+                                      file_info,
+                                      G_FILE_QUERY_INFO_NONE,
+                                      G_PRIORITY_DEFAULT,
+                                      NULL, gio_set_metadata_done, NULL);
+          g_object_unref(file_info);
           g_object_unref(gio_file);
 #endif
         }
 #endif
 #ifdef XP_MACOSX
         // On OS X, make the downloads stack bounce.
         CFStringRef observedObject = ::CFStringCreateWithCString(kCFAllocatorDefault,
                                                  NS_ConvertUTF16toUTF8(path).get(),