PLAN (Done):

Improve the favicon cache.

DONE This has been done using tko's method below.

It has a variety of problems at the moment:

In theory we only need to store images on disk for favicons that are needed not as a result of a page load. This means that just bookmarks (for the moment, history doesn't use them at the moment) will need them stored on disk.

What I propose is:

When a page is loaded that has a favicon:

When an object wants a favicon

Peridocally, the favicon cache will cull the GdkPixbuf?'s from memory that haven't been used in a while, it will also save images that are used for bookmarks to disk.

To download icons, we should use something like tko's code in although we need to check to see whether that uses the mozilla cache.

-- CrispinFlowerday - Dec 2004

Sounds little backwards (the GaleonFaviconUser thingie.) Braindumping here.

Two kinds of favicons:

  1. Persistent.
    • used for bookmarks
    • backed up by a local copy
    • need to maintain page URL --> favicon URL --> local file mapping (the latter part could be implicit)
    • local copy is updated (and old one discarded) whenever the page URL --> favicon URL mapping, or the favicon itself, changes
    • local copy is removed when the (last) bookmark is removed
  2. Transient.
    • used everywhere else, location entry, tab labels, Go menu, ...
    • use browser cache for storage

The GaleonFaviconCache API could be something like:

GaleonFavicon *galeon_favicon_cache_get            (self, const char *page_url);
void           galeon_favicon_cache_set_url        (self, const char *page_url, const char *favicon_url);
void           galeon_favicon_cache_set_persistent (self, const char *page_url, gboolean    is_persistent);

Internally the favicon cache can maintain a "page URL" --> GaleonFavicon mapping, whenever favicon changes all "subscribed" images are updated. We could also keep a favicon URL --> GdkPixbuf mapping in memory to avoid loading the same favicon multiple times. (Slight speed increase, saves some memory.)

Since the GaleonFaviconCache is providing GaleonFavicon rather than GdkPixbuf we can load the pixbuf contents asynchronously whenever. If a pixbuf is already in memory we can use it immediately. Otherwise we'll load the favicon from local file or cache only. We will not try to load anything from the network when the galeon_favicon_cache_get() is called.

Only when (during loading the page) the galeon_favicon_cache_set_url() is called (and there is someone "subscribed" to the page URL) we will attempt loading the favicon from remote server in addition to local copy and browser cache. If the page URL was flagged persistent, the local copy should be updated, otherwise the favicon should be loaded directly into a GdkPixbuf, no need for extra files (need to extend GaleonEmbedPersist a little, I guess.) Once the pixbuf has finished loading we'll just iterate through the "subscribers" for the page URL and update the =GaleonFavicon=s with the new pixbuf.

The page URL --> favicon URL mapping and the favicon contents need to be saved on the disk only for persistent favicons, i.e. bookmarks.

-- TommiKomulainen - 03 Jan 2005