dom/system/gonk/OpenFileFinder.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     3  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #ifndef mozilla_system_openfilefinder_h__
     6 #define mozilla_system_openfilefinder_h__
     8 #include "nsString.h"
    10 #include <dirent.h>
    12 namespace mozilla {
    13 namespace system {
    15 class OpenFileFinder
    16 {
    17 public:
    18   enum State
    19   {
    20     NEXT_PID,
    21     CHECK_FDS,
    22     DONE
    23   };
    24   class Info
    25   {
    26   public:
    27     nsCString mFileName;  // name of the the open file
    28     nsCString mAppName;   // App which has the file open (if it's a b2g app)
    29     pid_t     mPid;       // pid of the process which has the file open
    30     nsCString mComm;      // comm associated with pid
    31     nsCString mExe;       // executable name associated with pid
    32     bool      mIsB2gOrDescendant; // this is b2g/its descendant or not
    33   };
    35   OpenFileFinder(const nsACString& aPath, bool aCheckIsB2gOrDescendant = true);
    36   ~OpenFileFinder();
    38   bool First(Info* aInfo);  // Return the first open file
    39   bool Next(Info* aInfo);   // Return the next open file
    40   void Close();
    42 private:
    44   void FillInfo(Info *aInfo, const nsACString& aPath);
    45   bool ReadSymLink(const nsACString& aSymLink, nsACString& aOutPath);
    46   bool PathMatches(const nsACString& aPath)
    47   {
    48     return Substring(aPath, 0, mPath.Length()).Equals(mPath);
    49   }
    51   State     mState;   // Keeps track of what we're doing.
    52   nsCString mPath;    // Only report files contained within this directory tree
    53   DIR*      mProcDir; // Used for scanning /proc
    54   DIR*      mFdDir;   // Used for scanning /proc/PID/fd
    55   int       mPid;     // PID currently being processed
    56   pid_t     mMyPid;   // PID of parent process, we assume we're running on it.
    57   bool      mCheckIsB2gOrDescendant; // Do we care about non-b2g process?
    58 };
    60 } // system
    61 } // mozilla
    63 #endif  // mozilla_system_nsvolume_h__

mercurial