Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Friends
mozStorageService Class Reference

#include <mozStorageService.h>

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

List of all members.

Public Member Functions

 mozStorageService ()
nsresult Init ()
mozIStorageConnection openSpecialDatabase (in string aStorageKey)
 Get a connection to a named special database storage.
mozIStorageConnection openDatabase (in nsIFile aDatabaseFile)
 Open a connection to the specified file.
void observe (in nsISupports aSubject, in string aTopic, in wstring aData)
 Observe will be called when there is a notification for the topic |aTopic|.

Protected Member Functions

nsresult InitStorageAsyncIO ()
nsresult FlushAsyncIO ()
nsresult FinishAsyncIO ()
void FreeLocks ()

Protected Attributes

nsCOMPtr< nsIFilemProfileStorageFile

Private Member Functions

 ~mozStorageService ()

Friends

class mozStorageConnection

Detailed Description

Definition at line 53 of file mozStorageService.h.


Constructor & Destructor Documentation

Definition at line 57 of file mozStorageService.cpp.

{
    
}

Definition at line 62 of file mozStorageService.cpp.

{
    FreeLocks();
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 614 of file mozStorageAsyncIO.cpp.

{
  {
    nsAutoLock lock(AsyncQueueLock);

    if (!AsyncWriteThreadInstance)
      return NS_OK; // single-threaded mode, nothing to do

    // this will tell the writer to exit when the message queue is empty.
    AsyncWriterHaltWhenIdle = PR_TRUE;

    // this will wake up the writer thread when we release the lock
    PR_NotifyAllCondVar(AsyncQueueCondition);
  }

  // now we join with the writer thread
  AsyncWriteThreadInstance->Join();

  // release the thread and enter single-threaded mode
  NS_RELEASE(AsyncWriteThreadInstance);
  AsyncWriteThreadInstance = nsnull;

  return NS_OK;
}

Here is the call graph for this function:

Definition at line 560 of file mozStorageAsyncIO.cpp.

{
  AsyncMessage *message = 0;
  int rc;

  // single threaded? nothing to do.
  if (!AsyncWriteThreadInstance)
    return NS_OK;

  PRLock *flushLock = PR_NewLock();
  if (!flushLock)
    return NS_ERROR_OUT_OF_MEMORY;

  PRCondVar *flushCond = PR_NewCondVar(flushLock);
  if (!flushCond) {
    PR_DestroyLock(flushLock);
    return NS_ERROR_OUT_OF_MEMORY;
  }

  PR_Lock(flushLock);

  rc = AsyncBarrier(flushLock, flushCond);
  if (rc == SQLITE_OK) {
    // the async thread will notify us once it reaches
    // the ASYNC_BARRIER operation; only wait if
    // adding the barrier worked, otherwise just unlock
    // and return the error
    PR_WaitCondVar(flushCond, PR_INTERVAL_NO_TIMEOUT);
  }

  PR_Unlock(flushLock);

  PR_DestroyCondVar(flushCond);
  PR_DestroyLock(flushLock);

  if (rc == SQLITE_NOMEM)
    return NS_ERROR_OUT_OF_MEMORY;
  else if (rc != SQLITE_OK)
    return NS_ERROR_FAILURE;
  return NS_OK;
}

Here is the call graph for this function:

Definition at line 647 of file mozStorageAsyncIO.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 68 of file mozStorageService.cpp.

{
    // The service must be initialized on the main thread. The
    // InitStorageAsyncIO function creates a thread which is joined with the
    // main thread during shutdown. If the thread is created from a random
    // thread, we'll join to the wrong parent.
    NS_ENSURE_STATE(nsIThread::IsMainThread());

    // this makes multiple connections to the same database share the same pager
    // cache.
    sqlite3_enable_shared_cache(1);

    nsresult rv;
    nsCOMPtr<nsIObserverService> observerService = 
            do_GetService("@mozilla.org/observer-service;1", &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = InitStorageAsyncIO();
    NS_ENSURE_SUCCESS(rv, rv);

    rv = observerService->AddObserver(this, gQuitApplicationMessage, PR_FALSE);
    NS_ENSURE_SUCCESS(rv, rv);

    return NS_OK;
}

Here is the call graph for this function:

Definition at line 504 of file mozStorageAsyncIO.cpp.

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.

Open a connection to the specified file.

==========

DANGER

If you have more than one connection to a file, you MUST use the EXACT SAME NAME for the file each time, including case. The sqlite code uses a simple string compare to see if there is already a connection. Opening a connection to "Foo.sqlite" and "foo.sqlite" will CORRUPT YOUR DATABASE.

Opening connections from more than one thread to the same database will also CORRUPT YOUR DATABASE. All connections share the same sqlite cache, and the cache is not threadsafe.

The connection object returned by this function is not threadsafe. You must use it only from the thread you created it from.

Parameters:
aDatabaseFilea nsIFile of the database to open.
Returns:
a mozIStorageConnection for the requested database file.
Exceptions:
NS_ERROR_FAILUREif any operation fails while opening the database.

Get a connection to a named special database storage.

Parameters:
aStorageKeya string key identifying the type of storage requested. Valid values include: "profile", "memory".
See also:
openDatabase for restrictions on how database connections may be used. For the profile database, you should only access it from the main thread since other callers may also have connections.
Returns:
a new mozIStorageConnection for the requested storage database.
Exceptions:
NS_ERROR_INVALID_ARGif aStorageKey is invalid.

Friends And Related Function Documentation

friend class mozStorageConnection [friend]

Definition at line 56 of file mozStorageService.h.


Member Data Documentation

Definition at line 75 of file mozStorageService.h.


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