Back to index

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

#include <nsSharedPrefHandler.h>

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

List of all members.

Public Member Functions

nsresult OnSessionBegin ()
nsresult OnSessionEnd ()
nsresult OnSavePrefs ()
nsresult OnPrefChanged (PRBool defaultPref, PrefHashEntry *pref, PrefValue newValue)
void ReadingUserPrefs (PRBool isReading)
PRBool IsPrefShared (const char *prefName)
void onTransactionAvailable (in unsigned long aQueueID,[array, const, size_is(aDataLen)] in octet aData, in unsigned long aDataLen)
 This gets called when a Transaction has been sent from the TransactionManager.
void onAttachReply (in unsigned long aQueueID, in unsigned long aStatus)
 Called after an application sends an Attach message to the Transaction Manager.
void onDetachReply (in unsigned long aQueueID, in unsigned long aStatus)
 Called after an application sends a Detach message.
void onFlushReply (in unsigned long aQueueID, in unsigned long aStatus)
 The reply from the TM indicating all messages have been removed from the queue indicated.

Protected Member Functions

 nsSharedPrefHandler ()
virtual ~nsSharedPrefHandler ()
nsresult Init (nsPrefService *aOwner)
nsresult ReadExceptionFile ()
nsresult EnsureTransactionService ()

Protected Attributes

nsPrefServicemPrefService
nsCOMPtr< ipcITransactionServicemTransService
const nsCString mPrefsTSQueueName
PRPackedBool mSessionActive
PRPackedBool mReadingUserPrefs
PRPackedBool mProcessingTransaction
nsAutoVoidArray mExceptionList

Friends

nsresult NS_CreateSharedPrefHandler (nsPrefService *)
 Global method to create gSharedPrefHandler.

Detailed Description

Definition at line 61 of file nsSharedPrefHandler.h.


Constructor & Destructor Documentation

Definition at line 95 of file nsSharedPrefHandler.cpp.

                                         :
  mPrefService(nsnull), mPrefsTSQueueName("prefs"),
  mSessionActive(PR_FALSE),
  mReadingUserPrefs(PR_FALSE),
  mProcessingTransaction(PR_FALSE)
{
#if defined(PR_LOGGING)
  if (!gPrefsTransactionObserverLog)
    gPrefsTransactionObserverLog = PR_NewLogModule("nsSharedPrefHandler");
#endif
}

Here is the caller graph for this function:

Definition at line 107 of file nsSharedPrefHandler.cpp.

{
  mExceptionList.EnumerateForwards(enumFree, nsnull);
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 267 of file nsSharedPrefHandler.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 221 of file nsSharedPrefHandler.cpp.

{
  NS_ENSURE_ARG(aOwner);
  mPrefService = aOwner;
  (void)ReadExceptionFile(); 
  
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 208 of file nsSharedPrefHandler.cpp.

{
  if (!mExceptionList.Count()) // quick check for empty list
    return PR_TRUE;
    
  // returns PR_TRUE if we reached the end without finding it.
  return mExceptionList.EnumerateForwards(enumFind, NS_CONST_CAST(char*, prefName));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ipcITransactionObserver::onAttachReply ( in unsigned long  aQueueID,
in unsigned long  aStatus 
) [inherited]

Called after an application sends an Attach message to the Transaction Manager.

Parameters:
aQueueIDThe client has been attached to the queue with this ID
aStatusThe status of the operation, as defined in tmUtils.h
void ipcITransactionObserver::onDetachReply ( in unsigned long  aQueueID,
in unsigned long  aStatus 
) [inherited]

Called after an application sends a Detach message.

Indicates to the client that no more messages will be coming from the the TM to this client. Also, no messages posted from this client to the indicated queue will be accepted.

Parameters:
aQueueIDThe client has been detached from the queue with this ID
aStatusThe status of the operation, as defined in tmUtils.h
void ipcITransactionObserver::onFlushReply ( in unsigned long  aQueueID,
in unsigned long  aStatus 
) [inherited]

The reply from the TM indicating all messages have been removed from the queue indicated.

Parameters:
aQueueIDThe queue that has been flushed.
aStatusThe status of the operation, as defined in tmUtils.h
nsresult nsSharedPrefHandler::OnPrefChanged ( PRBool  defaultPref,
PrefHashEntry pref,
PrefValue  newValue 
)

Definition at line 156 of file nsSharedPrefHandler.cpp.

{
  if (!mSessionActive 
    || defaultPref
    || !IsPrefShared(pref->key)
    || mReadingUserPrefs
    || mProcessingTransaction)
    return NS_OK;
    
  nsresult rv = EnsureTransactionService();
  NS_ENSURE_SUCCESS(rv, rv);

  PRUint32 valueLen, prefNameLen = strlen(pref->key);
  
  ipcMessageWriter outMsg(256);
  outMsg.PutInt32(kCurrentPrefsTransactionDataVersion);
  outMsg.PutInt32(defaultPref); // XXX: Is not used?
  outMsg.PutInt32(prefNameLen + 1);
  outMsg.PutBytes(pref->key, prefNameLen + 1);

  switch (pref->flags & PREF_VALUETYPE_MASK) {
    case PREF_STRING:
      outMsg.PutInt32(PREF_STRING);
      valueLen = strlen(newValue.stringVal) + 1;
      outMsg.PutInt32(valueLen);
      outMsg.PutBytes(newValue.stringVal, valueLen);
      break;
    case PREF_INT:
      outMsg.PutInt32(PREF_INT);
      outMsg.PutInt32(sizeof(PRInt32));
      outMsg.PutInt32(newValue.intVal);
      break;
    case PREF_BOOL:
      outMsg.PutInt32(PREF_BOOL);
      outMsg.PutInt32(sizeof(PRInt32));
      outMsg.PutInt32(newValue.boolVal);
      break;
    default:
      return NS_ERROR_UNEXPECTED;
  }
  
  rv = outMsg.HasError() ? NS_ERROR_FAILURE : NS_OK;
  NS_ASSERTION(NS_SUCCEEDED(rv), "OnPrefChanged: outMsg failed");
  if (NS_SUCCEEDED(rv)) {
    rv = mTransService->PostTransaction(kPrefsTSQueueName, outMsg.GetBuffer(), outMsg.GetSize());
    NS_ASSERTION(NS_SUCCEEDED(rv), "ipcITransactionService::PostTransaction() failed");
  }
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 142 of file nsSharedPrefHandler.cpp.

{
  nsresult rv = EnsureTransactionService();
  NS_ENSURE_SUCCESS(rv, rv);
  
  // When the reply to this comes (synchronously), we'll actually
  // write out our data. The transaction service holds a lock on
  // our data file during our reply.
  rv = mTransService->Flush(kPrefsTSQueueName, PR_TRUE);
  NS_ASSERTION(NS_SUCCEEDED(rv), "ipcITransactionService::Flush() failed");

  return NS_OK;
}

Here is the call graph for this function:

Definition at line 112 of file nsSharedPrefHandler.cpp.

{
  nsresult rv = EnsureTransactionService();
  NS_ENSURE_SUCCESS(rv, rv);

  // When the reply to this comes (synchronously), we'll actually
  // read in our data. The transaction service holds a lock on
  // our data file during our reply.
  rv = mTransService->Attach(kPrefsTSQueueName, this, PR_TRUE);
  NS_ASSERTION(NS_SUCCEEDED(rv), "ipcITransactionService::Attach() failed");
  
  if (NS_SUCCEEDED(rv))
    mSessionActive = PR_TRUE;
    
  return rv;
}

Here is the call graph for this function:

Definition at line 129 of file nsSharedPrefHandler.cpp.

{
  nsresult rv = EnsureTransactionService();
  NS_ENSURE_SUCCESS(rv, rv);
  
  rv = mTransService->Detach(kPrefsTSQueueName);
  NS_ASSERTION(NS_SUCCEEDED(rv), "ipcITransactionService::Detach() failed");

  mSessionActive = PR_FALSE;

  return rv;
}

Here is the call graph for this function:

void ipcITransactionObserver::onTransactionAvailable ( in unsigned long  aQueueID,
[array, const, size_is(aDataLen)] in octet  aData,
in unsigned long  aDataLen 
) [inherited]

This gets called when a Transaction has been sent from the TransactionManager.

If the data passed in needs to be stored for longer than the life of the method the observer needs to make a copy.

Parameters:
aQueueIDThe queue from which the transaction originated
aDataThe data to be sent.
aDataLenThe length of the data argument

Definition at line 230 of file nsSharedPrefHandler.cpp.

{
  nsresult rv;
  
  nsCOMPtr<nsIProperties> directoryService =
      do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
  if (NS_SUCCEEDED(rv)) {
    nsCOMPtr<nsILocalFile> exceptionFile;
    rv = directoryService->Get(NS_APP_PREF_DEFAULTS_50_DIR, NS_GET_IID(nsILocalFile),
                              getter_AddRefs(exceptionFile));
    if (NS_SUCCEEDED(rv)) {
      rv = exceptionFile->AppendNative(kExceptionListFileName);
      if (NS_SUCCEEDED(rv)) {
        FILE *inStm;
        rv = exceptionFile->OpenANSIFileDesc("r", &inStm);
        if (NS_SUCCEEDED(rv)) {
          nsCAutoString lineStr;
          while (ReadLine(inStm, lineStr) != EOF) {
            lineStr.CompressWhitespace();
            if (lineStr.IsEmpty() || lineStr.CharAt(0) == kExceptionListCommentChar)
              continue;
              
            char *rawStr = ToNewCString(lineStr);
            if (!rawStr) {
              rv = NS_ERROR_OUT_OF_MEMORY;
              break;
            }
            mExceptionList.AppendElement(rawStr);
          }
          fclose(inStm);
        }
      }
    }
  }
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 78 of file nsSharedPrefHandler.h.

                  { mReadingUserPrefs = isReading; }

Here is the caller graph for this function:


Friends And Related Function Documentation

Global method to create gSharedPrefHandler.

Parameters:
aOwner

Definition at line 417 of file nsSharedPrefHandler.cpp.

{
  nsSharedPrefHandler *local = new nsSharedPrefHandler;
  if (!local)
    return NS_ERROR_OUT_OF_MEMORY;
  nsresult rv = local->Init(aOwner);
  if (NS_FAILED(rv)) {
    delete local;
    return rv;
  }
  NS_ADDREF(gSharedPrefHandler = local);
  return NS_OK;
}

Member Data Documentation

nsAutoVoidArray nsSharedPrefHandler::mExceptionList [protected]

Definition at line 101 of file nsSharedPrefHandler.h.

Definition at line 92 of file nsSharedPrefHandler.h.

Definition at line 95 of file nsSharedPrefHandler.h.

Definition at line 99 of file nsSharedPrefHandler.h.

Definition at line 98 of file nsSharedPrefHandler.h.

Definition at line 97 of file nsSharedPrefHandler.h.

Definition at line 94 of file nsSharedPrefHandler.h.


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