Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
nsUrlClassifierDBService Class Reference

#include <nsUrlClassifierDBService.h>

Inheritance diagram for nsUrlClassifierDBService:
Inheritance graph
[legend]
Collaboration diagram for nsUrlClassifierDBService:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsUrlClassifierDBService ()
nsresult Init ()
void exists (in ACString tableName, in ACString key, in nsIUrlClassifierCallback c)
 Looks up a key in the database.
void checkTables (in ACString tableNames, in nsIUrlClassifierCallback c)
 Checks to see if the tables exist.
void updateTables (in ACString updateString, in nsIUrlClassifierCallback c)
 Updates the table in the background.
void update (in ACString updateChunk)
 Update the table incrementally.
void finish (in nsIUrlClassifierCallback c)
 Finish an incremental update.
void cancelStream ()
 Cancel an incremental update.
void observe (in nsISupports aSubject, in string aTopic, in wstring aData)
 Observe will be called when there is a notification for the topic |aTopic|.

Static Public Member Functions

static nsUrlClassifierDBServiceGetInstance ()

Private Member Functions

 ~nsUrlClassifierDBService ()
 nsUrlClassifierDBService (nsUrlClassifierDBService &)
nsresult EnsureThreadStarted ()
nsresult Shutdown ()

Private Attributes

nsCOMPtr
< nsUrlClassifierDBServiceWorker > 
mWorker

Detailed Description

Definition at line 53 of file nsUrlClassifierDBService.h.


Constructor & Destructor Documentation

Definition at line 853 of file nsUrlClassifierDBService.cpp.

{
}

Definition at line 861 of file nsUrlClassifierDBService.cpp.

Here is the call graph for this function:


Member Function Documentation

Cancel an incremental update.

This rolls back and pending changes. and resets the stream interface.

void nsIUrlClassifierDBService::checkTables ( in ACString  tableNames,
in nsIUrlClassifierCallback  c 
) [inherited]

Checks to see if the tables exist.

tableNames is a comma separated list of table names to check. The callback is called with a comma separated list of tables that no longer exist (either the db is corrupted or the user deleted the file).

Definition at line 1091 of file nsUrlClassifierDBService.cpp.

{
  // xpcom-shutdown has triggered, the thread is already gone.
  if (!gKeepRunning) {
    return NS_ERROR_FAILURE;
  }

  nsAutoMonitor mon(gMonitor);
  while (!gEventQ)
    mon.Wait();

  return NS_OK;
}

Here is the caller graph for this function:

void nsIUrlClassifierDBService::exists ( in ACString  tableName,
in ACString  key,
in nsIUrlClassifierCallback  c 
) [inherited]

Looks up a key in the database.

After it finds a value, it calls callback with the value as the first param. If the key is not in the db or the table does not exist, the callback is called with an empty string parameter.

Finish an incremental update.

This commits any pending tables and calls the callback for each completed table.

Definition at line 871 of file nsUrlClassifierDBService.cpp.

{
#if defined(PR_LOGGING)
  if (!gUrlClassifierDbServiceLog)
    gUrlClassifierDbServiceLog = PR_NewLogModule("UrlClassifierDbService");
#endif

  // Force the storage service to be created on the main thread.
  nsresult rv;
  nsCOMPtr<mozIStorageService> storageService =
    do_GetService(MOZ_STORAGE_SERVICE_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  gMonitor = PR_NewMonitor();
  // Start the background thread.
  gDbBackgroundThread = PR_CreateThread(PR_USER_THREAD,
                                        EventLoop,
                                        nsnull,
                                        PR_PRIORITY_NORMAL,
                                        PR_GLOBAL_THREAD,
                                        PR_JOINABLE_THREAD,
                                        0);
  if (!gDbBackgroundThread)
    return NS_ERROR_OUT_OF_MEMORY;

  mWorker = new nsUrlClassifierDBServiceWorker();
  if (!mWorker)
    return NS_ERROR_OUT_OF_MEMORY;

  // Add an observer for shutdown
  nsCOMPtr<nsIObserverService> observerService =
      do_GetService("@mozilla.org/observer-service;1");
  if (!observerService)
    return NS_ERROR_FAILURE;

  observerService->AddObserver(this, "profile-before-change", PR_FALSE);
  observerService->AddObserver(this, "xpcom-shutdown", PR_FALSE);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIObserver::observe ( in nsISupports  aSubject,
in string  aTopic,
in wstring  aData 
) [inherited]

Observe will be called when there is a notification for the topic |aTopic|.

This assumes that the object implementing this interface has been registered with an observer service such as the nsIObserverService.

If you expect multiple topics/subjects, the impl is responsible for filtering.

You should not modify, add, remove, or enumerate notifications in the implemention of observe.

Parameters:
aSubject: Notification specific interface pointer.
aTopic: The notification topic or subject.
aData: Notification specific wide string. subject event.

Definition at line 1107 of file nsUrlClassifierDBService.cpp.

{
  LOG(("shutting down db service\n"));

  if (!gDbBackgroundThread)
    return NS_OK;

  nsresult rv;
  
  EnsureThreadStarted();
  
  // First close the db connection.
  if (mWorker) {
    LOG(("Sending close request\n"));
    nsCOMPtr<nsIUrlClassifierDBServiceWorker> proxy;
    rv = NS_GetProxyForObject(gEventQ,
                              NS_GET_IID(nsIUrlClassifierDBServiceWorker),
                              mWorker,
                              PROXY_ASYNC,
                              getter_AddRefs(proxy));
    if (NS_SUCCEEDED(rv)) {
      rv = proxy->CloseDb();
      NS_ASSERTION(NS_SUCCEEDED(rv), "failed to post close db event");
    }
  }

  PLEvent* ev = new PLEvent;
  PL_InitEvent(ev, nsnull, EventHandler, DestroyHandler);

  if (NS_FAILED(gEventQ->PostEvent(ev))) {
    PL_DestroyEvent(ev);
  }
  LOG(("joining background thread"));

  gShuttingDownThread = PR_TRUE;
  PRStatus ok = PR_JoinThread(gDbBackgroundThread);
  NS_ASSERTION(ok == PR_SUCCESS, "failed to join background thread");

  gDbBackgroundThread = nsnull;
  return NS_OK;
}

Here is the call graph for this function:

void nsIUrlClassifierDBService::update ( in ACString  updateChunk) [inherited]

Update the table incrementally.

void nsIUrlClassifierDBService::updateTables ( in ACString  updateString,
in nsIUrlClassifierCallback  c 
) [inherited]

Updates the table in the background.

Calls callback after each table completes processing with the new table line as the parameter. This allows us to keep track of the table version in our main thread.


Member Data Documentation

nsCOMPtr<nsUrlClassifierDBServiceWorker> nsUrlClassifierDBService::mWorker [private]

Definition at line 87 of file nsUrlClassifierDBService.h.


The documentation for this class was generated from the following files: