Back to index

lightning-sunbird  0.9+nobinonly
nsMetricsConfig.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* vim:set ts=2 sw=2 sts=2 et cindent: */
00003 /* ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is the Metrics extension.
00017  *
00018  * The Initial Developer of the Original Code is Google Inc.
00019  * Portions created by the Initial Developer are Copyright (C) 2006
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *  Darin Fisher <darin@meer.net>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef nsMetricsConfig_h__
00040 #define nsMetricsConfig_h__
00041 
00042 #include "nsDataHashtable.h"
00043 #include "nsHashKeys.h"
00044 
00045 class nsIDOMElement;
00046 class nsIFile;
00047 class nsILocalFile;
00048 template<class E> class nsTArray;
00049 
00050 class nsMetricsConfig
00051 {
00052 public:
00053   nsMetricsConfig();
00054   ~nsMetricsConfig() {}
00055 
00059   PRBool Init();
00060 
00064   void Reset();
00065 
00069   nsresult Load(nsIFile *file);
00070 
00074   nsresult Save(nsILocalFile *file);
00075 
00080   PRBool IsEventEnabled(const nsAString &eventNS,
00081                         const nsAString &eventName) const;
00082 
00086   void SetEventEnabled(const nsAString &eventNS,
00087                        const nsAString &eventName, PRBool enabled);
00088 
00093   void GetEvents(nsTArray<nsString> &events);
00094 
00098   void ClearEvents();
00099 
00103   PRInt32 EventLimit() const {
00104     NS_ASSERTION(mEventSet.IsInitialized(),
00105                  "nsMetricsConfig::Init not called");
00106     return mEventLimit;
00107   }
00108 
00112   void SetEventLimit(PRInt32 limit) {
00113     NS_ASSERTION(mEventSet.IsInitialized(),
00114                  "nsMetricsConfig::Init not called");
00115     mEventLimit = limit;
00116   }
00117 
00121   PRInt32 UploadInterval() const {
00122     NS_ASSERTION(mEventSet.IsInitialized(),
00123                  "nsMetricsConfig::Init not called");
00124     return mUploadInterval;
00125   }
00126 
00130   void SetUploadInterval(PRInt32 uploadInterval) {
00131     NS_ASSERTION(mEventSet.IsInitialized(),
00132                  "nsMetricsConfig::Init not called");
00133     mUploadInterval = uploadInterval;
00134   }
00135 
00139   PRBool HasConfig() const {
00140     NS_ASSERTION(mEventSet.IsInitialized(),
00141                  "nsMetricsConfig::Init not called");
00142     return mHasConfig;
00143   }
00144 
00145 private:
00146   typedef void (nsMetricsConfig::*ForEachChildElementCallback)(nsIDOMElement *);
00147 
00148   // Run a callback method for each child element of the given element.
00149   void ForEachChildElement(nsIDOMElement *elem, ForEachChildElementCallback cb);
00150 
00151   void ProcessToplevelElement(nsIDOMElement *elem);
00152   void ProcessConfigChild(nsIDOMElement *elem);
00153   void ProcessCollectorElement(nsIDOMElement *elem);
00154 
00155   static PLDHashOperator PR_CALLBACK CopyKey(nsStringHashKey *key,
00156                                              void *userData);
00157 
00158   nsTHashtable<nsStringHashKey> mEventSet;
00159   nsDataHashtable<nsStringHashKey,nsString> mNSURIToPrefixMap;
00160   PRInt32 mEventLimit;
00161   PRInt32 mUploadInterval;
00162   PRBool mHasConfig;
00163 };
00164 
00165 #endif  // nsMetricsConfig_h__