Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes
nsEmbedGlobalHistory Class Reference

#include <nsEmbedGlobalHistory.h>

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

List of all members.

Public Member Functions

 nsEmbedGlobalHistory ()
virtual ~nsEmbedGlobalHistory ()
NS_IMETHOD Init ()
void addPage (in string aURL)
 addPage Add a page to the history
boolean isVisited (in string aURL)
 isVisited Checks to see if the given page is in history
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 Types

enum  { kFlushModeAppend, kFlushModeFullWrite }

Protected Member Functions

nsresult LoadData ()
nsresult FlushData (PRIntn mode=kFlushModeFullWrite)
nsresult ResetData ()
nsresult GetHistoryFile ()
PRBool EntryHasExpired (HistoryEntry *entry)

Static Protected Member Functions

static PRIntn PR_CALLBACK enumRemoveEntryIfExpired (nsHashKey *aKey, void *aData, void *closure)

Protected Attributes

PRBool mDataIsLoaded
PRInt32 mEntriesAddedSinceFlush
nsCOMPtr< nsILocalFilemHistoryFile
nsHashtable * mURLTable
PRInt64 mExpirationInterval

Detailed Description

Definition at line 62 of file nsEmbedGlobalHistory.h.


Member Enumeration Documentation

anonymous enum [protected]
Enumerator:
kFlushModeAppend 
kFlushModeFullWrite 

Definition at line 77 of file nsEmbedGlobalHistory.h.


Constructor & Destructor Documentation

Definition at line 176 of file nsEmbedGlobalHistory.cpp.

Here is the call graph for this function:


Member Function Documentation

void nsIGlobalHistory::addPage ( in string  aURL) [inherited]

addPage Add a page to the history

Parameters:
aURLthe url to the page

Definition at line 358 of file nsEmbedGlobalHistory.cpp.

{
  // convert "now" from microsecs to millisecs
  PRInt64 nowInMilliSecs = PR_Now(); 
  LL_DIV(nowInMilliSecs, nowInMilliSecs, kOneThousand);

  // determine when the entry would have expired
  PRInt64 expirationIntervalAgo;
  LL_SUB(expirationIntervalAgo, nowInMilliSecs, mExpirationInterval);

  PRInt64 lastVisitTime = entry->GetLastVisitTime();
  return (LL_CMP(lastVisitTime, <, expirationIntervalAgo));
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRIntn PR_CALLBACK nsEmbedGlobalHistory::enumRemoveEntryIfExpired ( nsHashKey *  aKey,
void aData,
void closure 
) [static, protected]

Definition at line 372 of file nsEmbedGlobalHistory.cpp.

Here is the call graph for this function:

Definition at line 309 of file nsEmbedGlobalHistory.cpp.

{  
  if (mHistoryFile) {

    const char* openMode = (mode == kFlushModeAppend ? "a" : "w");
    FILE *stdFile;
    nsresult rv = mHistoryFile->OpenANSIFileDesc(openMode, &stdFile);
    if (NS_FAILED(rv)) return rv;

    // Before flushing either way, remove dead entries
    mURLTable->Enumerate(enumRemoveEntryIfExpired, this);  
    
    if (mode == kFlushModeAppend)
        mURLTable->Enumerate(enumWriteEntryIfUnwritten, stdFile);
    else
        mURLTable->Enumerate(enumWriteEntry, stdFile);
    
    mEntriesAddedSinceFlush = 0;
    fclose(stdFile);
  }
  return NS_OK; 
}

Here is the call graph for this function:

Definition at line 341 of file nsEmbedGlobalHistory.cpp.

{
  nsresult rv;

  // Get the history file in our profile dir.
  // Notice we are not just getting NS_APP_HISTORY_50_FILE
  // because it is used by the "real" global history component.
  
  nsCOMPtr<nsIFile> aFile; 
  rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(aFile));
  NS_ENSURE_SUCCESS(rv, rv);
  rv = aFile->Append(NS_LITERAL_STRING("history.txt"));
  NS_ENSURE_SUCCESS(rv, rv);
  mHistoryFile = do_QueryInterface(aFile);
  return NS_OK;
}

Here is the call graph for this function:

Definition at line 183 of file nsEmbedGlobalHistory.cpp.

{
  mURLTable = new nsHashtable;
  NS_ENSURE_TRUE(mURLTable, NS_ERROR_OUT_OF_MEMORY);
  
  // Get Pref and convert to millisecs
  nsCOMPtr<nsIPrefBranch> prefs(do_GetService("@mozilla.org/preferences-service;1"));
  if (prefs) {
    PRInt32 expireDays;
    prefs->GetIntPref(PREF_BROWSER_HISTORY_EXPIRE_DAYS, &expireDays);
    LL_I2L(mExpirationInterval, expireDays);
    LL_MUL(mExpirationInterval, mExpirationInterval, kMSecsPerDay);
  }
  
  // register to observe profile changes
  nsCOMPtr<nsIObserverService> observerService = 
       do_GetService("@mozilla.org/observer-service;1");
  NS_ASSERTION(observerService, "failed to get observer service");
  if (observerService)
    observerService->AddObserver(this, "profile-before-change", PR_TRUE);

  return NS_OK;
}

Here is the call graph for this function:

isVisited Checks to see if the given page is in history

Returns:
true if a page has been passed into addPage().
Parameters:
aURLthe url to the page

Definition at line 269 of file nsEmbedGlobalHistory.cpp.

{
  if (!mDataIsLoaded) {
    
    nsresult rv;            
    PRBool exists;

    mDataIsLoaded = PR_TRUE;

    rv = GetHistoryFile();
    if (NS_FAILED(rv))
      return rv;
    rv = mHistoryFile->Exists(&exists);
    if (NS_FAILED(rv))
      return rv;
    if (!exists)
      return NS_OK;
    
    FILE *stdFile;
    rv = mHistoryFile->OpenANSIFileDesc("r", &stdFile);
    if (NS_FAILED(rv))
      return rv;
      
    nsCAutoString outString;
    HistoryEntry *newEntry;      
    while (NS_SUCCEEDED(readEntry(stdFile, outString, &newEntry))) {
      if (EntryHasExpired(newEntry)) {
        delete newEntry;
      }
      else {
        nsCStringKey asKey(outString);
        mURLTable->Put(&asKey, newEntry);
      }
    }
    
    fclose(stdFile);
  }
  return NS_OK;
}

Here is the call 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 332 of file nsEmbedGlobalHistory.cpp.

Here is the call graph for this function:


Member Data Documentation

Definition at line 89 of file nsEmbedGlobalHistory.h.

Definition at line 90 of file nsEmbedGlobalHistory.h.

Definition at line 93 of file nsEmbedGlobalHistory.h.

Definition at line 91 of file nsEmbedGlobalHistory.h.

nsHashtable* nsEmbedGlobalHistory::mURLTable [protected]

Definition at line 92 of file nsEmbedGlobalHistory.h.


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