Back to index

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

#include <nsMsgFolderCompactor.h>

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

List of all members.

Public Member Functions

 nsOfflineStoreCompactState (void)
virtual ~nsOfflineStoreCompactState (void)
NS_IMETHOD OnStopRequest (nsIRequest *request, nsISupports *ctxt, nsresult status)
void Init (in nsIMsgFolder srcFolder, in nsICopyMessageListener destination, in nsISupports listenerData)
void compact (in nsIMsgFolder aFolder, in boolean aOfflineStore, in nsIMsgWindow aMsgWindow)
void compactAll (in nsISupportsArray aArrayOfFoldersToCompact, in nsIMsgWindow aMsgWindow, in boolean compactOfflineAlso, in nsISupportsArray aOfflineFolderArray)
void onDataAvailable (in nsIRequest aRequest, in nsISupports aContext, in nsIInputStream aInputStream, in unsigned long aOffset, in unsigned long aCount)
 Called when the next chunk of data (corresponding to the request) may be read without blocking the calling thread.
void onStartRequest (in nsIRequest aRequest, in nsISupports aContext)
 Called to signify the beginning of an asynchronous request.
void onStopRequest (in nsIRequest aRequest, in nsISupports aContext, in nsresult aStatusCode)
 Called to signify the end of an asynchronous request.
void StartMessage ()
void EndMessage (in nsMsgKey key)
void EndCopy (in nsISupports url, in nsresult aStatus)
void OnStartRunningUrl (in nsIURI url)
void OnStopRunningUrl (in nsIURI url, in nsresult aExitCode)

Protected Member Functions

virtual nsresult InitDB (nsIMsgDatabase *db)
virtual nsresult StartCompacting ()
virtual nsresult FinishCompact ()
void CloseOutputStream ()
void CleanupTempFilesAfterError ()
nsresult Init (nsIMsgFolder *aFolder, const char *aBaseMsgUri, nsIMsgDatabase *aDb, nsIFileSpec *aPathSpec, nsIMsgWindow *aMsgWindow)
nsresult GetMessage (nsIMsgDBHdr **message)
nsresult BuildMessageURI (const char *baseURI, PRUint32 key, nsCString &uri)
nsresult ShowStatusMsg (const PRUnichar *aMsg)
nsresult ReleaseFolderLock ()
void ShowCompactingStatusMsg ()
void ShowDoneStatus ()
nsresult CompactNextFolder ()
void AdvanceToNextLine (const char *buffer, PRUint32 &bufferOffset, PRUint32 maxBufferOffset)

Protected Attributes

nsCString m_baseMessageUri
nsCString m_messageUri
nsCOMPtr< nsIMsgFolderm_folder
nsCOMPtr< nsIMsgDatabasem_db
nsFileSpec m_fileSpec
nsOutputFileStreamm_fileStream
nsMsgKeyArray m_keyArray
PRInt32 m_size
PRInt32 m_curIndex
nsMsgKey m_startOfNewMsg
char m_dataBuffer [COMPACTOR_READ_BUFF_SIZE+1]
nsresult m_status
nsCOMPtr< nsIMsgMessageServicem_messageService
nsCOMPtr< nsISupportsArraym_folderArray
nsCOMPtr< nsIMsgWindowm_window
nsCOMPtr< nsIMsgDBHdrm_curSrcHdr
PRUint32 m_folderIndex
PRBool m_compactAll
PRBool m_compactOfflineAlso
PRBool m_compactingOfflineFolders
PRBool m_parsingFolder
PRBool m_needStatusLine
PRBool m_startOfMsg
PRInt32 m_statusOffset
PRInt32 m_addedHeaderSize
nsCOMPtr< nsISupportsArraym_offlineFolderArray

Detailed Description

Definition at line 117 of file nsMsgFolderCompactor.h.


Constructor & Destructor Documentation

Definition at line 818 of file nsMsgFolderCompactor.cpp.

{
}

Definition at line 822 of file nsMsgFolderCompactor.cpp.

{
}

Member Function Documentation

void nsFolderCompactState::AdvanceToNextLine ( const char *  buffer,
PRUint32 bufferOffset,
PRUint32  maxBufferOffset 
) [protected, inherited]

Definition at line 585 of file nsMsgFolderCompactor.cpp.

{
  for (; bufferOffset < maxBufferOffset; bufferOffset++)
  {
    if (buffer[bufferOffset] == nsCRT::CR || buffer[bufferOffset] == nsCRT::LF)
    {
      bufferOffset++;
      if (buffer[bufferOffset- 1] == nsCRT::CR && buffer[bufferOffset] == nsCRT::LF)
        bufferOffset++;
      break;
    }
  }
}
nsresult nsFolderCompactState::BuildMessageURI ( const char *  baseURI,
PRUint32  key,
nsCString uri 
) [protected, inherited]

Definition at line 118 of file nsMsgFolderCompactor.cpp.

{
  uri.Append(baseURI);
  uri.Append('#');
  uri.AppendInt(key);
  return NS_OK;
}

Here is the caller graph for this function:

Definition at line 108 of file nsMsgFolderCompactor.cpp.

{
  CloseOutputStream();
  if (m_db)
    m_db->ForceClosed();
  nsLocalFolderSummarySpec summarySpec(m_fileSpec);
  m_fileSpec.Delete(PR_FALSE);
  summarySpec.Delete(PR_FALSE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsFolderCompactState::CloseOutputStream ( ) [protected, inherited]

Definition at line 97 of file nsMsgFolderCompactor.cpp.

{
  if (m_fileStream)
  {
    m_fileStream->close();
    delete m_fileStream;
    m_fileStream = nsnull;
  }

}

Here is the caller graph for this function:

void nsIMsgFolderCompactor::compact ( in nsIMsgFolder  aFolder,
in boolean  aOfflineStore,
in nsIMsgWindow  aMsgWindow 
) [inherited]
void nsIMsgFolderCompactor::compactAll ( in nsISupportsArray  aArrayOfFoldersToCompact,
in nsIMsgWindow  aMsgWindow,
in boolean  compactOfflineAlso,
in nsISupportsArray  aOfflineFolderArray 
) [inherited]

Definition at line 495 of file nsMsgFolderCompactor.cpp.

{
   nsresult rv = NS_OK;
   m_folderIndex++;
   PRUint32 cnt=0;
   rv = m_folderArray->Count(&cnt);
   NS_ENSURE_SUCCESS(rv,rv);
   if (m_folderIndex == cnt)
   {
     if (m_compactOfflineAlso)
     {
       m_compactingOfflineFolders = PR_TRUE;
       nsCOMPtr<nsIMsgFolder> folder = do_QueryElementAt(m_folderArray,
                                                         m_folderIndex-1, &rv);
       if (NS_SUCCEEDED(rv) && folder)
         folder->CompactAllOfflineStores(m_window, m_offlineFolderArray);
     }
     else
     {
       ShowDoneStatus();
       return rv;
     }
       
   } 
   nsCOMPtr<nsIMsgFolder> folder = do_QueryElementAt(m_folderArray,
                                                     m_folderIndex, &rv);

   if (NS_SUCCEEDED(rv) && folder)
     rv = Compact(folder, m_compactingOfflineFolders, m_window);                    
    else
      ShowDoneStatus();
   return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsICopyMessageStreamListener::EndCopy ( in nsISupports  url,
in nsresult  aStatus 
) [inherited]

Reimplemented from nsFolderCompactState.

Definition at line 901 of file nsMsgFolderCompactor.cpp.

{
    // All okay time to finish up the compact process
  nsresult rv = NS_OK;
  nsCOMPtr<nsIFileSpec> pathSpec;
  nsFileSpec fileSpec;
  PRUint32 flags;

    // get leaf name and database name of the folder
  m_folder->GetFlags(&flags);
  rv = m_folder->GetPath(getter_AddRefs(pathSpec));
  pathSpec->GetFileSpec(&fileSpec);

  nsXPIDLCString leafName;

  pathSpec->GetLeafName(getter_Copies(leafName));

    // close down the temp file stream; preparing for deleting the old folder
    // and its database; then rename the temp folder and database
  m_fileStream->flush();
  m_fileStream->close();
  delete m_fileStream;
  m_fileStream = nsnull;

    // make sure the new database is valid
  nsCOMPtr <nsIDBFolderInfo> dbFolderInfo;
  m_db->GetDBFolderInfo(getter_AddRefs(dbFolderInfo));
  if (dbFolderInfo)
    dbFolderInfo->SetExpungedBytes(0);
  // this forces the m_folder to update mExpungedBytes from the db folder info.
  PRUint32 expungedBytes;
  m_folder->GetExpungedBytes(&expungedBytes);
  m_folder->UpdateSummaryTotals(PR_TRUE);
  m_db->SetSummaryValid(PR_TRUE);

    // remove the old folder 
  fileSpec.Delete(PR_FALSE);

    // rename the copied folder to be the original folder 
  m_fileSpec.Rename(leafName.get());

  PRUnichar emptyStr = 0;
  ShowStatusMsg(&emptyStr);
  if (m_compactAll)
    rv = CompactNextFolder();
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsFolderCompactState::GetMessage ( nsIMsgDBHdr **  message) [protected, inherited]

Definition at line 530 of file nsMsgFolderCompactor.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void nsICopyMessageStreamListener::Init ( in nsIMsgFolder  srcFolder,
in nsICopyMessageListener  destination,
in nsISupports  listenerData 
) [inherited]
NS_IMETHODIMP nsFolderCompactState::Init ( nsIMsgFolder aFolder,
const char *  aBaseMsgUri,
nsIMsgDatabase aDb,
nsIFileSpec aPathSpec,
nsIMsgWindow aMsgWindow 
) [protected, inherited]

Definition at line 278 of file nsMsgFolderCompactor.cpp.

{
  nsresult rv;

  m_folder = folder;
  m_baseMessageUri = baseMsgUri;

  pathSpec->GetFileSpec(&m_fileSpec);

  // need to make sure the temp file goes in the same real directory
  // as the original file, so resolve sym links.
  PRBool ignored;
  m_fileSpec.ResolveSymlink(ignored);

  m_fileSpec.SetLeafName("nstmp");
  m_fileSpec.MakeUnique();   //make sure we are not crunching existing nstmp file
  m_window = aMsgWindow;
  m_keyArray.RemoveAll();
  InitDB(db);

  m_size = m_keyArray.GetSize();
  m_curIndex = 0;
  
  m_fileStream = new nsOutputFileStream(m_fileSpec);
  if (!m_fileStream) 
  {
    m_folder->ThrowAlertMsg("compactFolderWriteFailed", m_window);
    rv = NS_ERROR_OUT_OF_MEMORY; 
  }
  else
  {
    rv = GetMessageServiceFromURI(baseMsgUri,
                                getter_AddRefs(m_messageService));
  }
  if (NS_FAILED(rv))
  {
    m_status = rv;
    Release(); // let go of ourselves...
  }
  return rv;
}

Here is the call graph for this function:

Reimplemented from nsFolderCompactState.

Definition at line 828 of file nsMsgFolderCompactor.cpp.

{
  db->ListAllOfflineMsgs(&m_keyArray);
  m_db = db;
  return NS_OK;
}

Here is the call graph for this function:

void nsIStreamListener::onDataAvailable ( in nsIRequest  aRequest,
in nsISupports  aContext,
in nsIInputStream  aInputStream,
in unsigned long  aOffset,
in unsigned long  aCount 
) [inherited]

Called when the next chunk of data (corresponding to the request) may be read without blocking the calling thread.

The onDataAvailable impl must read exactly |aCount| bytes of data before returning.

Parameters:
aRequestrequest corresponding to the source of the data
aContextuser defined context
aInputStreaminput stream containing the data chunk
aOffsetNumber of bytes that were sent in previous onDataAvailable calls for this request. In other words, the sum of all previous count parameters. If that number is greater than or equal to 2^32, this parameter will be PR_UINT32_MAX (2^32 - 1).
aCountnumber of bytes available in the stream

NOTE: The aInputStream parameter must implement readSegments.

An exception thrown from onDataAvailable has the side-effect of causing the request to be canceled.

void nsIRequestObserver::onStartRequest ( in nsIRequest  aRequest,
in nsISupports  aContext 
) [inherited]

Called to signify the beginning of an asynchronous request.

Parameters:
aRequestrequest being observed
aContextuser defined context

An exception thrown from onStartRequest has the side-effect of causing the request to be canceled.

Here is the caller graph for this function:

Here is the caller graph for this function:

void nsIRequestObserver::onStopRequest ( in nsIRequest  aRequest,
in nsISupports  aContext,
in nsresult  aStatusCode 
) [inherited]

Called to signify the end of an asynchronous request.

This call is always preceded by a call to onStartRequest.

Parameters:
aRequestrequest being observed
aContextuser defined context
aStatusCodereason for stopping (NS_OK if completed successfully)

An exception thrown from onStopRequest is generally ignored.

Here is the caller graph for this function:

NS_IMETHODIMP nsOfflineStoreCompactState::OnStopRequest ( nsIRequest request,
nsISupports *  ctxt,
nsresult  status 
)

Definition at line 836 of file nsMsgFolderCompactor.cpp.

{
  nsresult rv = status;
  nsCOMPtr<nsIURI> uri;
  nsCOMPtr<nsIMsgDBHdr> msgHdr;
  nsCOMPtr<nsIMsgDBHdr> newMsgHdr;
  nsCOMPtr <nsIMsgStatusFeedback> statusFeedback;
  ReleaseFolderLock();

  if (NS_FAILED(rv)) goto done;
  uri = do_QueryInterface(ctxt, &rv);
  if (NS_FAILED(rv)) goto done;
  rv = GetMessage(getter_AddRefs(msgHdr));
  if (NS_FAILED(rv)) goto done;

  if (msgHdr)
    msgHdr->SetMessageOffset(m_startOfNewMsg);

  if (m_window)
  {
    m_window->GetStatusFeedback(getter_AddRefs(statusFeedback));
    if (statusFeedback)
      statusFeedback->ShowProgress (100 * m_curIndex / m_size);
  }
    // advance to next message 
  m_curIndex ++;
  if (m_curIndex >= m_size)
  {
    m_db->Commit(nsMsgDBCommitType::kLargeCommit);
    msgHdr = nsnull;
    newMsgHdr = nsnull;
    // no more to copy finish it up
   FinishCompact();
    Release(); // kill self
  }
  else
  {
    m_messageUri.SetLength(0); // clear the previous message uri
    rv = BuildMessageURI(m_baseMessageUri.get(), m_keyArray[m_curIndex],
                                m_messageUri);
    if (NS_FAILED(rv)) goto done;
    rv = m_messageService->CopyMessage(m_messageUri.get(), this, PR_FALSE, nsnull,
                                       /* ### should get msg window! */ nsnull, nsnull);
   if (NS_FAILED(rv))
   {
     PRUint32 resultFlags;
     msgHdr->AndFlags(~MSG_FLAG_OFFLINE, &resultFlags);
   }
  // if this fails, we should clear the offline flag on the source message.
    
  }

done:
  if (NS_FAILED(rv)) {
    m_status = rv; // set the status to rv so the destructor can remove the
                   // temp folder and database
    Release(); // kill self
    return rv;
  }
  return rv;
}

Here is the call graph for this function:

void nsIUrlListener::OnStopRunningUrl ( in nsIURI  url,
in nsresult  aExitCode 
) [inherited]

Here is the caller graph for this function:

Definition at line 471 of file nsMsgFolderCompactor.cpp.

{
  nsresult result = NS_OK;
  if (!m_folder) return result;
  PRBool haveSemaphore;
  nsCOMPtr <nsISupports> supports = do_QueryInterface(NS_STATIC_CAST(nsIMsgFolderCompactor*, this));
  result = m_folder->TestSemaphore(supports, &haveSemaphore);
  if(NS_SUCCEEDED(result) && haveSemaphore)
    result = m_folder->ReleaseSemaphore(supports);
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 321 of file nsMsgFolderCompactor.cpp.

{
  nsXPIDLString statusString;
  nsresult rv = m_folder->GetStringWithFolderNameFromBundle("compactingFolder", getter_Copies(statusString));
  if (statusString && NS_SUCCEEDED(rv))
    ShowStatusMsg(statusString);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsFolderCompactState::ShowDoneStatus ( ) [protected, inherited]

Definition at line 483 of file nsMsgFolderCompactor.cpp.

{
  if (m_folder)
  {
    nsXPIDLString statusString;
    nsresult rv = m_folder->GetStringWithFolderNameFromBundle("doneCompacting", getter_Copies(statusString));
    if (statusString && NS_SUCCEEDED(rv))
      ShowStatusMsg(statusString);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsFolderCompactState::ShowStatusMsg ( const PRUnichar aMsg) [protected, inherited]

Definition at line 265 of file nsMsgFolderCompactor.cpp.

{
  nsCOMPtr <nsIMsgStatusFeedback> statusFeedback;
  if (m_window)
  {
    m_window->GetStatusFeedback(getter_AddRefs(statusFeedback));
    if (statusFeedback && aMsg)
      return statusFeedback->SetStatusString (aMsg);
  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented from nsFolderCompactState.

Definition at line 1023 of file nsMsgFolderCompactor.cpp.

{
  nsresult rv = NS_OK;
  if (m_size > 0 && m_curIndex == 0)
  {
    AddRef(); // we own ourselves, until we're done, anyway.
    ShowCompactingStatusMsg();
    m_messageUri.SetLength(0); // clear the previous message uri
    rv = BuildMessageURI(m_baseMessageUri.get(),
                                m_keyArray[0],
                                m_messageUri);
    if (NS_SUCCEEDED(rv))
      rv = m_messageService->CopyMessage(
        m_messageUri.get(), this, PR_FALSE, nsnull, m_window, nsnull);

  }
  else
  { // no messages to copy with
    ReleaseFolderLock();
    FinishCompact();
//    Release(); // we don't "own" ourselves yet.
  }
  return rv;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 112 of file nsMsgFolderCompactor.h.

Definition at line 87 of file nsMsgFolderCompactor.h.

Definition at line 104 of file nsMsgFolderCompactor.h.

Definition at line 106 of file nsMsgFolderCompactor.h.

Definition at line 105 of file nsMsgFolderCompactor.h.

PRInt32 nsFolderCompactState::m_curIndex [protected, inherited]

Definition at line 95 of file nsMsgFolderCompactor.h.

Definition at line 102 of file nsMsgFolderCompactor.h.

Definition at line 97 of file nsMsgFolderCompactor.h.

Definition at line 90 of file nsMsgFolderCompactor.h.

Definition at line 91 of file nsMsgFolderCompactor.h.

Definition at line 92 of file nsMsgFolderCompactor.h.

Definition at line 89 of file nsMsgFolderCompactor.h.

Definition at line 100 of file nsMsgFolderCompactor.h.

Definition at line 103 of file nsMsgFolderCompactor.h.

nsMsgKeyArray nsFolderCompactState::m_keyArray [protected, inherited]

Definition at line 93 of file nsMsgFolderCompactor.h.

Definition at line 99 of file nsMsgFolderCompactor.h.

Definition at line 88 of file nsMsgFolderCompactor.h.

Definition at line 109 of file nsMsgFolderCompactor.h.

Definition at line 113 of file nsMsgFolderCompactor.h.

Definition at line 107 of file nsMsgFolderCompactor.h.

PRInt32 nsFolderCompactState::m_size [protected, inherited]

Definition at line 94 of file nsMsgFolderCompactor.h.

Definition at line 110 of file nsMsgFolderCompactor.h.

Definition at line 96 of file nsMsgFolderCompactor.h.

nsresult nsFolderCompactState::m_status [protected, inherited]

Definition at line 98 of file nsMsgFolderCompactor.h.

Definition at line 111 of file nsMsgFolderCompactor.h.

Definition at line 101 of file nsMsgFolderCompactor.h.


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