Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions
nsGlobalHistory.cpp File Reference
#include "nsNetUtil.h"
#include "nsGlobalHistory.h"
#include "nsCRT.h"
#include "nsIEnumerator.h"
#include "nsIServiceManager.h"
#include "nsEnumeratorUtils.h"
#include "nsRDFCID.h"
#include "nsIDirectoryService.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsString.h"
#include "nsReadableUtils.h"
#include "nsUnicharUtils.h"
#include "nsXPIDLString.h"
#include "plhash.h"
#include "plstr.h"
#include "prprf.h"
#include "prtime.h"
#include "rdf.h"
#include "nsCOMArray.h"
#include "nsIIOService.h"
#include "nsILocalFile.h"
#include "nsIURL.h"
#include "nsNetCID.h"
#include "nsInt64.h"
#include "nsMorkCID.h"
#include "nsIMdbFactoryFactory.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch2.h"
#include "nsIObserverService.h"
#include "nsITextToSubURI.h"

Go to the source code of this file.

Classes

struct  matchExpiration_t
struct  matchHost_t
struct  matchSearchTerm_t
struct  matchQuery_t
class  tokenPair
class  searchTerm
struct  searchQuery

Defines

#define PREF_BRANCH_BASE   "browser."
#define PREF_BROWSER_HISTORY_EXPIRE_DAYS   "history_expire_days"
#define PREF_AUTOCOMPLETE_ONLY_TYPED   "urlbar.matchOnlyTyped"
#define PREF_AUTOCOMPLETE_ENABLED   "urlbar.autocomplete.enabled"
#define FIND_BY_AGEINDAYS_PREFIX   "find:datasource=history&match=AgeInDays&method="
#define HISTORY_URI_LENGTH_MAX   65536
#define HISTORY_TITLE_LENGTH_MAX   4096
#define HISTORY_SYNC_TIMEOUT   (10 * PR_MSEC_PER_SEC)
#define HISTORY_EXPIRE_NOW_TIMEOUT   (3 * PR_MSEC_PER_SEC)
#define MSECS_PER_DAY   (PR_MSEC_PER_SEC * 60 * 60 * 24)

Functions

static NS_DEFINE_CID (kRDFServiceCID, NS_RDFSERVICE_CID)
static NS_DEFINE_CID (kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID)
static PRBool HasCell (nsIMdbEnv *aEnv, nsIMdbRow *aRow, mdb_column aCol)
static PRTime NormalizeTime (PRTime aTime)
static PRInt32 GetAgeInDays (PRTime aNormalizedNow, PRTime aDate)
static PRBool matchAgeInDaysCallback (nsIMdbRow *row, void *aClosure)
static PRBool matchExpirationCallback (nsIMdbRow *row, void *aClosure)
static PRBool matchAllCallback (nsIMdbRow *row, void *aClosure)
static PRBool matchHostCallback (nsIMdbRow *row, void *aClosure)
static PRBool matchQueryCallback (nsIMdbRow *row, void *aClosure)
 NS_IMPL_ISUPPORTS7 (nsGlobalHistory, nsIGlobalHistory2, nsIBrowserHistory, nsIObserver, nsISupportsWeakReference, nsIRDFDataSource, nsIRDFRemoteDataSource, nsIAutoCompleteSearch) NS_IMETHODIMP nsGlobalHistory

Class Documentation

struct matchExpiration_t

Definition at line 138 of file nsGlobalHistory.cpp.

Collaboration diagram for matchExpiration_t:
Class Members
PRTime * expirationDate
nsGlobalHistory * history
struct matchHost_t

Definition at line 143 of file nsGlobalHistory.cpp.

Collaboration diagram for matchHost_t:
Class Members
PRBool entireDomain
nsGlobalHistory * history
const char * host
struct matchSearchTerm_t

Definition at line 149 of file nsGlobalHistory.cpp.

Collaboration diagram for matchSearchTerm_t:
Class Members
nsIMdbEnv * env
nsGlobalHistory * globalHist
PRBool haveClosure
PRInt32 intValue
PRTime now
nsIMdbStore * store
searchTerm * term
struct matchQuery_t

Definition at line 159 of file nsGlobalHistory.cpp.

Collaboration diagram for matchQuery_t:
Class Members
nsGlobalHistory * history
searchQuery * query
struct searchQuery

Definition at line 207 of file nsGlobalHistory.cpp.

Class Members
mdb_column groupBy
nsVoidArray terms

Define Documentation

#define FIND_BY_AGEINDAYS_PREFIX   "find:datasource=history&match=AgeInDays&method="

Definition at line 114 of file nsGlobalHistory.cpp.

Definition at line 126 of file nsGlobalHistory.cpp.

Definition at line 122 of file nsGlobalHistory.cpp.

Definition at line 119 of file nsGlobalHistory.cpp.

Definition at line 118 of file nsGlobalHistory.cpp.

#define MSECS_PER_DAY   (PR_MSEC_PER_SEC * 60 * 60 * 24)

Definition at line 128 of file nsGlobalHistory.cpp.

#define PREF_AUTOCOMPLETE_ENABLED   "urlbar.autocomplete.enabled"

Definition at line 112 of file nsGlobalHistory.cpp.

#define PREF_AUTOCOMPLETE_ONLY_TYPED   "urlbar.matchOnlyTyped"

Definition at line 111 of file nsGlobalHistory.cpp.

#define PREF_BRANCH_BASE   "browser."

Definition at line 109 of file nsGlobalHistory.cpp.

#define PREF_BROWSER_HISTORY_EXPIRE_DAYS   "history_expire_days"

Definition at line 110 of file nsGlobalHistory.cpp.


Function Documentation

static PRInt32 GetAgeInDays ( PRTime  aNormalizedNow,
PRTime  aDate 
) [static]

Definition at line 244 of file nsGlobalHistory.cpp.

{
  PRTime dateMidnight = NormalizeTime(aDate);

  PRTime diff;
  LL_SUB(diff, aNormalizedNow, dateMidnight);

  // two-step process since I can't seem to load
  // MSECS_PER_DAY * PR_MSEC_PER_SEC into a PRInt64 at compile time
  PRInt64 msecPerSec;
  LL_I2L(msecPerSec, PR_MSEC_PER_SEC);
  PRInt64 ageInSeconds;
  LL_DIV(ageInSeconds, diff, msecPerSec);

  PRInt32 ageSec; LL_L2I(ageSec, ageInSeconds);
  
  PRInt64 msecPerDay;
  LL_I2L(msecPerDay, MSECS_PER_DAY);
  
  PRInt64 ageInDays;
  LL_DIV(ageInDays, ageInSeconds, msecPerDay);

  PRInt32 retval;
  LL_L2I(retval, ageInDays);
  return retval;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool HasCell ( nsIMdbEnv aEnv,
nsIMdbRow aRow,
mdb_column  aCol 
) [static]

Definition at line 212 of file nsGlobalHistory.cpp.

{
  mdbYarn yarn;
  mdb_err err = aRow->AliasCellYarn(aEnv, aCol, &yarn);

  // no cell
  if (err != 0)
    return PR_FALSE;

  // if we have the cell, make sure it has a value??
  return (yarn.mYarn_Fill != 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool matchAgeInDaysCallback ( nsIMdbRow row,
void aClosure 
) [static]

Definition at line 293 of file nsGlobalHistory.cpp.

{
  matchSearchTerm_t *matchSearchTerm = (matchSearchTerm_t*)aClosure;
  const searchTerm *term = matchSearchTerm->term;
  nsIMdbEnv *env = matchSearchTerm->env;
  nsIMdbStore *store = matchSearchTerm->store;
  
  // fill in the rest of the closure if it's not filled in yet
  // this saves us from recalculating this stuff on every row
  if (!matchSearchTerm->haveClosure) {
    PRInt32 err;
    // Need to create an nsAutoString to use ToInteger
    matchSearchTerm->intValue = nsAutoString(term->text).ToInteger(&err);
    matchSearchTerm->now = NormalizeTime(PR_Now());
    if (err != 0) return PR_FALSE;
    matchSearchTerm->haveClosure = PR_TRUE;
  }
  
  // XXX convert the property to a column, get the column value

  mdb_column column;
  mdb_err err = store->StringToToken(env, "LastVisitDate", &column);
  if (err != 0) return PR_FALSE;

  mdbYarn yarn;
  err = row->AliasCellYarn(env, column, &yarn);
  if (err != 0) return PR_FALSE;
  
  PRTime rowDate;
  PR_sscanf((const char*)yarn.mYarn_Buf, "%lld", &rowDate);

  PRInt32 days = GetAgeInDays(matchSearchTerm->now, rowDate);
  
  if (term->method.Equals("is"))
    return (days == matchSearchTerm->intValue);
  else if (term->method.Equals("isgreater"))
    return (days >  matchSearchTerm->intValue);
  else if (term->method.Equals("isless"))
    return (days <  matchSearchTerm->intValue);
  
  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool matchAllCallback ( nsIMdbRow row,
void aClosure 
) [static]

Definition at line 344 of file nsGlobalHistory.cpp.

{
  return PR_TRUE;
}
static PRBool matchExpirationCallback ( nsIMdbRow row,
void aClosure 
) [static]

Definition at line 337 of file nsGlobalHistory.cpp.

{
  matchExpiration_t *expires = (matchExpiration_t*)aClosure;
  return expires->history->MatchExpiration(row, expires->expirationDate);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool matchHostCallback ( nsIMdbRow row,
void aClosure 
) [static]

Definition at line 350 of file nsGlobalHistory.cpp.

{
  matchHost_t *hostInfo = (matchHost_t*)aClosure;
  return hostInfo->history->MatchHost(row, hostInfo);
}

Here is the call graph for this function:

static PRBool matchQueryCallback ( nsIMdbRow row,
void aClosure 
) [static]

Definition at line 357 of file nsGlobalHistory.cpp.

{
  matchQuery_t *query = (matchQuery_t*)aClosure;
  return query->history->RowMatches(row, query->query, PR_TRUE);
}

Here is the call graph for this function:

static PRTime NormalizeTime ( PRTime  aTime) [static]

Definition at line 226 of file nsGlobalHistory.cpp.

{
  // normalize both now and date to midnight of the day they occur on
  PRExplodedTime explodedTime;
  PR_ExplodeTime(aTime, PR_LocalTimeParameters, &explodedTime);

  // set to midnight (0:00)
  explodedTime.tm_min =
    explodedTime.tm_hour =
    explodedTime.tm_sec =
    explodedTime.tm_usec = 0;

  return PR_ImplodeTime(&explodedTime);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static NS_DEFINE_CID ( kRDFServiceCID  ,
NS_RDFSERVICE_CID   
) [static]
static NS_DEFINE_CID ( kStringBundleServiceCID  ,
NS_STRINGBUNDLESERVICE_CID   
) [static]

Definition at line 547 of file nsGlobalHistory.cpp.

{
  PRTime now = GetNow();

  return AddPageToDatabase(aURI, aRedirect, aTopLevel, now, aReferrer);
}