gecko/netwerk/ipc/RemoteOpenFileChild.h
Nathan Froyd e4e2da55c9 Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat
The bulk of this commit was generated with a script, executed at the top
level of a typical source code checkout.  The only non-machine-generated
part was modifying MFBT's moz.build to reflect the new naming.

CLOSED TREE makes big refactorings like this a piece of cake.

 # The main substitution.
find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \
    xargs perl -p -i -e '
 s/nsRefPtr\.h/RefPtr\.h/g; # handle includes
 s/nsRefPtr ?</RefPtr</g;   # handle declarations and variables
'

 # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h.
perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h

 # Handle nsRefPtr.h itself, a couple places that define constructors
 # from nsRefPtr, and code generators specially.  We do this here, rather
 # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename
 # things like nsRefPtrHashtable.
perl -p -i -e 's/nsRefPtr/RefPtr/g' \
     mfbt/nsRefPtr.h \
     xpcom/glue/nsCOMPtr.h \
     xpcom/base/OwningNonNull.h \
     ipc/ipdl/ipdl/lower.py \
     ipc/ipdl/ipdl/builtin.py \
     dom/bindings/Codegen.py \
     python/lldbutils/lldbutils/utils.py

 # In our indiscriminate substitution above, we renamed
 # nsRefPtrGetterAddRefs, the class behind getter_AddRefs.  Fix that up.
find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \
    xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g'

if [ -d .git ]; then
    git mv mfbt/nsRefPtr.h mfbt/RefPtr.h
else
    hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h
fi
2015-10-18 01:24:48 -04:00

123 lines
3.7 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set sw=2 ts=8 et tw=80 : */
/* 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/. */
#ifndef _RemoteOpenFileChild_h
#define _RemoteOpenFileChild_h
#include "mozilla/Attributes.h"
#include "mozilla/dom/TabChild.h"
#include "mozilla/net/PRemoteOpenFileChild.h"
#include "nsICachedFileDescriptorListener.h"
#include "nsILocalFile.h"
#include "nsIRemoteOpenFileListener.h"
class nsILoadContext;
namespace mozilla {
namespace ipc {
class FileDescriptor;
} // namespace ipc
namespace net {
/**
* RemoteOpenFileChild: a thin wrapper around regular nsIFile classes that does
* IPC to open a file handle on parent instead of child. Used when we can't
* open file handle on child (don't have permission), but we don't want the
* overhead of shipping all I/O traffic across IPDL. Example: JAR files.
*
* To open a file handle with this class, AsyncRemoteFileOpen() must be called
* first. After the listener's OnRemoteFileOpenComplete() is called, if the
* result is NS_OK, nsIFile.OpenNSPRFileDesc() may be called to get a
* duplicated file descriptor.
*
* Note that the file descriptor returned by NSPRFileDesc() is duplicated from
* the original, which shares its file offset with the original. If the file
* offset is modified (ex: by lseek/read/write) on one of the shared
* descriptors, the offset is also changed for the other. It can be safely
* used only with operations that take absolute offsets, such as
* mmap/pread/pwrite.
*
* This class should only be instantiated in a child process.
*
*/
class RemoteOpenFileChild final
: public PRemoteOpenFileChild
, public nsIFile
, public nsIHashable
, public nsICachedFileDescriptorListener
{
typedef mozilla::dom::TabChild TabChild;
typedef mozilla::ipc::FileDescriptor FileDescriptor;
virtual ~RemoteOpenFileChild();
public:
RemoteOpenFileChild()
: mNSPRFileDesc(nullptr)
, mAsyncOpenCalled(false)
, mNSPROpenCalled(false)
{}
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIFILE
NS_DECL_NSIHASHABLE
// aRemoteOpenUri must be scheme 'remoteopenfile://': otherwise looks like
// a file:// uri.
nsresult Init(nsIURI* aRemoteOpenUri, nsIURI* aAppUri);
// Send message to parent to tell it to open file handle for file.
// TabChild is required, for IPC security.
// Note: currently only PR_RDONLY is supported for 'flags'
nsresult AsyncRemoteFileOpen(int32_t aFlags,
nsIRemoteOpenFileListener* aListener,
nsITabChild* aTabChild,
nsILoadContext *aLoadContext);
nsresult SetNSPRFileDesc(PRFileDesc* aNSPRFileDesc);
void ReleaseIPDLReference()
{
Release();
}
private:
RemoteOpenFileChild(const RemoteOpenFileChild& other);
protected:
void AddIPDLReference()
{
AddRef();
}
virtual bool Recv__delete__(const FileDescriptor&) override;
virtual void OnCachedFileDescriptor(const nsAString& aPath,
const FileDescriptor& aFD) override;
void HandleFileDescriptorAndNotifyListener(const FileDescriptor&,
bool aFromRecvDelete);
void NotifyListener(nsresult aResult);
// regular nsIFile object, that we forward most calls to.
nsCOMPtr<nsIFile> mFile;
nsCOMPtr<nsIURI> mURI;
nsCOMPtr<nsIURI> mAppURI;
nsCOMPtr<nsIRemoteOpenFileListener> mListener;
RefPtr<TabChild> mTabChild;
PRFileDesc* mNSPRFileDesc;
bool mAsyncOpenCalled;
bool mNSPROpenCalled;
};
} // namespace net
} // namespace mozilla
#endif // _RemoteOpenFileChild_h