Back to index

lightning-sunbird  0.9+nobinonly
nsLoadCollector.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  *  Brian Ryner <bryner@brianryner.com>
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 nsLoadCollector_h_
00040 #define nsLoadCollector_h_
00041 
00042 // This file defines the load collector class, which monitors requests using
00043 // the document loader service and records the events into the metrics service.
00044 //
00045 // The load collector logs <document action="load"/> events.
00046 // This event has the following attributes:
00047 //
00048 // origin: The action which initiated the load (string).  Possible values are:
00049 //         "typed": The user typed or pasted the URI into the location bar.
00050 //         "link": The user followed a link to the URI.
00051 //         "reload": The user reloaded the URI.
00052 //         "refresh": A meta-refresh caused the URI to be loaded.
00053 //         "session-history": The user used back/forward to load the URI.
00054 //         "global-history": The user selected the URI from global history.
00055 //         "bookmark": The user selected the URI from bookmarks.
00056 //         "external": An external application passed in the URI to load.
00057 //         "other": Any origin not listed above.
00058 //
00059 // bfCacheHit: The document presentation was restored from the
00060 //             session history cache (boolean).
00061 //
00062 // window: The id of the window where the document loaded (uint16).
00063 // loadtime: The elapsed time for the load, in milliseconds (uint32).
00064 
00065 #include "nsIMetricsCollector.h"
00066 #include "nsIWebProgressListener.h"
00067 #include "nsIWritablePropertyBag2.h"
00068 #include "nsWeakReference.h"
00069 #include "nsDataHashtable.h"
00070 #include "nsAutoPtr.h"
00071 #include "nsIDocumentObserver.h"
00072 #include "nsPtrHashKey.h"
00073 
00074 class nsIDocument;
00075 
00076 class nsLoadCollector : public nsIMetricsCollector,
00077                         public nsIWebProgressListener,
00078                         public nsIDocumentObserver,
00079                         public nsSupportsWeakReference
00080 {
00081  public:
00082   NS_DECL_ISUPPORTS
00083   NS_DECL_NSIMETRICSCOLLECTOR
00084   NS_DECL_NSIWEBPROGRESSLISTENER
00085   NS_DECL_NSIDOCUMENTOBSERVER
00086 
00087   nsLoadCollector();
00088   nsresult Init();
00089 
00090  private:
00091   struct RequestEntry {
00092     nsCOMPtr<nsIWritablePropertyBag2> properties;
00093     PRTime startTime;
00094   };
00095 
00096   struct DocumentEntry {
00097     PRUint32 docID;
00098     PRUint32 windowID;
00099     PRBool subframe;
00100   };
00101 
00102   ~nsLoadCollector();
00103 
00104   // Callback for removing a document observer and map entry
00105   static PLDHashOperator PR_CALLBACK
00106   RemoveDocumentFromMap(const nsIDocument *document,
00107                         DocumentEntry &entry, void *userData);
00108 
00109   // Hash table mapping nsIRequest objects to their event properties.
00110   nsDataHashtable<nsISupportsHashKey, RequestEntry> mRequestMap;
00111 
00112   // Documents we're currently listening to, and their associated ids
00113   nsDataHashtable< nsPtrHashKey<nsIDocument>, DocumentEntry > mDocumentMap;
00114 
00115   // The next document id we'll assign
00116   PRUint32 mNextDocID;
00117 };
00118 
00119 #define NS_LOADCOLLECTOR_CLASSNAME "Load Collector"
00120 #define NS_LOADCOLLECTOR_CID \
00121 { 0xa97357a0, 0xa2f3, 0x4b1f, {0x93, 0xd3, 0x36, 0xdc, 0xb7, 0xee, 0x24, 0x63}}
00122 
00123 #endif // nsLoadCollector_h_