Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
nsUrlClassifierDBService.cpp File Reference
#include "mozIStorageService.h"
#include "mozIStorageConnection.h"
#include "mozIStorageStatement.h"
#include "mozStorageCID.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsAutoLock.h"
#include "nsCOMPtr.h"
#include "nsCRT.h"
#include "nsIDirectoryService.h"
#include "nsIEventQueueService.h"
#include "nsIObserverService.h"
#include "nsIProperties.h"
#include "nsIProxyObjectManager.h"
#include "nsToolkitCompsCID.h"
#include "nsUrlClassifierDBService.h"
#include "nsString.h"
#include "nsTArray.h"
#include "plevent.h"
#include "prlog.h"
#include "prmon.h"
#include "prthread.h"
#include "prprf.h"
#include "nsProxyRelease.h"
#include "nsEventQueueUtils.h"

Go to the source code of this file.

Classes

class  nsUrlClassifierCallbackWrapper

Defines

#define LOG(args)
#define DATABASE_FILENAME   "urlclassifier2.sqlite"

Functions

static NS_DEFINE_CID (kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID)
static NS_DEFINE_CID (kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID)
 PR_STATIC_CALLBACK (void) EventLoop(void *arg)
static void Rot13Line (nsCString &line)
 NS_IMPL_THREADSAFE_ISUPPORTS1 (nsUrlClassifierCallbackWrapper, nsIUrlClassifierCallback) class nsUrlClassifierDBServiceWorker
 NS_IMPL_THREADSAFE_ISUPPORTS1 (nsUrlClassifierDBServiceWorker, nsIUrlClassifierDBServiceWorker) nsUrlClassifierDBServiceWorker
 NS_IMPL_THREADSAFE_ISUPPORTS2 (nsUrlClassifierDBService, nsIUrlClassifierDBService, nsIObserver) nsUrlClassifierDBService *nsUrlClassifierDBService
 PR_STATIC_CALLBACK (void *) EventHandler(PLEvent *ev)
 EventLoop (void *arg)
 EventHandler (PLEvent *ev)
 DestroyHandler (PLEvent *ev)

Variables

static nsUrlClassifierDBServicesUrlClassifierDBService
static nsIEventQueuegEventQ = nsnull
static PRMonitorgMonitor = nsnull
static PRThreadgDbBackgroundThread = nsnull
static PRBool gShuttingDownThread = PR_FALSE
static const char * kNEW_TABLE_SUFFIX = "_new"
static PRBool gKeepRunning = PR_TRUE
static const unsigned char kRot13Table [256]

Define Documentation

#define DATABASE_FILENAME   "urlclassifier2.sqlite"

Definition at line 72 of file nsUrlClassifierDBService.cpp.

#define LOG (   args)

Definition at line 68 of file nsUrlClassifierDBService.cpp.


Function Documentation

static void DestroyHandler ( PLEvent ev)

Definition at line 1201 of file nsUrlClassifierDBService.cpp.

{
  delete ev;
}

Here is the caller graph for this function:

static void * EventHandler ( PLEvent ev)

Definition at line 1193 of file nsUrlClassifierDBService.cpp.

{
  gKeepRunning = PR_FALSE;
  return nsnull;
}
EventLoop ( void arg)

Definition at line 1150 of file nsUrlClassifierDBService.cpp.

{
  nsresult rv;
  LOG(("Starting background thread.\n"));

  nsCOMPtr<nsIEventQueueService> eventQService =
      do_GetService(kEventQueueServiceCID, &rv);
  NS_ASSERTION(NS_SUCCEEDED(rv), "do_GetService(EventQueueService)");

  rv = eventQService->CreateMonitoredThreadEventQueue();
  NS_ASSERTION(NS_SUCCEEDED(rv), "CreateMonitoredThreadEventQueue");

  {
    nsAutoMonitor mon(gMonitor);
    rv = eventQService->GetSpecialEventQueue(
                    nsIEventQueueService::CURRENT_THREAD_EVENT_QUEUE,
                    &gEventQ);
    NS_ASSERTION(NS_SUCCEEDED(rv), "GetSpecialEventQueue");

    PR_Notify(gMonitor);
  }

  while (gKeepRunning) {
    PLEvent* ev;
    if (NS_SUCCEEDED(gEventQ->WaitForEvent(&ev))) {
      gEventQ->HandleEvent(ev);
    }
  }

  rv = gEventQ->ProcessPendingEvents();

  // Have mWorker release the hold on the event queue.
  eventQService->DestroyThreadEventQueue();

  // Release the event queue for clean up.
  NS_RELEASE(gEventQ);
  gEventQ = nsnull;

  LOG(("Exiting background thread.\n"));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static NS_DEFINE_CID ( kProxyObjectManagerCID  ,
NS_PROXYEVENT_MANAGER_CID   
) [static]

Definition at line 172 of file nsUrlClassifierDBService.cpp.

                                     : public nsIUrlClassifierDBServiceWorker
{
public:
  nsUrlClassifierDBServiceWorker();

  NS_DECL_ISUPPORTS
  NS_DECL_NSIURLCLASSIFIERDBSERVICE
  NS_DECL_NSIURLCLASSIFIERDBSERVICEWORKER

private:
  // No subclassing
  ~nsUrlClassifierDBServiceWorker();

  // Disallow copy constructor
  nsUrlClassifierDBServiceWorker(nsUrlClassifierDBServiceWorker&);

  // Table names have hyphens in them, which SQL doesn't allow,
  // so we convert them to underscores.
  void GetDbTableName(const nsACString& aTableName, nsCString* aDbTableName);

  // Try to open the db, DATABASE_FILENAME.
  nsresult OpenDb();

  // Create a table in the db if it doesn't exist.
  nsresult MaybeCreateTable(const nsCString& aTableName);

  // Drop a table if it exists.
  nsresult MaybeDropTable(const nsCString& aTableName);

  // If this is not an update request, swap the new table
  // in for the old table.
  nsresult MaybeSwapTables(const nsCString& aVersionLine);

  // Parse a version string of the form [table-name #.###] or
  // [table-name #.### update] and return the table name and
  // whether or not it's an update.
  nsresult ParseVersionString(const nsCSubstring& aLine,
                              nsCString* aTableName,
                              PRBool* aIsUpdate);

  // Handle a new table line of the form [table-name #.####].  We create the
  // table if it doesn't exist and set the aTableName, aUpdateStatement,
  // and aDeleteStatement.
  nsresult ProcessNewTable(const nsCSubstring& aLine,
                           nsCString* aTableName,
                           mozIStorageStatement** aUpdateStatement,
                           mozIStorageStatement** aDeleteStatement);

  // Handle an add or remove line.  We execute additional update or delete
  // statements.
  nsresult ProcessUpdateTable(const nsCSubstring& aLine,
                              const nsCString& aTableName,
                              mozIStorageStatement* aUpdateStatement,
                              mozIStorageStatement* aDeleteStatement);

  // Holds a connection to the Db.  We lazily initialize this because it has
  // to be created in the background thread (currently mozStorageConnection
  // isn't thread safe).
  mozIStorageConnection* mConnection;

  // True if we're in the middle of a streaming update.
  PRBool mHasPendingUpdate;

  // For incremental updates, keep track of tables that have been updated.
  // When finish() is called, we go ahead and pass these update lines to
  // the callback.
  nsTArray<nsCString> mTableUpdateLines;

  // We receive data in small chunks that may be broken in the middle of
  // a line.  So we save the last partial line here.
  nsCString mPendingStreamUpdate;
};
NS_IMPL_THREADSAFE_ISUPPORTS1 ( nsUrlClassifierDBServiceWorker  ,
nsIUrlClassifierDBServiceWorker   
)

Definition at line 250 of file nsUrlClassifierDBService.cpp.

  : mConnection(nsnull), mHasPendingUpdate(PR_FALSE), mTableUpdateLines()
{
}

Definition at line 827 of file nsUrlClassifierDBService.cpp.

{
  if (!sUrlClassifierDBService) {
    sUrlClassifierDBService = new nsUrlClassifierDBService();
    if (!sUrlClassifierDBService)
      return nsnull;

    NS_ADDREF(sUrlClassifierDBService);   // addref the global

    if (NS_FAILED(sUrlClassifierDBService->Init())) {
      NS_RELEASE(sUrlClassifierDBService);
      return nsnull;
    }
  } else {
    // Already exists, just add a ref
    NS_ADDREF(sUrlClassifierDBService);   // addref the return result
  }
  return sUrlClassifierDBService;
}

Here is the call graph for this function:

Definition at line 102 of file TestIPCLocks.cpp.

{
  const char *lockName = (const char *) arg;

  LOG("entering TestThread [lock=%s]\n", lockName);

  nsresult rv;

  RandomSleep(1000, 1100);

  //LOG("done sleeping\n");

  rv = gLockService->AcquireLock(lockName, PR_TRUE);
  if (NS_SUCCEEDED(rv))
  {
    //LOG("acquired lock \"%s\"\n", lockName);
    RandomSleep(500, 1000);
    //LOG("releasing lock \"%s\"\n", lockName);
    rv = gLockService->ReleaseLock(lockName);
    if (NS_FAILED(rv))
    {
      LOG("failed to release lock [rv=%x]\n", rv);
      NS_ERROR("failed to release lock");
    }
  }
  else
  {
    LOG("failed to acquire lock [rv=%x]\n", rv);
    NS_NOTREACHED("failed to acquire lock");
  }

  LOG("exiting TestThread [lock=%s rv=%x]\n", lockName, rv);
}

Here is the call graph for this function:

Definition at line 1859 of file nsGfxScrollFrame.cpp.

{
  NS_ASSERTION(nsnull != aEvent,"Event is null");
  nsGfxScrollFrameInner* inner = NS_STATIC_CAST(nsGfxScrollFrameInner*, aEvent->owner);
  inner->FireScrollEvent();
  return nsnull;
}

Here is the call graph for this function:

static void Rot13Line ( nsCString line) [static]

Definition at line 126 of file nsUrlClassifierDBService.cpp.

{
  nsCString::iterator start, end;
  line.BeginWriting(start);
  line.EndWriting(end);
  while (start != end) {
    *start = kRot13Table[NS_STATIC_CAST(PRInt32, *start)];
    ++start;
  }
}

Variable Documentation

Definition at line 87 of file nsUrlClassifierDBService.cpp.

Definition at line 81 of file nsUrlClassifierDBService.cpp.

Definition at line 97 of file nsUrlClassifierDBService.cpp.

PRMonitor* gMonitor = nsnull [static]

Definition at line 84 of file nsUrlClassifierDBService.cpp.

Definition at line 91 of file nsUrlClassifierDBService.cpp.

const char* kNEW_TABLE_SUFFIX = "_new" [static]

Definition at line 93 of file nsUrlClassifierDBService.cpp.

const unsigned char kRot13Table[256] [static]
Initial value:
 {
  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
  21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
  40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
  59, 60, 61, 62, 63, 64, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
  65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 91, 92, 93, 94, 95, 96,
  110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 97, 98,
  99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 123, 124, 125, 126,
  127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141,
  142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156,
  157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171,
  172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186,
  187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201,
  202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216,
  217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231,
  232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246,
  247, 248, 249, 250, 251, 252, 253, 254, 255 }

Definition at line 106 of file nsUrlClassifierDBService.cpp.

Definition at line 78 of file nsUrlClassifierDBService.cpp.