Chromium Code Reviews| Index: chrome/browser/chrome_net_benchmarking_message_filter.cc |
| diff --git a/chrome/browser/chrome_net_benchmarking_message_filter.cc b/chrome/browser/chrome_net_benchmarking_message_filter.cc |
| index 04bc990c65ad3e684f0bbd124853c22d25de7006..0781d1fa62649d491a0f067cc05f3827a3b496e1 100644 |
| --- a/chrome/browser/chrome_net_benchmarking_message_filter.cc |
| +++ b/chrome/browser/chrome_net_benchmarking_message_filter.cc |
| @@ -30,6 +30,57 @@ void ClearCacheCallback(ChromeNetBenchmarkingMessageFilter* filter, |
| filter->Send(reply_msg); |
| } |
| +// 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), |
| + callback_( |
|
wtc
2014/01/15 19:08:59
I guess it is not necessary to use ALLOW_THIS_IN_I
ramant (doing other things)
2014/01/18 00:21:56
We get compiler error if we use ALLOW_THIS_IN_INIT
|
| + base::Bind(&DoomEntriesHelper::CacheCallback, |
| + base::Unretained(this))) { |
| + } |
| + |
| + void ClearCache(const net::CompletionCallback& callback) { |
| + clear_cache_callback_ = callback; |
| + return CacheCallback(net::OK); // Start clearing the cache. |
| + } |
| + |
| + const net::CompletionCallback& callback() { return callback_; } |
| + |
| + private: |
| + void CacheCallback(int result) { |
| + do { |
| + if (result != net::OK) { |
| + clear_cache_callback_.Run(result); |
| + delete this; |
| + return; |
| + } |
| + |
| + if (entry_) { |
| + // Doom all entries except those with snapstart information. |
|
wtc
2014/01/15 19:08:59
Change "snapstart information" to "sslhostinfo".
ramant (doing other things)
2014/01/18 00:21:56
Done.
|
| + 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::CompletionCallback callback_; |
| + net::CompletionCallback clear_cache_callback_; |
| +}; |
| + |
| } // namespace |
| ChromeNetBenchmarkingMessageFilter::ChromeNetBenchmarkingMessageFilter( |
| @@ -62,7 +113,9 @@ bool ChromeNetBenchmarkingMessageFilter::OnMessageReceived( |
| return handled; |
| } |
| -void ChromeNetBenchmarkingMessageFilter::OnClearCache(IPC::Message* reply_msg) { |
| +void ChromeNetBenchmarkingMessageFilter::OnClearCache( |
| + bool preserve_ssl_host_info, |
| + IPC::Message* reply_msg) { |
| // This function is disabled unless the user has enabled |
| // benchmarking extensions. |
| if (!CheckBenchmarkingEnabled()) { |
| @@ -76,10 +129,16 @@ void ChromeNetBenchmarkingMessageFilter::OnClearCache(IPC::Message* reply_msg) { |
| if (backend) { |
| net::CompletionCallback callback = |
| base::Bind(&ClearCacheCallback, make_scoped_refptr(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 { |
|
wtc
2014/01/15 19:08:59
Remove this "else" because it is after a return st
ramant (doing other things)
2014/01/18 00:21:56
Done.
|
| + rv = backend->DoomAllEntries(callback); |
| + if (rv == net::ERR_IO_PENDING) { |
| + // The callback will send the reply. |
| + return; |
| + } |
| } |
| } |
| ChromeViewHostMsg_ClearCache::WriteReplyParams(reply_msg, rv); |