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

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

mercurial