Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions
imgCache Class Reference

#include <imgCache.h>

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

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_IMGICACHE
NS_DECL_NSIOBSERVER 
imgCache ()
virtual ~imgCache ()
void clearCache (in boolean chrome)
 Evict images from the cache.
void removeEntry (in nsIURI uri)
 Evict images from the cache.
nsIProperties findEntryProperties (in nsIURI uri)
 Find Properties Used to get properties such as 'type' and 'content-disposition' 'type' is a nsISupportsCString containing the images' mime type such as 'image/png' 'content-disposition' will be a nsISupportsCString containing the header If you call this before any data has been loaded from a URI, it will succeed, but come back empty.
void observe (in nsISupports aSubject, in string aTopic, in wstring aData)
 Observe will be called when there is a notification for the topic |aTopic|.

Static Public Member Functions

static nsresult Init ()
static void Shutdown ()
static PRBool Put (nsIURI *aKey, imgRequest *request, nsICacheEntryDescriptor **aEntry)
static PRBool Get (nsIURI *aKey, PRBool *aHasExpired, imgRequest **aRequest, nsICacheEntryDescriptor **aEntry)
static PRBool Remove (nsIURI *aKey)
static nsresult ClearChromeImageCache ()
static nsresult ClearImageCache ()

Detailed Description

Definition at line 58 of file imgCache.h.


Constructor & Destructor Documentation

Definition at line 62 of file imgCache.cpp.

{
  /* member initializers and constructor code */
}

Here is the caller graph for this function:

imgCache::~imgCache ( ) [virtual]

Definition at line 67 of file imgCache.cpp.

{
  /* destructor code */
}

Member Function Documentation

void imgICache::clearCache ( in boolean  chrome) [inherited]

Evict images from the cache.

Parameters:
chromeIf TRUE, evict only chrome images. If FALSE, evict everything except chrome images.

Definition at line 188 of file imgCache.cpp.

{
  if (!gChromeSession)
    return NS_OK;

  return gChromeSession->EvictEntries();
}

Definition at line 196 of file imgCache.cpp.

{
  if (!gSession)
    return NS_OK;

  return gSession->EvictEntries();
}

Find Properties Used to get properties such as 'type' and 'content-disposition' 'type' is a nsISupportsCString containing the images' mime type such as 'image/png' 'content-disposition' will be a nsISupportsCString containing the header If you call this before any data has been loaded from a URI, it will succeed, but come back empty.

Parameters:
uriThe URI to look up.
Returns:
NULL if the URL was not found in the cache
PRBool imgCache::Get ( nsIURI aKey,
PRBool aHasExpired,
imgRequest **  aRequest,
nsICacheEntryDescriptor **  aEntry 
) [static]

Definition at line 256 of file imgCache.cpp.

{
  LOG_STATIC_FUNC(gImgLog, "imgCache::Get");

  nsresult rv;

  nsCOMPtr<nsICacheSession> ses;
  GetCacheSession(aKey, getter_AddRefs(ses));
  if (!ses) return PR_FALSE;

  nsCAutoString spec;
  aKey->GetAsciiSpec(spec);

  nsCOMPtr<nsICacheEntryDescriptor> entry;

  rv = ses->OpenCacheEntry(spec, nsICache::ACCESS_READ, nsICache::BLOCKING, getter_AddRefs(entry));

  if (NS_FAILED(rv) || !entry)
    return PR_FALSE;

  if (aHasExpired) {
    PRUint32 expirationTime;
    rv = entry->GetExpirationTime(&expirationTime);
    if (NS_FAILED(rv) || (expirationTime <= SecondsFromPRTime(PR_Now()))) {
      *aHasExpired = PR_TRUE;
    } else {
      *aHasExpired = PR_FALSE;
    }
    // Special treatment for file URLs - entry has expired if file has changed
    nsCOMPtr<nsIFileURL> fileUrl(do_QueryInterface(aKey));
    if (fileUrl) {
      PRUint32 lastModTime;
      entry->GetLastModified(&lastModTime);

      nsCOMPtr<nsIFile> theFile;
      rv = fileUrl->GetFile(getter_AddRefs(theFile));
      if (NS_SUCCEEDED(rv)) {
        PRInt64 fileLastMod;
        rv = theFile->GetLastModifiedTime(&fileLastMod);
        if (NS_SUCCEEDED(rv)) {
          // nsIFile uses millisec, NSPR usec
          PRInt64 one_thousand = LL_INIT(0, 1000);
          LL_MUL(fileLastMod, fileLastMod, one_thousand);
          *aHasExpired = SecondsFromPRTime((PRTime)fileLastMod) > lastModTime;
        }
      }
    }
  }

  nsCOMPtr<nsISupports> sup;
  entry->GetCacheElement(getter_AddRefs(sup));

  *aRequest = NS_REINTERPRET_CAST(imgRequest*, sup.get());
  NS_IF_ADDREF(*aRequest);

  *aEntry = entry;
  NS_ADDREF(*aEntry);

  return PR_TRUE;
}

Here is the call graph for this function:

nsresult imgCache::Init ( void  ) [static]

Definition at line 72 of file imgCache.cpp.

{
  imgCache* cache = new imgCache();
  if(!cache) return NS_ERROR_OUT_OF_MEMORY;

  nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1");
  if (os) {
    os->AddObserver(cache, "memory-pressure", PR_FALSE);
    os->AddObserver(cache, "chrome-flush-skin-caches", PR_FALSE);
    os->AddObserver(cache, "chrome-flush-caches", PR_FALSE);
  }
  
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller 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.
PRBool imgCache::Put ( nsIURI aKey,
imgRequest request,
nsICacheEntryDescriptor **  aEntry 
) [static]

Definition at line 206 of file imgCache.cpp.

{
  LOG_STATIC_FUNC(gImgLog, "imgCache::Put");

  nsresult rv;

  nsCOMPtr<nsICacheSession> ses;
  GetCacheSession(aKey, getter_AddRefs(ses));
  if (!ses) return PR_FALSE;

  nsCAutoString spec;
  aKey->GetAsciiSpec(spec);

  nsCOMPtr<nsICacheEntryDescriptor> entry;

  rv = ses->OpenCacheEntry(spec, nsICache::ACCESS_WRITE, nsICache::BLOCKING, getter_AddRefs(entry));

  if (NS_FAILED(rv) || !entry)
    return PR_FALSE;

  nsCOMPtr<nsISupports> sup = NS_REINTERPRET_CAST(nsISupports*, request);
  entry->SetCacheElement(sup);

  entry->MarkValid();

  // If file, force revalidation on expiration
  PRBool isFile;
  aKey->SchemeIs("file", &isFile);
  if (isFile)
    entry->SetMetaDataElement("MustValidateIfExpired", "true");

  *aEntry = entry;
  NS_ADDREF(*aEntry);

  return PR_TRUE;
}

Here is the call graph for this function:

PRBool imgCache::Remove ( nsIURI aKey) [static]

Definition at line 318 of file imgCache.cpp.

{
  LOG_STATIC_FUNC(gImgLog, "imgCache::Remove");
  if (!aKey) return PR_FALSE;

  nsresult rv;
  nsCOMPtr<nsICacheSession> ses;
  GetCacheSession(aKey, getter_AddRefs(ses));
  if (!ses) return PR_FALSE;

  nsCAutoString spec;
  aKey->GetAsciiSpec(spec);

  nsCOMPtr<nsICacheEntryDescriptor> entry;

  rv = ses->OpenCacheEntry(spec, nsICache::ACCESS_READ, nsICache::BLOCKING, getter_AddRefs(entry));

  if (NS_FAILED(rv) || !entry)
    return PR_FALSE;

  entry->Doom();

  return PR_TRUE;
}

Here is the call graph for this function:

void imgICache::removeEntry ( in nsIURI  uri) [inherited]

Evict images from the cache.

Parameters:
uriThe URI to remove.
Returns:
NS_OK if uri was removed from the cache. NS_ERROR_NOT_AVAILABLE if uri was unable to be removed from the cache.
void imgCache::Shutdown ( ) [static]

Definition at line 181 of file imgCache.cpp.

Here is the caller graph for this function:


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