-
Notifications
You must be signed in to change notification settings - Fork 921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clear IPFS cache when clearing browsing data #7578
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,19 @@ | |
#include "extensions/browser/event_router.h" | ||
#endif | ||
|
||
#if BUILDFLAG(IPFS_ENABLED) | ||
#include "base/command_line.h" | ||
#include "base/files/file_path.h" | ||
#include "base/process/launch.h" | ||
#include "base/process/process.h" | ||
#include "base/task/task_traits.h" | ||
#include "base/task/thread_pool.h" | ||
#include "base/threading/thread_restrictions.h" | ||
#include "base/time/time.h" | ||
#include "brave/browser/ipfs/ipfs_service_factory.h" | ||
#include "brave/components/ipfs/ipfs_service.h" | ||
#endif | ||
|
||
BraveBrowsingDataRemoverDelegate::BraveBrowsingDataRemoverDelegate( | ||
content::BrowserContext* browser_context) | ||
: ChromeBrowsingDataRemoverDelegate(browser_context), | ||
|
@@ -46,6 +59,12 @@ void BraveBrowsingDataRemoverDelegate::RemoveEmbedderData( | |
// shields settings with non-empty resource ids. | ||
if (remove_mask & DATA_TYPE_CONTENT_SETTINGS) | ||
ClearShieldsSettings(delete_begin, delete_end); | ||
|
||
#if BUILDFLAG(IPFS_ENABLED) | ||
if (remove_mask & content::BrowsingDataRemover::DATA_TYPE_CACHE) | ||
ClearIPFSCache(); | ||
#endif | ||
|
||
#if BUILDFLAG(ENABLE_EXTENSIONS) | ||
if (remove_mask & DATA_TYPE_HISTORY) { | ||
auto* event_router = extensions::EventRouter::Get(profile_); | ||
|
@@ -91,3 +110,68 @@ void BraveBrowsingDataRemoverDelegate::ClearShieldsSettings( | |
} | ||
} | ||
} | ||
|
||
#if BUILDFLAG(IPFS_ENABLED) | ||
void BraveBrowsingDataRemoverDelegate::WaitForIPFSRepoGC( | ||
base::Process process) { | ||
bool exited = false; | ||
|
||
{ | ||
base::ScopedAllowBaseSyncPrimitives scoped_allow_base_sync_primitives; | ||
|
||
// Because we set maximum IPFS storage size as 1GB in Brave, ipfs repo gc | ||
// command should be finished in just a few seconds and we do not expect | ||
// this child process would hang forever. To be safe, we will wait for 30 | ||
// seconds max here. | ||
exited = process.WaitForExitWithTimeout(base::TimeDelta::FromSeconds(30), | ||
nullptr); | ||
} | ||
|
||
if (!exited) | ||
process.Terminate(0, false /* wait */); | ||
} | ||
|
||
// Run ipfs repo gc command to clear IPFS cache when IPFS executable path is | ||
// available. Because the command does not support time ranged cleanup, we will | ||
// always clear the whole cache expect for pinned files when clearing browsing | ||
// data. | ||
void BraveBrowsingDataRemoverDelegate::ClearIPFSCache() { | ||
auto* service = | ||
ipfs::IpfsServiceFactory::GetInstance()->GetForContext(profile_); | ||
if (!service) | ||
return; | ||
|
||
base::FilePath path = service->GetIpfsExecutablePath(); | ||
if (path.empty()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should get the last known good path when the executable path is not determined here please in a follow up. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, opened brave/brave-browser#13605. |
||
return; | ||
|
||
base::CommandLine cmdline(path); | ||
cmdline.AppendArg("repo"); | ||
cmdline.AppendArg("gc"); | ||
|
||
base::FilePath data_path = service->GetDataPath(); | ||
base::LaunchOptions options; | ||
#if defined(OS_WIN) | ||
options.environment[L"IPFS_PATH"] = data_path.value(); | ||
#else | ||
options.environment["IPFS_PATH"] = data_path.value(); | ||
#endif | ||
#if defined(OS_LINUX) | ||
options.kill_on_parent_death = true; | ||
#endif | ||
#if defined(OS_WIN) | ||
options.start_hidden = true; | ||
#endif | ||
|
||
base::Process process = base::LaunchProcess(cmdline, options); | ||
if (!process.IsValid()) { | ||
return; | ||
} | ||
|
||
base::ThreadPool::PostTaskAndReply( | ||
FROM_HERE, {base::TaskPriority::USER_VISIBLE, base::MayBlock()}, | ||
base::BindOnce(&BraveBrowsingDataRemoverDelegate::WaitForIPFSRepoGC, | ||
base::Unretained(this), base::Passed(&process)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (sorry, just randomly came across this) Fortunately, in our case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also, probably we'd better explicitly mention There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you @iefremov, I'll open a follow-up PR for this. |
||
CreateTaskCompletionClosure(TracingDataType::kHostCache)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. kHostCache is the most reasonable existing one I could find in the list, type value is only meant for recording purpose, so we should be good here. This value is gone in chromium latest version, so we would need to update the value to kEmbedderData during future chromium upgrade. |
||
} | ||
#endif // BUILDFLAG(IPFS_ENABLED) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* Copyright (c) 2021 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_CHROMIUM_SRC_BASE_THREADING_THREAD_RESTRICTIONS_H_ | ||
#define BRAVE_CHROMIUM_SRC_BASE_THREADING_THREAD_RESTRICTIONS_H_ | ||
|
||
class BraveBrowsingDataRemoverDelegate; | ||
|
||
#define BRAVE_SCOPED_ALLOW_BASE_SYNC_PRIMITIVES_H \ | ||
friend class ::BraveBrowsingDataRemoverDelegate; | ||
|
||
#include "../../../../base/threading/thread_restrictions.h" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: empty line after a multi-line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. force pushed to add an empty line after define for this file and |
||
#undef BRAVE_SCOPED_ALLOW_BASE_SYNC_PRIMITIVES_H | ||
|
||
#endif // BRAVE_CHROMIUM_SRC_BASE_THREADING_THREAD_RESTRICTIONS_H_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* Copyright (c) 2021 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_BROWSING_DATA_CHROME_BROWSING_DATA_REMOVER_DELEGATE_H_ | ||
#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_BROWSING_DATA_CHROME_BROWSING_DATA_REMOVER_DELEGATE_H_ | ||
|
||
class BraveBrowsingDataRemoverDelegate; | ||
|
||
#define BRAVE_CHROME_BROWSING_DATA_REMOVER_DELEGATE_H \ | ||
friend class BraveBrowsingDataRemoverDelegate; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I am seeing why we need the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mkarolin For CreateTaskCompletionClosure. |
||
|
||
#include "../../../../../chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" | ||
#undef BRAVE_CHROME_BROWSING_DATA_REMOVER_DELEGATE_H | ||
|
||
#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_BROWSING_DATA_CHROME_BROWSING_DATA_REMOVER_DELEGATE_H_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
diff --git a/base/threading/thread_restrictions.h b/base/threading/thread_restrictions.h | ||
index ac19eaecc4cc36c4376052c33314bc289bab7bcf..6e79d17b49ba84fa4ccbbfefd88c3aa1888a855b 100644 | ||
--- a/base/threading/thread_restrictions.h | ||
+++ b/base/threading/thread_restrictions.h | ||
@@ -433,6 +433,7 @@ INLINE_IF_DCHECK_IS_OFF void DisallowBaseSyncPrimitives() | ||
EMPTY_BODY_IF_DCHECK_IS_OFF; | ||
|
||
class BASE_EXPORT ScopedAllowBaseSyncPrimitives { | ||
+ BRAVE_SCOPED_ALLOW_BASE_SYNC_PRIMITIVES_H | ||
private: | ||
// This can only be instantiated by friends. Use | ||
// ScopedAllowBaseSyncPrimitivesForTesting in unit tests to avoid the friend |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
diff --git a/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h b/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h | ||
index ae0d55606244bca6ac1a1fa0037e0dc286c36174..74bc2123ced2db3fcdfc8854aac5a61f6067bd62 100644 | ||
--- a/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h | ||
+++ b/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h | ||
@@ -195,6 +195,7 @@ class ChromeBrowsingDataRemoverDelegate | ||
void OverrideDomainReliabilityClearerForTesting( | ||
DomainReliabilityClearer clearer); | ||
|
||
+ BRAVE_CHROME_BROWSING_DATA_REMOVER_DELEGATE_H | ||
private: | ||
using WebRtcEventLogManager = webrtc_event_logging::WebRtcEventLogManager; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not have the dependency added in this PR.
We have some existing deps problems for the browsing_data target, which I would like it to be addressed in a separate PR.
For chromium, their browsing_data_remover_delegate source files are listed in the browser target itself, I think we should probably consider doing the same since we need chrome/browser and brave/browser in existing files in our browsing_data target.