Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
nsEmbedGlobalHistory.cpp File Reference
#include "nsEmbedGlobalHistory.h"
#include "nsIObserver.h"
#include "nsIObserverService.h"
#include "nsWeakReference.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsHashtable.h"
#include "nsInt64.h"
#include "prtypes.h"
#include "nsFixedSizeAllocator.h"
#include "nsVoidArray.h"
#include "nsIPrefService.h"

Go to the source code of this file.

Classes

class  HistoryEntry

Defines

#define PREF_BROWSER_HISTORY_EXPIRE_DAYS   "browser.history_expire_days"

Functions

static nsresult readEntry (FILE *inStream, nsCString &url, HistoryEntry **entry)
static nsresult writeEntry (FILE *outStm, nsCStringKey *url, HistoryEntry *entry)
static PRIntn PR_CALLBACK enumWriteEntry (nsHashKey *aKey, void *aData, void *closure)
static PRIntn PR_CALLBACK enumWriteEntryIfUnwritten (nsHashKey *aKey, void *aData, void *closure)
static PRIntn PR_CALLBACK enumDeleteEntry (nsHashKey *aKey, void *aData, void *closure)
static nsresult parsePRInt64 (FILE *inStm, PRInt64 &outValue)
static nsresult writePRInt64 (FILE *outStm, const PRInt64 &inValue)

Variables

static const PRInt32 kNewEntriesBetweenFlush = 10
static const PRUint32 kDefaultExpirationIntervalDays = 7
static const PRInt64 kMSecsPerDay = LL_INIT(0, 60 * 60 * 24 * 1000)
static const PRInt64 kOneThousand = LL_INIT(0, 1000)

Define Documentation

#define PREF_BROWSER_HISTORY_EXPIRE_DAYS   "browser.history_expire_days"

Definition at line 59 of file nsEmbedGlobalHistory.cpp.


Function Documentation

PRIntn PR_CALLBACK enumDeleteEntry ( nsHashKey *  aKey,
void aData,
void closure 
) [static]

Definition at line 544 of file nsEmbedGlobalHistory.cpp.

Here is the caller graph for this function:

PRIntn PR_CALLBACK enumWriteEntry ( nsHashKey *  aKey,
void aData,
void closure 
) [static]

Definition at line 508 of file nsEmbedGlobalHistory.cpp.

{
  FILE *outStm = NS_STATIC_CAST(FILE*, closure);
  if (!outStm)
    return kHashEnumerateStop;
  nsCStringKey *stringKey = NS_STATIC_CAST(nsCStringKey*, aKey);
  if (!stringKey)
    return kHashEnumerateStop;
  HistoryEntry *entry = NS_STATIC_CAST(HistoryEntry*, aData);
  if (!entry)
    return kHashEnumerateStop;

  nsresult rv = writeEntry(outStm, stringKey, entry);
    
  return NS_SUCCEEDED(rv) ? kHashEnumerateNext : kHashEnumerateStop;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRIntn PR_CALLBACK enumWriteEntryIfUnwritten ( nsHashKey *  aKey,
void aData,
void closure 
) [static]

Definition at line 525 of file nsEmbedGlobalHistory.cpp.

{
  FILE *outStm = NS_STATIC_CAST(FILE*, closure);
  if (!outStm)
    return kHashEnumerateStop;
  nsCStringKey *stringKey = NS_STATIC_CAST(nsCStringKey*, aKey);
  if (!stringKey)
    return kHashEnumerateStop;
  HistoryEntry *entry = NS_STATIC_CAST(HistoryEntry*, aData);
  if (!entry)
    return kHashEnumerateStop;

  nsresult rv = NS_OK;
  if (!entry->GetIsWritten())
    rv = writeEntry(outStm, stringKey, entry);
    
  return NS_SUCCEEDED(rv) ? kHashEnumerateNext : kHashEnumerateStop;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult parsePRInt64 ( FILE inStm,
PRInt64 outValue 
) [static]

Definition at line 393 of file nsEmbedGlobalHistory.cpp.

{
  int c, charsRead = 0;
  nsInt64 value = 0;

  while (PR_TRUE) {
    c = fgetc(inStm);
    if (c == EOF || !isdigit(c))
      break;
      
    ++charsRead;
    PRInt32 digit = c - '0';
    value *= nsInt64(10);
    value += nsInt64(digit);
  }
  if (!charsRead)
    return NS_ERROR_FAILURE;
  outValue = value;
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult readEntry ( FILE inStream,
nsCString url,
HistoryEntry **  entry 
) [static]

Definition at line 414 of file nsEmbedGlobalHistory.cpp.

{
  nsresult rv;

  // Get the last visted date
  PRInt64 value;
  rv = parsePRInt64(inStream, value);
  if (NS_FAILED(rv))
    return rv;
  
  // Get the URL
  int c;
  char buf[1024];
  char *next, *end = buf + sizeof(buf);
    
  outURL.Truncate(0);
  next = buf;
  
  while (PR_TRUE) {
    c = fgetc(inStream);
    
    if (c == EOF)
      break;
    else if (c == '\n')
      break;
    else if (c == '\r') {
      c = fgetc(inStream);
      if (c != '\n')
        ungetc(c, inStream);
      break;
    }
    else {
      *next++ = c;
      if (next >= end) {
        outURL.Append(buf, next - buf);
        next = buf;
      }
    }
  }
  if (next > buf)
    outURL.Append(buf, next - buf);
    
  if (!outURL.Length() && c == EOF)
    return NS_ERROR_FAILURE;
    
  *outEntry = new HistoryEntry;
  if (!*outEntry)
    return NS_ERROR_OUT_OF_MEMORY;
  (*outEntry)->SetLastVisitTime(value);
  (*outEntry)->SetIsWritten();
    
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult writeEntry ( FILE outStm,
nsCStringKey *  url,
HistoryEntry entry 
) [static]

Definition at line 488 of file nsEmbedGlobalHistory.cpp.

{
  writePRInt64(outStm, entry->GetLastVisitTime());
  fputc(':', outStm);

  fputs(url->GetString(), outStm);
  entry->SetIsWritten();

#if defined (XP_WIN) || defined(XP_OS2)
  fputc('\r', outStm);
  fputc('\n', outStm);
#elif defined(XP_UNIX)
  fputc('\n', outStm);
#else
  fputc('\r', outStm);
#endif

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult writePRInt64 ( FILE outStm,
const PRInt64 inValue 
) [static]

Definition at line 468 of file nsEmbedGlobalHistory.cpp.

{
  nsInt64 value(inValue);
  
  if (value == nsInt64(0)) {
    fputc('0', outStm);
    return NS_OK;
  }
  
  nsCAutoString tempString;

  while (value != nsInt64(0)) {
    PRInt32 ones = PRInt32(value % nsInt64(10));
    value /= nsInt64(10);
    tempString.Insert(char('0' + ones), 0);
  }
  int result = fputs(tempString.get(), outStm);
  return (result == EOF) ? NS_ERROR_FAILURE : NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 54 of file nsEmbedGlobalHistory.cpp.

const PRInt64 kMSecsPerDay = LL_INIT(0, 60 * 60 * 24 * 1000) [static]

Definition at line 56 of file nsEmbedGlobalHistory.cpp.

Definition at line 52 of file nsEmbedGlobalHistory.cpp.

const PRInt64 kOneThousand = LL_INIT(0, 1000) [static]

Definition at line 57 of file nsEmbedGlobalHistory.cpp.