Skip to content

Commit

Permalink
Flush HTTP, media, code, and renderer caches too.
Browse files Browse the repository at this point in the history
  • Loading branch information
riastradh-brave committed May 24, 2019
1 parent f545d9b commit f3307f3
Showing 1 changed file with 52 additions and 8 deletions.
60 changes: 52 additions & 8 deletions browser/ui/browser_commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,83 @@
#include "chrome/browser/profiles/profile_window.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "components/web_cache/browser/web_cache_manager.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "services/network/public/cpp/features.h"

using content::BrowserContext;
using content::BrowserThread;
using content::NavigationController;
using content::StoragePartition;
using content::WebContents;

namespace {
void NewTorIdentityCallbackDone(WebContents* current_tab) {
// Reload the page once we have a new circuit and cleared browsing data.
void NewTorIdentityCallbackReload(WebContents* current_tab) {
NavigationController& controller = current_tab->GetController();
controller.Reload(content::ReloadType::BYPASSING_CACHE, true);
}

void NewTorIdentityCallback(WebContents* current_tab) {
// Flush everything else in the storage partition.
void NewTorIdentityCallbackClearData(WebContents* current_tab) {
auto* context = current_tab->GetBrowserContext();
auto* site = current_tab->GetSiteInstance();
auto* partition =
content::BrowserContext::GetStoragePartition(context, site);
auto* partition = BrowserContext::GetStoragePartition(context, site);
auto cookie_delete_filter = network::mojom::CookieDeletionFilter::New();
// Delete all cookies, irrespective of persistence status.
cookie_delete_filter->session_control =
network::mojom::CookieDeletionSessionControl::IGNORE_CONTROL;
partition->ClearData(
content::StoragePartition::REMOVE_DATA_MASK_ALL,
content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
content::StoragePartition::OriginMatcherFunction(),
StoragePartition::REMOVE_DATA_MASK_ALL,
StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
StoragePartition::OriginMatcherFunction(),
std::move(cookie_delete_filter),
/*perform_cleanup*/ true,
/*begin*/ base::Time(), // beginning of time
/*end*/ base::Time::Max(), // end of time
base::Bind(&NewTorIdentityCallbackDone, current_tab));
base::Bind(&NewTorIdentityCallbackReload, current_tab));
}

// Flush any code caches in the storage partition.
void NewTorIdentityCallbackClearCodeCaches(WebContents* current_tab) {
auto* context = current_tab->GetBrowserContext();
auto* site = current_tab->GetSiteInstance();
auto* partition = BrowserContext::GetStoragePartition(context, site);
partition->ClearCodeCaches(
/*begin*/ base::Time(), // beginning of time
/*end*/ base::Time::Max(), // end of time
base::RepeatingCallback<bool(const GURL&)>(),
base::BindOnce(&NewTorIdentityCallbackClearData, current_tab));
}

// Flush the renderer cache and the HTTP and media caches.
void NewTorIdentityCallback(WebContents* current_tab) {
int render_process_id = current_tab->GetMainFrame()->GetProcess()->GetID();
auto* cache_manager = web_cache::WebCacheManager::GetInstance();
cache_manager->ClearCacheForProcess(render_process_id);

auto* context = current_tab->GetBrowserContext();
auto* site = current_tab->GetSiteInstance();
auto* partition = BrowserContext::GetStoragePartition(context, site);
base::OnceClosure callback = base::BindOnce(
&NewTorIdentityCallbackClearCodeCaches, current_tab);
if (base::FeatureList::IsEnabled(network::features::kNetworkService)) {
partition->GetNetworkContext()->ClearHttpCache(
/*begin*/ base::Time(), // beginning of time
/*end*/ base::Time::Max(), // end of time
/*ClearDataFilter*/ nullptr,
std::move(callback));
} else {
partition->ClearHttpAndMediaCaches(
/*begin*/ base::Time(), // beginning of time
/*end*/ base::Time::Max(), // end of time
base::RepeatingCallback<bool(const GURL&)>(),
std::move(callback));
}
}
} // namespace

Expand Down

0 comments on commit f3307f3

Please sign in to comment.