LCOV - code coverage report
Current view: directory - gfx/src - gfxCrashReporterUtils.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 23 0 0.0 %
Date: 2012-06-02 Functions: 8 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is Mozilla Corporation code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is Mozilla Foundation.
      18                 :  * Portions created by the Initial Developer are Copyright (C) 2011
      19                 :  * the Initial Developer. All Rights Reserved.
      20                 :  *
      21                 :  * Alternatively, the contents of this file may be used under the terms of
      22                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      23                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      24                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      25                 :  * of those above. If you wish to allow use of your version of this file only
      26                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      27                 :  * use your version of this file under the terms of the MPL, indicate your
      28                 :  * decision by deleting the provisions above and replace them with the notice
      29                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      30                 :  * the provisions above, a recipient may use your version of this file under
      31                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      32                 :  *
      33                 :  * ***** END LICENSE BLOCK ***** */
      34                 : 
      35                 : #include "gfxCrashReporterUtils.h"
      36                 : 
      37                 : #if defined(MOZ_CRASHREPORTER)
      38                 : #define MOZ_GFXFEATUREREPORTER 1
      39                 : #endif
      40                 : 
      41                 : #ifdef MOZ_GFXFEATUREREPORTER
      42                 : #include "nsExceptionHandler.h"
      43                 : #include "nsString.h"
      44                 : #include "nsIObserverService.h"
      45                 : #include "nsIObserver.h"
      46                 : #include "nsAutoPtr.h"
      47                 : #include "nsServiceManagerUtils.h"
      48                 : #include "mozilla/Services.h"
      49                 : 
      50                 : namespace mozilla {
      51                 : 
      52                 : static nsTArray<nsCString> *gFeaturesAlreadyReported = nsnull;
      53                 : 
      54                 : class ObserverToDestroyFeaturesAlreadyReported : public nsIObserver
      55                 : {
      56                 : 
      57                 : public:
      58                 :   NS_DECL_ISUPPORTS
      59                 :   NS_DECL_NSIOBSERVER
      60                 : 
      61               0 :   ObserverToDestroyFeaturesAlreadyReported() {}
      62               0 :   virtual ~ObserverToDestroyFeaturesAlreadyReported() {}
      63                 : };
      64                 : 
      65               0 : NS_IMPL_ISUPPORTS1(ObserverToDestroyFeaturesAlreadyReported,
      66                 :                    nsIObserver)
      67                 : 
      68                 : NS_IMETHODIMP
      69               0 : ObserverToDestroyFeaturesAlreadyReported::Observe(nsISupports* aSubject,
      70                 :                                                   const char* aTopic,
      71                 :                                                   const PRUnichar* aData)
      72                 : {
      73               0 :   if (!strcmp(aTopic, "xpcom-shutdown")) {
      74               0 :     if (gFeaturesAlreadyReported) {
      75               0 :       delete gFeaturesAlreadyReported;
      76               0 :       gFeaturesAlreadyReported = nsnull;
      77                 :     }
      78                 :   }
      79               0 :   return NS_OK;
      80                 : }
      81                 : 
      82                 : 
      83                 : void
      84               0 : ScopedGfxFeatureReporter::WriteAppNote(char statusChar)
      85                 : {
      86                 :   // LeakLog made me do this. Basically, I just wanted gFeaturesAlreadyReported to be a static nsTArray<nsCString>,
      87                 :   // and LeakLog was complaining about leaks like this:
      88                 :   //    leaked 1 instance of nsTArray_base with size 8 bytes
      89                 :   //    leaked 7 instances of nsStringBuffer with size 8 bytes each (56 bytes total)
      90                 :   // So this is a work-around using a pointer, and using a nsIObserver to deallocate on xpcom shutdown.
      91                 :   // Yay for fighting bloat.
      92               0 :   if (!gFeaturesAlreadyReported) {
      93               0 :     nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
      94               0 :     if (!observerService)
      95                 :       return;
      96               0 :     nsRefPtr<ObserverToDestroyFeaturesAlreadyReported> observer = new ObserverToDestroyFeaturesAlreadyReported;
      97               0 :     nsresult rv = observerService->AddObserver(observer, "xpcom-shutdown", false);
      98               0 :     if (NS_FAILED(rv)) {
      99               0 :       observer = nsnull;
     100                 :       return;
     101                 :     }
     102               0 :     gFeaturesAlreadyReported = new nsTArray<nsCString>;
     103                 :   }
     104                 : 
     105               0 :   nsCAutoString featureString;
     106                 :   featureString.AppendPrintf("%s%c ",
     107                 :                              mFeature,
     108               0 :                              statusChar);
     109                 : 
     110               0 :   if (!gFeaturesAlreadyReported->Contains(featureString)) {
     111               0 :     gFeaturesAlreadyReported->AppendElement(featureString);
     112               0 :     CrashReporter::AppendAppNotesToCrashReport(featureString);
     113                 :   }
     114                 : }
     115                 : 
     116                 : } // end namespace mozilla
     117                 : 
     118                 : #else
     119                 : 
     120                 : namespace mozilla {
     121                 : void ScopedGfxFeatureReporter::WriteAppNote(char) {}
     122                 : }
     123                 : 
     124                 : #endif

Generated by: LCOV version 1.7