diff options
author | mbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-15 23:14:44 +0000 |
---|---|---|
committer | mbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-15 23:14:44 +0000 |
commit | 0e34852ad6c4d5bc35f7000392467837211c9a87 (patch) | |
tree | 7b04317a795dbb0aae584699ad4f4a81d2ee7b3b | |
parent | aa042406ccff58edb414117877b669b5ca2d7a32 (diff) | |
download | chromium_src-0e34852ad6c4d5bc35f7000392467837211c9a87.zip chromium_src-0e34852ad6c4d5bc35f7000392467837211c9a87.tar.gz chromium_src-0e34852ad6c4d5bc35f7000392467837211c9a87.tar.bz2 |
Update benchmarking clearCache routine to be able to preserve sslhostinfo:
related entries.
* The clearCache() API is part of the benchmarking extension.
* Modified clearCache() to take an argument so that we can selectively
clear SSL information or not.
* The actual clear data call used to just call DoomAllEntries. It still
does that for clearing everything. If preserving the ssl host entries,
however, it will enumerate the cache. Ran into cache invalidation upon
calling doom, which makes the clear inefficient, but functional.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6529012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75027 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/renderer_host/render_message_filter.cc | 68 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_message_filter.h | 2 | ||||
-rw-r--r-- | chrome/common/render_messages_internal.h | 10 | ||||
-rw-r--r-- | chrome/renderer/render_thread.cc | 4 | ||||
-rw-r--r-- | chrome/renderer/render_thread.h | 4 | ||||
-rw-r--r-- | chrome/renderer/renderer_glue.cc | 4 | ||||
-rw-r--r-- | webkit/extensions/v8/benchmarking_extension.cc | 9 | ||||
-rw-r--r-- | webkit/glue/webkit_glue.h | 4 |
8 files changed, 86 insertions, 19 deletions
diff --git a/chrome/browser/renderer_host/render_message_filter.cc b/chrome/browser/renderer_host/render_message_filter.cc index f4f8514..4ae24e0 100644 --- a/chrome/browser/renderer_host/render_message_filter.cc +++ b/chrome/browser/renderer_host/render_message_filter.cc @@ -269,6 +269,55 @@ class OpenChannelToPpapiPluginCallback : public RenderMessageCompletionCallback, } }; +// Class to assist with clearing out the cache when we want to preserve +// the sslhostinfo entries. It's not very efficient, but its just for debug. +class DoomEntriesHelper { + public: + explicit DoomEntriesHelper(disk_cache::Backend* backend) + : backend_(backend), + entry_(NULL), + iter_(NULL), + ALLOW_THIS_IN_INITIALIZER_LIST(callback_(this, + &DoomEntriesHelper::CacheCallback)), + user_callback_(NULL) { + } + + void ClearCache(ClearCacheCompletion* callback) { + user_callback_ = callback; + return CacheCallback(net::OK); // Start clearing the cache. + } + + private: + void CacheCallback(int result) { + do { + if (result != net::OK) { + user_callback_->RunWithParams(Tuple1<int>(result)); + delete this; + return; + } + + if (entry_) { + // Doom all entries except those with snapstart information. + std::string key = entry_->GetKey(); + if (key.find("sslhostinfo:") != 0) { + entry_->Doom(); + backend_->EndEnumeration(&iter_); + iter_ = NULL; // We invalidated our iterator - start from the top! + } + entry_->Close(); + entry_ = NULL; + } + result = backend_->OpenNextEntry(&iter_, &entry_, &callback_); + } while (result != net::ERR_IO_PENDING); + } + + disk_cache::Backend* backend_; + disk_cache::Entry* entry_; + void* iter_; + net::CompletionCallbackImpl<DoomEntriesHelper> callback_; + ClearCacheCompletion* user_callback_; +}; + } // namespace RenderMessageFilter::RenderMessageFilter( @@ -1324,7 +1373,8 @@ void RenderMessageFilter::OnSetCacheMode(bool enabled) { http_cache->set_mode(mode); } -void RenderMessageFilter::OnClearCache(IPC::Message* reply_msg) { +void RenderMessageFilter::OnClearCache(bool preserve_ssl_host_info, + IPC::Message* reply_msg) { // This function is disabled unless the user has enabled // benchmarking extensions. int rv = -1; @@ -1334,13 +1384,19 @@ void RenderMessageFilter::OnClearCache(IPC::Message* reply_msg) { if (backend) { ClearCacheCompletion* callback = new ClearCacheCompletion(this, reply_msg); - rv = backend->DoomAllEntries(callback); - if (rv == net::ERR_IO_PENDING) { - // The callback will send the reply. + if (preserve_ssl_host_info) { + DoomEntriesHelper* helper = new DoomEntriesHelper(backend); + helper->ClearCache(callback); // Will self clean. return; + } else { + rv = backend->DoomAllEntries(callback); + if (rv == net::ERR_IO_PENDING) { + // The callback will send the reply. + return; + } + // Completed synchronously, no need for the callback. + delete callback; } - // Completed synchronously, no need for the callback. - delete callback; } } ViewHostMsg_ClearCache::WriteReplyParams(reply_msg, rv); diff --git a/chrome/browser/renderer_host/render_message_filter.h b/chrome/browser/renderer_host/render_message_filter.h index a0339de..ff50fab 100644 --- a/chrome/browser/renderer_host/render_message_filter.h +++ b/chrome/browser/renderer_host/render_message_filter.h @@ -308,7 +308,7 @@ class RenderMessageFilter : public BrowserMessageFilter, void OnCloseCurrentConnections(); void OnSetCacheMode(bool enabled); - void OnClearCache(IPC::Message* reply_msg); + void OnClearCache(bool preserve_ssl_host_info, IPC::Message* reply_msg); void OnCacheableMetadataAvailable(const GURL& url, double expected_response_time, const std::vector<char>& data); diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index d48dbd5..49ab928 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -108,7 +108,7 @@ IPC_MESSAGE_CONTROL3(ViewMsg_SetCacheCapacities, size_t /* max_dead_capacity */, size_t /* capacity */) -// Tells the renderer to cleat the cache. +// Tells the renderer to clear the cache. IPC_MESSAGE_CONTROL0(ViewMsg_ClearCache) // Reply in response to ViewHostMsg_ShowView or ViewHostMsg_ShowWidget. @@ -2241,8 +2241,12 @@ IPC_MESSAGE_CONTROL1(ViewHostMsg_SetCacheMode, // Message sent from the renderer to the browser to request that the browser // clear the cache. Used for debugging/testing. -IPC_SYNC_MESSAGE_CONTROL0_1(ViewHostMsg_ClearCache, - int /* result */) +// |preserve_ssl_host_info| controls whether clearing the cache will preserve +// persisted SSL information stored in the cache. +// |result| is the returned status from the operation. +IPC_SYNC_MESSAGE_CONTROL1_1(ViewHostMsg_ClearCache, + bool /* preserve_ssl_host_info */, + int /* result */) // Message sent from the renderer to the browser to request that the browser // enable or disable spdy. Used for debugging/testing/benchmarking. diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc index fc74a39..85bcddc 100644 --- a/chrome/renderer/render_thread.cc +++ b/chrome/renderer/render_thread.cc @@ -768,9 +768,9 @@ void RenderThread::SetCacheMode(bool enabled) { Send(new ViewHostMsg_SetCacheMode(enabled)); } -void RenderThread::ClearCache() { +void RenderThread::ClearCache(bool preserve_ssl_host_info) { int rv; - Send(new ViewHostMsg_ClearCache(&rv)); + Send(new ViewHostMsg_ClearCache(preserve_ssl_host_info, &rv)); } void RenderThread::EnableSpdy(bool enable) { diff --git a/chrome/renderer/render_thread.h b/chrome/renderer/render_thread.h index bfb9e55..97bb0ef 100644 --- a/chrome/renderer/render_thread.h +++ b/chrome/renderer/render_thread.h @@ -215,7 +215,9 @@ class RenderThread : public RenderThreadBase, void SetCacheMode(bool enabled); // Sends a message to the browser to clear the disk cache. - void ClearCache(); + // |preserve_ssl_host_info| is a flag indicating if the cache should purge + // entries related to cached SSL information. + void ClearCache(bool preserve_ssl_host_info); // Sends a message to the browser to enable/disable spdy. void EnableSpdy(bool enable); diff --git a/chrome/renderer/renderer_glue.cc b/chrome/renderer/renderer_glue.cc index ecbf7f5..7ba91ff 100644 --- a/chrome/renderer/renderer_glue.cc +++ b/chrome/renderer/renderer_glue.cc @@ -256,8 +256,8 @@ void SetCacheMode(bool enabled) { RenderThread::current()->SetCacheMode(enabled); } -void ClearCache() { - RenderThread::current()->ClearCache(); +void ClearCache(bool preserve_ssl_host_info) { + RenderThread::current()->ClearCache(preserve_ssl_host_info); } std::string GetProductVersion() { diff --git a/webkit/extensions/v8/benchmarking_extension.cc b/webkit/extensions/v8/benchmarking_extension.cc index 2fa56eb0..600eafa 100644 --- a/webkit/extensions/v8/benchmarking_extension.cc +++ b/webkit/extensions/v8/benchmarking_extension.cc @@ -27,9 +27,9 @@ class BenchmarkingWrapper : public v8::Extension { "if (typeof(chrome.benchmarking) == 'undefined') {" " chrome.benchmarking = {};" "};" - "chrome.benchmarking.clearCache = function() {" + "chrome.benchmarking.clearCache = function(preserve_ssl_entries) {" " native function ClearCache();" - " ClearCache();" + " ClearCache(preserve_ssl_entries);" "};" "chrome.benchmarking.closeConnections = function() {" " native function CloseConnections();" @@ -94,7 +94,10 @@ class BenchmarkingWrapper : public v8::Extension { } static v8::Handle<v8::Value> ClearCache(const v8::Arguments& args) { - webkit_glue::ClearCache(); + bool preserve_ssl_host_entries = false; + if (args.Length() && args[0]->IsBoolean()) + preserve_ssl_host_entries = args[0]->BooleanValue(); + webkit_glue::ClearCache(preserve_ssl_host_entries); WebCache::clear(); return v8::Undefined(); } diff --git a/webkit/glue/webkit_glue.h b/webkit/glue/webkit_glue.h index 5df2aea..c742c09 100644 --- a/webkit/glue/webkit_glue.h +++ b/webkit/glue/webkit_glue.h @@ -265,7 +265,9 @@ void CloseCurrentConnections(); void SetCacheMode(bool enabled); // Clear the disk cache. Used for debugging. -void ClearCache(); +// |preserve_ssl_host_info| indicates whether disk cache entries related to +// SSL information should be purged. +void ClearCache(bool preserve_ssl_host_info); // Returns the product version. E.g., Chrome/4.1.333.0 std::string GetProductVersion(); |