sbMetadataCrashTracker.h
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2010 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the ``GPL'').
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
30 #ifndef SBMETADATACRASHTRACKER_H_
31 #define SBMETADATACRASHTRACKER_H_
32 
33 // INCLUDES ===================================================================
34 
35 // TODO cleanup
36 #include <nscore.h>
37 #include <prlock.h>
38 #include <prmon.h>
39 #include <nsAutoLock.h>
40 #include <nsStringGlue.h>
41 #include <nsTArray.h>
42 #include <nsCOMArray.h>
43 #include <nsCOMPtr.h>
44 #include <nsAutoPtr.h>
45 #include <nsISupports.h>
46 #include <nsIOutputStream.h>
47 #include <nsIFile.h>
48 #include <nsDataHashtable.h>
49 
50 
51 
52 // CLASSES ====================================================================
53 
71 {
72 public:
74 
76  virtual ~sbMetadataCrashTracker();
77 
82  nsresult Init();
83 
87  nsresult StartLog();
88 
96  nsresult ResetLog();
97 
102  nsresult LogURLBegin(const nsACString& aURL);
103 
108  nsresult LogURLEnd(const nsACString& aURL);
109 
114  nsresult IsURLBlacklisted(const nsACString& aURL,
115  PRBool* aIsBlackListed);
116 
123  nsresult AddBlacklistURL(const nsACString& aURL);
124 
125 private:
126 
131  nsresult ProcessExistingLog();
132 
137  static PLDHashOperator PR_CALLBACK
138  AddURLsToBlacklist(nsCStringHashKey::KeyType aKey,
139  nsCString aEntry,
140  void* aUserData);
141 
146  static PLDHashOperator PR_CALLBACK
147  WriteBlacklistURLToFile(nsCStringHashKey::KeyType aKey,
148  PRBool aEntry,
149  void* aUserData);
150 
154  nsresult ReadBlacklist();
155 
159  nsresult WriteBlacklist();
160 
164  nsresult GetProfileFile(const nsAString& aName, nsIFile** aFile);
165 
166 
167 
168  nsCOMPtr<nsIFile> mBlacklistFile;
169  nsDataHashtable<nsCStringHashKey, PRBool> mURLBlacklist;
170 
171  // Rather than log the URL for both begin and complete we
172  // assign each URL a number. This cuts the log file size in half.
173  PRUint32 mCounter;
174  nsDataHashtable<nsCStringHashKey, PRUint32> mURLToIndexMap;
175 
176  nsCOMPtr<nsIFile> mLogFile;
177  nsCOMPtr<nsIOutputStream> mOutputStream;
178  PRLock* mLock;
179 
180  // Value of songbird.metadata.simulate.crash.url, if set
181  nsCString mSimulateCrashURL;
182 };
183 
184 #endif // SBMETADATACRASHTRACKER_H_
nsresult IsURLBlacklisted(const nsACString &aURL, PRBool *aIsBlackListed)
nsresult LogURLEnd(const nsACString &aURL)
nsresult AddBlacklistURL(const nsACString &aURL)
_updateCookies aName
nsresult LogURLBegin(const nsACString &aURL)
NS_DECL_ISUPPORTS sbMetadataCrashTracker()