diff options
Diffstat (limited to 'content/hlcache.c')
-rw-r--r-- | content/hlcache.c | 87 |
1 files changed, 68 insertions, 19 deletions
diff --git a/content/hlcache.c b/content/hlcache.c index 33436f7ed..5cba88bc6 100644 --- a/content/hlcache.c +++ b/content/hlcache.c @@ -30,12 +30,16 @@ #include "utils/messages.h" #include "utils/ring.h" #include "utils/utils.h" +#include "netsurf/inttypes.h" #include "netsurf/misc.h" #include "netsurf/content.h" #include "desktop/gui_internal.h" #include "content/mimesniff.h" #include "content/hlcache.h" +// Note, this is *ONLY* so that we can abort cleanly during shutdown of the cache +#include "content/content_protected.h" +#include "content/content_factory.h" typedef struct hlcache_entry hlcache_entry; typedef struct hlcache_retrieval_ctx hlcache_retrieval_ctx; @@ -104,9 +108,10 @@ static struct hlcache_s *hlcache = NULL; /** * Attempt to clean the cache */ -static void hlcache_clean(void *ignored) +static void hlcache_clean(void *force_clean_flag) { hlcache_entry *entry, *next; + bool force_clean = (force_clean_flag != NULL); for (entry = hlcache->content_list; entry != NULL; entry = next) { next = entry->next; @@ -114,12 +119,17 @@ static void hlcache_clean(void *ignored) if (entry->content == NULL) continue; - if (content__get_status(entry->content) == CONTENT_STATUS_LOADING) - continue; - if (content_count_users(entry->content) != 0) continue; + if (content__get_status(entry->content) == CONTENT_STATUS_LOADING) { + if (force_clean == false) + continue; + NSLOG(netsurf, DEBUG, "Forcing content cleanup during shutdown"); + content_abort(entry->content); + content_set_error(entry->content); + } + /** \todo This is over-zealous: all unused contents * will be immediately destroyed. Ideally, we want to * purge all unused contents that are using stale @@ -353,7 +363,8 @@ static nserror hlcache_migrate_ctx(hlcache_retrieval_ctx *ctx, hlcache_event hlevent; hlevent.type = CONTENT_MSG_ERROR; - hlevent.data.error = messages_get("MiscError"); + hlevent.data.errordata.errorcode = NSERROR_UNKNOWN; + hlevent.data.errordata.errormsg = messages_get("MiscError"); ctx->handle->cb(ctx->handle, &hlevent, ctx->handle->pw); @@ -385,7 +396,8 @@ static nserror hlcache_migrate_ctx(hlcache_retrieval_ctx *ctx, hlcache_event hlevent; hlevent.type = CONTENT_MSG_ERROR; - hlevent.data.error = messages_get("UnacceptableType"); + hlevent.data.errordata.errorcode = NSERROR_UNKNOWN; + hlevent.data.errordata.errormsg = messages_get("UnacceptableType"); ctx->handle->cb(ctx->handle, &hlevent, ctx->handle->pw); @@ -413,8 +425,10 @@ static nserror hlcache_migrate_ctx(hlcache_retrieval_ctx *ctx, * \param pw Pointer to client-specific data * \return NSERROR_OK on success, appropriate error otherwise */ -static nserror hlcache_llcache_callback(llcache_handle *handle, - const llcache_event *event, void *pw) +static nserror +hlcache_llcache_callback(llcache_handle *handle, + const llcache_event *event, + void *pw) { hlcache_retrieval_ctx *ctx = pw; lwc_string *effective_type = NULL; @@ -423,6 +437,17 @@ static nserror hlcache_llcache_callback(llcache_handle *handle, assert(ctx->llcache == handle); switch (event->type) { + case LLCACHE_EVENT_GOT_CERTS: + /* Pass them on upward */ + if (ctx->handle->cb != NULL) { + hlcache_event hlevent; + + hlevent.type = CONTENT_MSG_SSL_CERTS; + hlevent.data.chain = event->data.chain; + + ctx->handle->cb(ctx->handle, &hlevent, ctx->handle->pw); + } + break; case LLCACHE_EVENT_HAD_HEADERS: error = mimesniff_compute_effective_type(llcache_handle_get_header(handle, "Content-Type"), NULL, 0, ctx->flags & HLCACHE_RETRIEVE_SNIFF_TYPE, @@ -481,8 +506,9 @@ static nserror hlcache_llcache_callback(llcache_handle *handle, if (ctx->handle->cb != NULL) { hlcache_event hlevent; - hlevent.type = CONTENT_MSG_ERRORCODE; - hlevent.data.errorcode = error; + hlevent.type = CONTENT_MSG_ERROR; + hlevent.data.errordata.errorcode = error; + hlevent.data.errordata.errormsg = NULL; ctx->handle->cb(ctx->handle, &hlevent, ctx->handle->pw); } @@ -492,7 +518,8 @@ static nserror hlcache_llcache_callback(llcache_handle *handle, hlcache_event hlevent; hlevent.type = CONTENT_MSG_ERROR; - hlevent.data.error = event->data.msg; + hlevent.data.errordata.errorcode = event->data.error.code; + hlevent.data.errordata.errormsg = event->data.error.msg; ctx->handle->cb(ctx->handle, &hlevent, ctx->handle->pw); } @@ -566,7 +593,7 @@ void hlcache_finalise(void) num_contents++; } - NSLOG(netsurf, INFO, "%d contents remain before cache drain", + NSLOG(netsurf, INFO, "%"PRIu32" contents remain before cache drain", num_contents); /* Drain cache */ @@ -581,12 +608,27 @@ void hlcache_finalise(void) } } while (num_contents > 0 && num_contents != prev_contents); - NSLOG(netsurf, INFO, "%d contents remaining:", num_contents); + NSLOG(netsurf, INFO, "%"PRIu32" contents remaining after being polite", + num_contents); + + /* Drain cache again, forcing the matter */ + do { + prev_contents = num_contents; + + hlcache_clean(&entry); // Any non-NULL pointer will do + + for (num_contents = 0, entry = hlcache->content_list; + entry != NULL; entry = entry->next) { + num_contents++; + } + } while (num_contents > 0 && num_contents != prev_contents); + + NSLOG(netsurf, INFO, "%"PRIu32" contents remaining:", num_contents); for (entry = hlcache->content_list; entry != NULL; entry = entry->next) { hlcache_handle entry_handle = { entry, NULL, NULL }; if (entry->content != NULL) { - NSLOG(netsurf, INFO, " %p : %s (%d users)", + NSLOG(netsurf, INFO, " %p : %s (%"PRIu32" users)", entry, nsurl_access(hlcache_handle_get_url(&entry_handle)), content_count_users(entry->content)); @@ -622,6 +664,9 @@ void hlcache_finalise(void) NSLOG(netsurf, INFO, "hit/miss %d/%d", hlcache->hit_count, hlcache->miss_count); + /* De-schedule ourselves */ + guit->misc->schedule(-1, hlcache_clean, NULL); + free(hlcache); hlcache = NULL; @@ -630,11 +675,15 @@ void hlcache_finalise(void) } /* See hlcache.h for documentation */ -nserror hlcache_handle_retrieve(nsurl *url, uint32_t flags, - nsurl *referer, llcache_post_data *post, - hlcache_handle_callback cb, void *pw, - hlcache_child_context *child, - content_type accepted_types, hlcache_handle **result) +nserror +hlcache_handle_retrieve(nsurl *url, + uint32_t flags, + nsurl *referer, + llcache_post_data *post, + hlcache_handle_callback cb, void *pw, + hlcache_child_context *child, + content_type accepted_types, + hlcache_handle **result) { hlcache_retrieval_ctx *ctx; nserror error; |