Bug 977372 - Close IPC'd filedescriptor from device descriptor when finished with it. r=mikeh

This commit is contained in:
Dave Hylands 2014-02-28 12:02:55 -08:00
Родитель 354d15dbb9
Коммит 21e3c246cf
2 изменённых файлов: 21 добавлений и 1 удалений

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

@ -11,6 +11,7 @@
#include "DeviceStorage.h"
#include "DeviceStorageFileDescriptor.h"
#include "mozilla/dom/TabChild.h"
#include "mozilla/ipc/FileDescriptorUtils.h"
#include "mozilla/MediaManager.h"
#include "mozilla/Services.h"
#include "mozilla/unused.h"
@ -34,6 +35,7 @@
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::idl;
using namespace mozilla::ipc;
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsDOMCameraControl)
NS_INTERFACE_MAP_ENTRY(nsISupports)
@ -728,8 +730,16 @@ nsDOMCameraControl::OnCreatedFileDescriptor(bool aSucceeded)
return;
}
}
OnError(CameraControlListener::kInStartRecording, NS_LITERAL_STRING("FAILURE"));
if (mDSFileDescriptor->mFileDescriptor.IsValid()) {
// An error occured. We need to manually close the file associated with the
// FileDescriptor, and we shouldn't do this on the main thread, so we
// use a little helper.
nsRefPtr<CloseFileRunnable> closer =
new CloseFileRunnable(mDSFileDescriptor->mFileDescriptor);
closer->Dispatch();
}
}
void

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

@ -30,6 +30,7 @@
#include "mozilla/FileUtils.h"
#include "mozilla/Services.h"
#include "mozilla/unused.h"
#include "mozilla/ipc/FileDescriptorUtils.h"
#include "nsAlgorithm.h"
#include <media/mediaplayer.h>
#include "nsPrintfCString.h"
@ -46,6 +47,7 @@
using namespace mozilla;
using namespace mozilla::layers;
using namespace mozilla::gfx;
using namespace mozilla::ipc;
using namespace android;
#define RETURN_IF_NO_CAMERA_HW() \
@ -855,6 +857,14 @@ nsGonkCameraControl::StartRecordingImpl(DeviceStorageFileDescriptor* aFileDescri
return NS_ERROR_INVALID_ARG;
}
// SetupRecording creates a dup of the file descriptor, so we need to
// close the file descriptor when we leave this function. Also note, that
// since we're already off the main thread, we don't need to dispatch this.
// We just let the CloseFileRunnable destructor do the work.
nsRefPtr<CloseFileRunnable> closer;
if (aFileDescriptor->mFileDescriptor.IsValid()) {
closer = new CloseFileRunnable(aFileDescriptor->mFileDescriptor);
}
nsresult rv;
int fd = aFileDescriptor->mFileDescriptor.PlatformHandle();
if (aOptions) {