2012-07-16 09:38:18 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "nsVolumeService.h"
|
|
|
|
|
|
|
|
#include "Volume.h"
|
|
|
|
#include "VolumeManager.h"
|
|
|
|
#include "VolumeServiceIOThread.h"
|
|
|
|
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsDependentSubstring.h"
|
2012-12-14 16:01:34 -08:00
|
|
|
#include "nsIDOMWakeLockListener.h"
|
2012-07-16 09:38:18 -07:00
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsIObserverService.h"
|
2012-12-14 16:01:34 -08:00
|
|
|
#include "nsIPowerManagerService.h"
|
2012-07-16 09:38:18 -07:00
|
|
|
#include "nsISupportsUtils.h"
|
|
|
|
#include "nsIVolume.h"
|
|
|
|
#include "nsIVolumeService.h"
|
|
|
|
#include "nsLocalFile.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2012-12-14 16:01:34 -08:00
|
|
|
#include "nsVolumeMountLock.h"
|
2012-07-16 09:38:18 -07:00
|
|
|
#include "nsXULAppAPI.h"
|
2012-12-14 16:01:34 -08:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2012-07-16 09:38:18 -07:00
|
|
|
#include "mozilla/Services.h"
|
|
|
|
|
|
|
|
#define VOLUME_MANAGER_LOG_TAG "nsVolumeService"
|
|
|
|
#include "VolumeManagerLog.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2012-12-14 16:01:34 -08:00
|
|
|
using namespace mozilla::dom;
|
2012-07-16 09:38:18 -07:00
|
|
|
using namespace mozilla::services;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace system {
|
|
|
|
|
2013-07-18 19:21:20 -07:00
|
|
|
NS_IMPL_ISUPPORTS2(nsVolumeService,
|
|
|
|
nsIVolumeService,
|
|
|
|
nsIDOMMozWakeLockListener)
|
2012-12-14 16:01:34 -08:00
|
|
|
|
|
|
|
StaticRefPtr<nsVolumeService> nsVolumeService::sSingleton;
|
|
|
|
|
|
|
|
// static
|
|
|
|
already_AddRefed<nsVolumeService>
|
|
|
|
nsVolumeService::GetSingleton()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (!sSingleton) {
|
|
|
|
sSingleton = new nsVolumeService();
|
|
|
|
}
|
2013-04-18 07:13:23 -07:00
|
|
|
nsRefPtr<nsVolumeService> volumeService = sSingleton.get();
|
|
|
|
return volumeService.forget();
|
2012-12-14 16:01:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
|
|
|
nsVolumeService::Shutdown()
|
|
|
|
{
|
2013-04-02 12:52:17 -07:00
|
|
|
if (!sSingleton) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (XRE_GetProcessType() != GeckoProcessType_Default) {
|
|
|
|
sSingleton = nullptr;
|
2012-12-14 16:01:34 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPowerManagerService> pmService =
|
|
|
|
do_GetService(POWERMANAGERSERVICE_CONTRACTID);
|
|
|
|
if (pmService) {
|
|
|
|
pmService->RemoveWakeLockListener(sSingleton.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
XRE_GetIOMessageLoop()->PostTask(
|
|
|
|
FROM_HERE,
|
|
|
|
NewRunnableFunction(ShutdownVolumeServiceIOThread));
|
|
|
|
|
|
|
|
sSingleton = nullptr;
|
|
|
|
}
|
2012-07-16 09:38:18 -07:00
|
|
|
|
|
|
|
nsVolumeService::nsVolumeService()
|
2013-04-18 07:13:23 -07:00
|
|
|
: mArrayMonitor("nsVolumeServiceArray")
|
2012-07-16 09:38:18 -07:00
|
|
|
{
|
2012-12-14 16:01:34 -08:00
|
|
|
sSingleton = this;
|
|
|
|
|
|
|
|
if (XRE_GetProcessType() != GeckoProcessType_Default) {
|
2013-04-02 12:52:17 -07:00
|
|
|
// Request the initial state for all volumes.
|
|
|
|
ContentChild::GetSingleton()->SendBroadcastVolume(NS_LITERAL_STRING(""));
|
2012-12-14 16:01:34 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-16 09:38:18 -07:00
|
|
|
// Startup the IOThread side of things. The actual volume changes
|
|
|
|
// are captured by the IOThread and forwarded to main thread.
|
|
|
|
XRE_GetIOMessageLoop()->PostTask(
|
|
|
|
FROM_HERE,
|
2012-12-14 16:01:34 -08:00
|
|
|
NewRunnableFunction(InitVolumeServiceIOThread, this));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPowerManagerService> pmService =
|
|
|
|
do_GetService(POWERMANAGERSERVICE_CONTRACTID);
|
|
|
|
if (!pmService) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pmService->AddWakeLockListener(this);
|
2012-07-16 09:38:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsVolumeService::~nsVolumeService()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-12-14 16:01:34 -08:00
|
|
|
// Callback for nsIDOMMozWakeLockListener
|
2013-04-18 07:13:23 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVolumeService::Callback(const nsAString& aTopic, const nsAString& aState)
|
2012-12-14 16:01:34 -08:00
|
|
|
{
|
|
|
|
CheckMountLock(aTopic, aState);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-18 07:13:23 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVolumeService::BroadcastVolume(const nsAString& aVolName)
|
2012-12-14 16:01:34 -08:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
|
2013-04-02 12:52:17 -07:00
|
|
|
|
|
|
|
if (aVolName.EqualsLiteral("")) {
|
2013-04-18 07:13:23 -07:00
|
|
|
nsVolume::Array volumeArray;
|
|
|
|
{
|
|
|
|
// Copy the array since we don't want to call BroadcastVolume
|
|
|
|
// while we're holding the lock.
|
|
|
|
MonitorAutoLock autoLock(mArrayMonitor);
|
|
|
|
volumeArray = mVolumeArray;
|
|
|
|
}
|
|
|
|
|
2013-04-02 12:52:17 -07:00
|
|
|
// We treat being passed the empty string as "broadcast all volumes"
|
2013-04-18 07:13:23 -07:00
|
|
|
nsVolume::Array::size_type numVolumes = volumeArray.Length();
|
2013-04-02 12:52:17 -07:00
|
|
|
nsVolume::Array::index_type volIndex;
|
|
|
|
for (volIndex = 0; volIndex < numVolumes; volIndex++) {
|
2013-04-18 07:13:23 -07:00
|
|
|
const nsString& volName(volumeArray[volIndex]->Name());
|
2013-04-02 12:52:17 -07:00
|
|
|
if (!volName.EqualsLiteral("")) {
|
|
|
|
// Note: The volume service is the only entity that should be able to
|
|
|
|
// modify the array of volumes. So we shouldn't have any issues with
|
|
|
|
// the array being modified under our feet (Since we're the volume
|
|
|
|
// service the array can't change until after we finish iterating the
|
|
|
|
// the loop).
|
|
|
|
nsresult rv = BroadcastVolume(volName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-04-18 07:13:23 -07:00
|
|
|
nsRefPtr<nsVolume> vol;
|
|
|
|
{
|
|
|
|
MonitorAutoLock autoLock(mArrayMonitor);
|
|
|
|
vol = FindVolumeByName(aVolName);
|
|
|
|
}
|
2012-12-14 16:01:34 -08:00
|
|
|
if (!vol) {
|
|
|
|
ERR("BroadcastVolume: Unable to locate volume '%s'",
|
|
|
|
NS_LossyConvertUTF16toASCII(aVolName).get());
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> obs = GetObserverService();
|
|
|
|
NS_ENSURE_TRUE(obs, NS_NOINTERFACE);
|
|
|
|
|
2013-01-28 14:34:30 -08:00
|
|
|
DBG("nsVolumeService::BroadcastVolume for '%s'", vol->NameStr().get());
|
2013-01-29 05:27:46 -08:00
|
|
|
NS_ConvertUTF8toUTF16 stateStr(vol->StateStr());
|
2012-12-14 16:01:34 -08:00
|
|
|
obs->NotifyObservers(vol, NS_VOLUME_STATE_CHANGED, stateStr.get());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-07 08:43:02 -08:00
|
|
|
NS_IMETHODIMP nsVolumeService::GetVolumeByName(const nsAString& aVolName, nsIVolume **aResult)
|
2012-07-16 09:38:18 -07:00
|
|
|
{
|
2013-04-18 07:13:23 -07:00
|
|
|
MonitorAutoLock autoLock(mArrayMonitor);
|
|
|
|
|
2012-07-16 09:38:18 -07:00
|
|
|
nsRefPtr<nsVolume> vol = FindVolumeByName(aVolName);
|
|
|
|
if (!vol) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2013-04-18 07:13:23 -07:00
|
|
|
vol.forget(aResult);
|
2012-07-16 09:38:18 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-18 07:13:23 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVolumeService::GetVolumeByPath(const nsAString& aPath, nsIVolume **aResult)
|
2012-07-16 09:38:18 -07:00
|
|
|
{
|
2013-06-03 01:41:27 -07:00
|
|
|
NS_ConvertUTF16toUTF8 utf8Path(aPath);
|
2012-07-16 09:38:18 -07:00
|
|
|
char realPathBuf[PATH_MAX];
|
|
|
|
|
2013-05-11 02:10:18 -07:00
|
|
|
while (realpath(utf8Path.get(), realPathBuf) < 0) {
|
|
|
|
if (errno != ENOENT) {
|
|
|
|
ERR("GetVolumeByPath: realpath on '%s' failed: %d", utf8Path.get(), errno);
|
|
|
|
return NSRESULT_FOR_ERRNO();
|
|
|
|
}
|
|
|
|
// The pathname we were passed doesn't exist, so we try stripping off trailing
|
|
|
|
// components until we get a successful call to realpath, or until we run out
|
|
|
|
// of components (if we finally get to /something then we also stop).
|
|
|
|
int32_t slashIndex = utf8Path.RFindChar('/');
|
|
|
|
if ((slashIndex == kNotFound) || (slashIndex == 0)) {
|
|
|
|
errno = ENOENT;
|
|
|
|
ERR("GetVolumeByPath: realpath on '%s' failed.", utf8Path.get());
|
|
|
|
return NSRESULT_FOR_ERRNO();
|
|
|
|
}
|
2013-06-03 01:41:27 -07:00
|
|
|
utf8Path.Assign(Substring(utf8Path, 0, slashIndex));
|
2012-07-16 09:38:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// The volume mount point is always a directory. Something like /mnt/sdcard
|
|
|
|
// Once we have a full qualified pathname with symlinks removed (which is
|
|
|
|
// what realpath does), we basically check if aPath starts with the mount
|
|
|
|
// point, but we don't want to have /mnt/sdcard match /mnt/sdcardfoo but we
|
|
|
|
// do want it to match /mnt/sdcard/foo
|
|
|
|
// So we add a trailing slash to the mount point and the pathname passed in
|
|
|
|
// prior to doing the comparison.
|
|
|
|
|
|
|
|
strlcat(realPathBuf, "/", sizeof(realPathBuf));
|
|
|
|
|
2013-04-18 07:13:23 -07:00
|
|
|
MonitorAutoLock autoLock(mArrayMonitor);
|
|
|
|
|
2013-04-02 12:52:17 -07:00
|
|
|
nsVolume::Array::size_type numVolumes = mVolumeArray.Length();
|
2012-07-16 09:38:18 -07:00
|
|
|
nsVolume::Array::index_type volIndex;
|
|
|
|
for (volIndex = 0; volIndex < numVolumes; volIndex++) {
|
|
|
|
nsRefPtr<nsVolume> vol = mVolumeArray[volIndex];
|
2013-06-03 01:41:27 -07:00
|
|
|
NS_ConvertUTF16toUTF8 volMountPointSlash(vol->MountPoint());
|
2012-07-16 09:38:18 -07:00
|
|
|
volMountPointSlash.Append(NS_LITERAL_CSTRING("/"));
|
|
|
|
nsDependentCSubstring testStr(realPathBuf, volMountPointSlash.Length());
|
|
|
|
if (volMountPointSlash.Equals(testStr)) {
|
2013-04-18 07:13:23 -07:00
|
|
|
vol.forget(aResult);
|
2012-07-16 09:38:18 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
2013-04-18 07:13:23 -07:00
|
|
|
return NS_ERROR_FILE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVolumeService::CreateOrGetVolumeByPath(const nsAString& aPath, nsIVolume** aResult)
|
|
|
|
{
|
|
|
|
nsresult rv = GetVolumeByPath(aPath, aResult);
|
|
|
|
if (rv == NS_OK) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-12-06 09:31:57 -08:00
|
|
|
|
2013-04-18 07:13:23 -07:00
|
|
|
// In order to support queries by the updater, we will fabricate a volume
|
|
|
|
// from the pathname, so that the caller can determine the volume size.
|
|
|
|
nsCOMPtr<nsIVolume> vol = new nsVolume(NS_LITERAL_STRING("fake"),
|
|
|
|
aPath, nsIVolume::STATE_MOUNTED,
|
2013-08-22 16:12:25 -07:00
|
|
|
-1 /* generation */,
|
|
|
|
true /* isMediaPresent*/,
|
|
|
|
false /* isSharing */);
|
2013-04-18 07:13:23 -07:00
|
|
|
vol.forget(aResult);
|
2012-12-06 09:31:57 -08:00
|
|
|
return NS_OK;
|
2012-07-16 09:38:18 -07:00
|
|
|
}
|
|
|
|
|
2013-04-18 07:13:23 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVolumeService::GetVolumeNames(nsTArray<nsString>& aVolNames)
|
2013-04-02 12:52:17 -07:00
|
|
|
{
|
2013-04-18 07:13:23 -07:00
|
|
|
MonitorAutoLock autoLock(mArrayMonitor);
|
|
|
|
|
2013-04-02 12:52:17 -07:00
|
|
|
nsVolume::Array::size_type numVolumes = mVolumeArray.Length();
|
|
|
|
nsVolume::Array::index_type volIndex;
|
|
|
|
for (volIndex = 0; volIndex < numVolumes; volIndex++) {
|
|
|
|
nsRefPtr<nsVolume> vol = mVolumeArray[volIndex];
|
|
|
|
aVolNames.AppendElement(vol->Name());
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-18 07:13:23 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVolumeService::CreateMountLock(const nsAString& aVolumeName, nsIVolumeMountLock **aResult)
|
2012-12-14 16:01:34 -08:00
|
|
|
{
|
2013-04-18 07:13:23 -07:00
|
|
|
nsCOMPtr<nsIVolumeMountLock> mountLock = nsVolumeMountLock::Create(aVolumeName);
|
2012-12-14 16:01:34 -08:00
|
|
|
if (!mountLock) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
2013-04-18 07:13:23 -07:00
|
|
|
mountLock.forget(aResult);
|
2012-12-14 16:01:34 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-18 07:13:23 -07:00
|
|
|
void
|
|
|
|
nsVolumeService::CheckMountLock(const nsAString& aMountLockName,
|
|
|
|
const nsAString& aMountLockState)
|
2012-12-14 16:01:34 -08:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-04-18 07:13:23 -07:00
|
|
|
nsRefPtr<nsVolume> vol = FindVolumeByMountLockName(aMountLockName);
|
|
|
|
if (vol) {
|
|
|
|
vol->UpdateMountLock(aMountLockState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsVolume>
|
|
|
|
nsVolumeService::FindVolumeByMountLockName(const nsAString& aMountLockName)
|
|
|
|
{
|
|
|
|
MonitorAutoLock autoLock(mArrayMonitor);
|
|
|
|
|
2013-04-02 12:52:17 -07:00
|
|
|
nsVolume::Array::size_type numVolumes = mVolumeArray.Length();
|
2012-12-14 16:01:34 -08:00
|
|
|
nsVolume::Array::index_type volIndex;
|
|
|
|
for (volIndex = 0; volIndex < numVolumes; volIndex++) {
|
|
|
|
nsRefPtr<nsVolume> vol = mVolumeArray[volIndex];
|
|
|
|
nsString mountLockName;
|
|
|
|
vol->GetMountLockName(mountLockName);
|
|
|
|
if (mountLockName.Equals(aMountLockName)) {
|
2013-04-18 07:13:23 -07:00
|
|
|
return vol.forget();
|
2012-12-14 16:01:34 -08:00
|
|
|
}
|
|
|
|
}
|
2013-04-18 07:13:23 -07:00
|
|
|
return nullptr;
|
2012-12-14 16:01:34 -08:00
|
|
|
}
|
|
|
|
|
2013-04-18 07:13:23 -07:00
|
|
|
already_AddRefed<nsVolume>
|
|
|
|
nsVolumeService::FindVolumeByName(const nsAString& aName)
|
2012-07-16 09:38:18 -07:00
|
|
|
{
|
2013-04-18 07:13:23 -07:00
|
|
|
mArrayMonitor.AssertCurrentThreadOwns();
|
2012-07-16 09:38:18 -07:00
|
|
|
|
2013-04-02 12:52:17 -07:00
|
|
|
nsVolume::Array::size_type numVolumes = mVolumeArray.Length();
|
2012-07-16 09:38:18 -07:00
|
|
|
nsVolume::Array::index_type volIndex;
|
|
|
|
for (volIndex = 0; volIndex < numVolumes; volIndex++) {
|
|
|
|
nsRefPtr<nsVolume> vol = mVolumeArray[volIndex];
|
|
|
|
if (vol->Name().Equals(aName)) {
|
|
|
|
return vol.forget();
|
|
|
|
}
|
|
|
|
}
|
2013-04-18 07:13:23 -07:00
|
|
|
return nullptr;
|
2012-07-16 09:38:18 -07:00
|
|
|
}
|
|
|
|
|
2012-12-14 16:01:34 -08:00
|
|
|
//static
|
2013-04-18 07:13:23 -07:00
|
|
|
already_AddRefed<nsVolume>
|
2013-07-08 23:37:47 -07:00
|
|
|
nsVolumeService::CreateOrFindVolumeByName(const nsAString& aName, bool aIsFake /*= false*/)
|
2012-07-16 09:38:18 -07:00
|
|
|
{
|
2013-04-18 07:13:23 -07:00
|
|
|
MonitorAutoLock autoLock(mArrayMonitor);
|
2012-07-16 09:38:18 -07:00
|
|
|
|
|
|
|
nsRefPtr<nsVolume> vol;
|
|
|
|
vol = FindVolumeByName(aName);
|
|
|
|
if (vol) {
|
|
|
|
return vol.forget();
|
|
|
|
}
|
|
|
|
// Volume not found - add a new one
|
|
|
|
vol = new nsVolume(aName);
|
2013-07-08 23:37:47 -07:00
|
|
|
vol->SetIsFake(aIsFake);
|
2012-07-16 09:38:18 -07:00
|
|
|
mVolumeArray.AppendElement(vol);
|
|
|
|
return vol.forget();
|
|
|
|
}
|
|
|
|
|
2013-04-18 07:13:23 -07:00
|
|
|
void
|
|
|
|
nsVolumeService::UpdateVolume(nsIVolume* aVolume)
|
2012-07-16 09:38:18 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-04-02 12:52:17 -07:00
|
|
|
nsString volName;
|
|
|
|
aVolume->GetName(volName);
|
2013-07-08 23:37:47 -07:00
|
|
|
bool aIsFake;
|
|
|
|
aVolume->GetIsFake(&aIsFake);
|
|
|
|
nsRefPtr<nsVolume> vol = CreateOrFindVolumeByName(volName, aIsFake);
|
2012-07-16 09:38:18 -07:00
|
|
|
if (vol->Equals(aVolume)) {
|
|
|
|
// Nothing has really changed. Don't bother telling anybody.
|
|
|
|
return;
|
|
|
|
}
|
2013-07-08 23:37:47 -07:00
|
|
|
|
|
|
|
if (!vol->IsFake() && aIsFake) {
|
|
|
|
// Prevent an incoming fake volume from overriding an existing real volume.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-16 09:38:18 -07:00
|
|
|
vol->Set(aVolume);
|
2012-08-02 17:28:59 -07:00
|
|
|
nsCOMPtr<nsIObserverService> obs = GetObserverService();
|
2012-07-16 09:38:18 -07:00
|
|
|
if (!obs) {
|
|
|
|
return;
|
|
|
|
}
|
2013-01-29 05:27:46 -08:00
|
|
|
NS_ConvertUTF8toUTF16 stateStr(vol->StateStr());
|
2012-07-16 09:38:18 -07:00
|
|
|
obs->NotifyObservers(vol, NS_VOLUME_STATE_CHANGED, stateStr.get());
|
|
|
|
}
|
|
|
|
|
2013-07-08 23:37:47 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVolumeService::CreateFakeVolume(const nsAString& name, const nsAString& path)
|
|
|
|
{
|
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
2013-08-22 16:12:25 -07:00
|
|
|
nsRefPtr<nsVolume> vol = new nsVolume(name, path, nsIVolume::STATE_INIT,
|
|
|
|
-1 /* mountGeneration */,
|
|
|
|
true /* isMediaPresent */,
|
|
|
|
false /* isSharing */);
|
2013-07-08 23:37:47 -07:00
|
|
|
vol->SetIsFake(true);
|
2013-07-29 16:41:07 -07:00
|
|
|
vol->LogState();
|
2013-07-08 23:37:47 -07:00
|
|
|
UpdateVolume(vol.get());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ContentChild::GetSingleton()->SendCreateFakeVolume(nsString(name), nsString(path));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsVolumeService::SetFakeVolumeState(const nsAString& name, int32_t state)
|
|
|
|
{
|
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
|
|
|
nsRefPtr<nsVolume> vol;
|
|
|
|
{
|
|
|
|
MonitorAutoLock autoLock(mArrayMonitor);
|
|
|
|
vol = FindVolumeByName(name);
|
|
|
|
}
|
|
|
|
if (!vol || !vol->IsFake()) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
vol->SetState(state);
|
2013-07-29 16:41:07 -07:00
|
|
|
vol->LogState();
|
2013-07-08 23:37:47 -07:00
|
|
|
UpdateVolume(vol.get());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ContentChild::GetSingleton()->SendSetFakeVolumeState(nsString(name), state);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-16 09:38:18 -07:00
|
|
|
/***************************************************************************
|
|
|
|
* The UpdateVolumeRunnable creates an nsVolume and updates the main thread
|
|
|
|
* data structure while running on the main thread.
|
|
|
|
*/
|
|
|
|
class UpdateVolumeRunnable : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2013-01-07 08:43:02 -08:00
|
|
|
UpdateVolumeRunnable(nsVolumeService* aVolumeService, const Volume* aVolume)
|
2012-12-14 16:01:34 -08:00
|
|
|
: mVolumeService(aVolumeService),
|
|
|
|
mVolume(new nsVolume(aVolume))
|
2012-07-16 09:38:18 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-08-22 16:12:25 -07:00
|
|
|
DBG("UpdateVolumeRunnable::Run '%s' state %s gen %d locked %d "
|
|
|
|
"media %d sharing %d",
|
2013-01-28 14:34:30 -08:00
|
|
|
mVolume->NameStr().get(), mVolume->StateStr(),
|
2013-08-22 16:12:25 -07:00
|
|
|
mVolume->MountGeneration(), (int)mVolume->IsMountLocked(),
|
|
|
|
(int)mVolume->IsMediaPresent(), mVolume->IsSharing());
|
2012-07-16 09:38:18 -07:00
|
|
|
|
2012-12-14 16:01:34 -08:00
|
|
|
mVolumeService->UpdateVolume(mVolume);
|
2013-04-18 07:13:23 -07:00
|
|
|
mVolumeService = nullptr;
|
|
|
|
mVolume = nullptr;
|
2012-07-16 09:38:18 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-12-14 16:01:34 -08:00
|
|
|
nsRefPtr<nsVolumeService> mVolumeService;
|
|
|
|
nsRefPtr<nsVolume> mVolume;
|
2012-07-16 09:38:18 -07:00
|
|
|
};
|
|
|
|
|
2013-04-18 07:13:23 -07:00
|
|
|
void
|
|
|
|
nsVolumeService::UpdateVolumeIOThread(const Volume* aVolume)
|
2012-07-16 09:38:18 -07:00
|
|
|
{
|
2013-08-22 16:12:25 -07:00
|
|
|
DBG("UpdateVolumeIOThread: Volume '%s' state %s mount '%s' gen %d locked %d "
|
|
|
|
"media %d sharing %d",
|
2012-12-14 16:01:34 -08:00
|
|
|
aVolume->NameStr(), aVolume->StateStr(), aVolume->MountPoint().get(),
|
2013-08-22 16:12:25 -07:00
|
|
|
aVolume->MountGeneration(), (int)aVolume->IsMountLocked(),
|
2013-10-18 20:21:52 -07:00
|
|
|
(int)aVolume->MediaPresent(), (int)aVolume->IsSharing());
|
2012-07-16 09:38:18 -07:00
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
2012-12-14 16:01:34 -08:00
|
|
|
NS_DispatchToMainThread(new UpdateVolumeRunnable(this, aVolume));
|
2012-07-16 09:38:18 -07:00
|
|
|
}
|
|
|
|
|
2012-12-14 16:01:34 -08:00
|
|
|
} // namespace system
|
|
|
|
} // namespace mozilla
|