Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
nsMetricsService.cpp File Reference
#include "nsMetricsService.h"
#include "nsMetricsEventItem.h"
#include "nsIMetricsCollector.h"
#include "nsStringUtils.h"
#include "nsXPCOM.h"
#include "nsServiceManagerUtils.h"
#include "nsComponentManagerUtils.h"
#include "nsIFile.h"
#include "nsDirectoryServiceUtils.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsNetCID.h"
#include "nsIObserverService.h"
#include "nsIUploadChannel.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch2.h"
#include "nsIObserver.h"
#include "nsILocalFile.h"
#include "nsIPropertyBag.h"
#include "nsIProperty.h"
#include "nsIVariant.h"
#include "nsIDOMElement.h"
#include "nsIDOMDocument.h"
#include "nsIDOMSerializer.h"
#include "blapi.h"
#include "plbase64.h"
#include "nsISimpleEnumerator.h"
#include "nsIInputStreamChannel.h"
#include "nsIFileStreams.h"
#include "nsIBufferedStreams.h"
#include "nsIHttpChannel.h"
#include "nsIHttpProtocolHandler.h"
#include "nsIIOService.h"
#include "nsMultiplexInputStream.h"
#include "prtime.h"
#include "prmem.h"
#include "prprf.h"
#include "prrng.h"
#include "bzlib.h"
#include "nsIClassInfoImpl.h"
#include "nsIDocShellTreeItem.h"
#include "nsDocShellCID.h"
#include "nsMemory.h"
#include "nsIBadCertListener.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIX509Cert.h"
#include "nsAutoPtr.h"
#include "nsIDOMWindow.h"
#include "nsIDOMDocumentView.h"
#include "nsIDOMAbstractView.h"
#include "nsIStringStream.h"

Go to the source code of this file.

Classes

class  nsMetricsService::BadCertListener
struct  DisabledCollectorsClosure

Defines

#define nsString_h___
#define NS_METRICS_MIME_TYPE   "application/vnd.mozilla.metrics.bz2"
#define NS_EVENTLOG_FLUSH_POINT   64
#define NS_SECONDS_PER_DAY   (60 * 60 * 24)

Functions

static nsresult CompressBZ2 (nsIInputStream *src, PRFileDesc *outFd)
 NS_IMPL_THREADSAFE_ISUPPORTS2 (nsMetricsService::BadCertListener, nsIBadCertListener, nsIInterfaceRequestor) NS_IMETHODIMP nsMetricsService
 NS_IMPL_ISUPPORTS6_CI (nsMetricsService, nsIMetricsService, nsIAboutModule, nsIStreamListener, nsIRequestObserver, nsIObserver, nsITimerCallback) NS_IMETHODIMP nsMetricsService
static NS_METHOD CopySegmentToStream (nsIInputStream *inStr, void *closure, const char *buffer, PRUint32 offset, PRUint32 count, PRUint32 *countWritten)

Variables

static const char kQuitApplicationTopic [] = "quit-application"
static const char kUploadTimePref [] = "metrics.upload.next-time"
static const char kPingTimePref [] = "metrics.upload.next-ping"
static const char kEventCountPref [] = "metrics.event-count"
static const char kEnablePref [] = "metrics.upload.enable"

Define Documentation

Definition at line 106 of file nsMetricsService.cpp.

#define NS_METRICS_MIME_TYPE   "application/vnd.mozilla.metrics.bz2"

Definition at line 102 of file nsMetricsService.cpp.

#define NS_SECONDS_PER_DAY   (60 * 60 * 24)

Definition at line 108 of file nsMetricsService.cpp.

Definition at line 94 of file nsMetricsService.cpp.


Function Documentation

static nsresult CompressBZ2 ( nsIInputStream src,
PRFileDesc outFd 
) [static]

Definition at line 130 of file nsMetricsService.cpp.

{
  // compress the data chunk-by-chunk

  char inbuf[4096], outbuf[4096];
  bz_stream strm;
  int ret = BZ_OK;

  memset(&strm, 0, sizeof(strm));

  if (BZ2_bzCompressInit(&strm, 9 /*max blocksize*/, 0, 0) != BZ_OK)
    return NS_ERROR_OUT_OF_MEMORY;

  nsresult rv = NS_OK;
  int action = BZ_RUN;
  for (;;) {
    PRUint32 bytesRead = 0;
    if (action == BZ_RUN && strm.avail_in == 0) {
      // fill inbuf
      rv = src->Read(inbuf, sizeof(inbuf), &bytesRead);
      if (NS_FAILED(rv))
        break;
      strm.next_in = inbuf;
      strm.avail_in = (int) bytesRead;
    }

    strm.next_out = outbuf;
    strm.avail_out = sizeof(outbuf);

    ret = BZ2_bzCompress(&strm, action);
    if (action == BZ_RUN) {
      if (ret != BZ_RUN_OK) {
        MS_LOG(("BZ2_bzCompress/RUN failed: %d", ret));
        rv = NS_ERROR_UNEXPECTED;
        break;
      }

      if (bytesRead < sizeof(inbuf)) {
        // We're done now, tell libbz2 to finish
        action = BZ_FINISH;
      }
    } else if (ret != BZ_FINISH_OK && ret != BZ_STREAM_END) {
      MS_LOG(("BZ2_bzCompress/FINISH failed: %d", ret));
      rv = NS_ERROR_UNEXPECTED;
      break;
    }

    if (strm.avail_out < sizeof(outbuf)) {
      PRInt32 n = sizeof(outbuf) - strm.avail_out;
      if (PR_Write(outFd, outbuf, n) != n) {
        MS_LOG(("Failed to write compressed file"));
        rv = NS_ERROR_UNEXPECTED;
        break;
      }
    }

    if (ret == BZ_STREAM_END)
      break;
  }

  BZ2_bzCompressEnd(&strm);
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static NS_METHOD CopySegmentToStream ( nsIInputStream inStr,
void closure,
const char *  buffer,
PRUint32  offset,
PRUint32  count,
PRUint32 countWritten 
) [static]

Definition at line 940 of file nsMetricsService.cpp.

{
  nsIOutputStream *outStr = NS_STATIC_CAST(nsIOutputStream *, closure);
  *countWritten = 0;
  while (count) {
    PRUint32 n;
    nsresult rv = outStr->Write(buffer, count, &n);
    if (NS_FAILED(rv))
      return rv;
    buffer += n;
    count -= n;
    *countWritten += n;
  }
  return NS_OK;
}

Definition at line 317 of file nsMetricsService.cpp.

{
  *result = nsnull;

  nsMetricsEventItem *item = new nsMetricsEventItem(itemNamespace, itemName);
  NS_ENSURE_TRUE(item, NS_ERROR_OUT_OF_MEMORY);

  NS_ADDREF(*result = item);
  return NS_OK;
}

Here is the call graph for this function:

Definition at line 215 of file nsMetricsService.cpp.

{
  *result = PR_FALSE;
  return NS_OK;
}

Variable Documentation

const char kEnablePref[] = "metrics.upload.enable" [static]

Definition at line 119 of file nsMetricsService.cpp.

const char kEventCountPref[] = "metrics.event-count" [static]

Definition at line 118 of file nsMetricsService.cpp.

const char kPingTimePref[] = "metrics.upload.next-ping" [static]

Definition at line 117 of file nsMetricsService.cpp.

const char kQuitApplicationTopic[] = "quit-application" [static]

Definition at line 115 of file nsMetricsService.cpp.

const char kUploadTimePref[] = "metrics.upload.next-time" [static]

Definition at line 116 of file nsMetricsService.cpp.