Skip to content
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

implemented history clearing handler + reset leo confirmation #20179

Merged
merged 11 commits into from
Sep 21, 2023
15 changes: 14 additions & 1 deletion app/brave_settings_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -1415,7 +1415,20 @@
<message name="IDS_SETTINGS_LEO_ASSISTANT_RESET_AND_CLEAR_DATA_LABEL" desc="The text for settings option">
Clear Leo data
</message>
<!-- Avatars. Generated via zsh and node:
<message name="IDS_SETTINGS_LEO_ASSISTANT_RESET_AND_CLEAR_DATA_CONFIRMATION_LABEL" desc="The confirmation window message for reset option">
Resetting the Leo assistant will require you to opt-in to use Brave
Leo in the future and will also clear your chat history. Clearing your
chat history will delete all your previous conversations with Brave
Leo. This action cannot be undone.
</message>
<message name="IDS_SETTINGS_LEO_ASSISTANT_CLEAR_HISTORY_DATA_LABEL" desc="The text for settings option">
Brave Leo
</message>
<message name="IDS_SETTINGS_LEO_ASSISTANT_CLEAR_HISTORY_DATA_SUBLABEL" desc="The text for settings option">
Data and chat history
</message>

<!-- Avatars. Generated via zsh and node:
declare -i a=56
for file in $(cat < avatarlist); do node -e "console.log(\`<message name=\"IDS_BRAVE_AVATAR_LABEL_$a\" desc=\"The label for the $file avatar.\">
\${\`$file\`.split('_').map(w => w[0].toUpperCase() + w.substr(1)).join(' ').replace('.png', '')}
Expand Down
10 changes: 10 additions & 0 deletions browser/about_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,17 @@
kOsWin | kOsMac | kOsLinux | kOsAndroid, \
FEATURE_VALUE_TYPE(ai_chat::features::kAIChat), \
})
#define BRAVE_AI_CHAT_HISTORY \
EXPAND_FEATURE_ENTRIES({ \
"brave-ai-chat-history", \
"Brave AI Chat History", \
"Enables AI Chat History persistence and management", \
kOsWin | kOsMac | kOsLinux, \
FEATURE_VALUE_TYPE(ai_chat::features::kAIChatHistory), \
})
#else
#define BRAVE_AI_CHAT
#define BRAVE_AI_CHAT_HISTORY
#endif

// Keep the last item empty.
Expand Down Expand Up @@ -880,6 +889,7 @@
BRAVE_CHANGE_ACTIVE_TAB_ON_SCROLL_EVENT_FEATURE_ENTRIES \
BRAVE_SHARED_PINNED_TABS \
BRAVE_AI_CHAT \
BRAVE_AI_CHAT_HISTORY \
LAST_BRAVE_FEATURE_ENTRIES_ITEM // Keep it as the last item.
namespace flags_ui {
namespace {
Expand Down
1 change: 1 addition & 0 deletions browser/browsing_data/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ source_set("browser_tests") {
deps = [
"//base",
"//base/test:test_support",
"//brave/components/ai_chat/common/buildflags:buildflags",
"//chrome/app:command_ids",
"//chrome/browser",
"//chrome/browser/browsing_data:constants",
Expand Down
19 changes: 19 additions & 0 deletions browser/browsing_data/brave_browsing_data_remover_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
#include "brave/components/ipfs/ipfs_service.h"
#endif

#if BUILDFLAG(ENABLE_AI_CHAT)
#include "brave/components/ai_chat/common/features.h"
#endif

BraveBrowsingDataRemoverDelegate::BraveBrowsingDataRemoverDelegate(
content::BrowserContext* browser_context)
: ChromeBrowsingDataRemoverDelegate(browser_context),
Expand Down Expand Up @@ -70,6 +74,13 @@ void BraveBrowsingDataRemoverDelegate::RemoveEmbedderData(
brave_news::BraveNewsControllerFactory::GetForContext(profile_)
->ClearHistory();
}
#if BUILDFLAG(ENABLE_AI_CHAT)
if (remove_mask & chrome_browsing_data_remover::DATA_TYPE_BRAVE_LEO_HISTORY &&
ai_chat::features::IsAIChatEnabled() &&
ai_chat::features::IsAIChatHistoryEnabled()) {
ClearAiChatHistory(delete_begin, delete_end);
}
#endif // BUILDFLAG(ENABLE_AI_CHAT)
}

void BraveBrowsingDataRemoverDelegate::ClearShieldsSettings(
Expand Down Expand Up @@ -101,6 +112,14 @@ void BraveBrowsingDataRemoverDelegate::ClearShieldsSettings(
}
}

#if BUILDFLAG(ENABLE_AI_CHAT)
void BraveBrowsingDataRemoverDelegate::ClearAiChatHistory(base::Time begin_time,
base::Time end_time) {
// Handler for the Brave Leo History clearing.
// It is prepared for future implementation.
}
#endif // BUILDFLAG(ENABLE_AI_CHAT)

#if BUILDFLAG(ENABLE_IPFS)
void BraveBrowsingDataRemoverDelegate::WaitForIPFSRepoGC(
base::Process process) {
Expand Down
4 changes: 4 additions & 0 deletions browser/browsing_data/brave_browsing_data_remover_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "brave/components/ai_chat/common/buildflags/buildflags.h"
#include "brave/components/ipfs/buildflags/buildflags.h"
#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"

Expand Down Expand Up @@ -49,6 +50,9 @@ class BraveBrowsingDataRemoverDelegate
override;

void ClearShieldsSettings(base::Time begin_time, base::Time end_time);
#if BUILDFLAG(ENABLE_AI_CHAT)
void ClearAiChatHistory(base::Time begin_time, base::Time end_time);
#endif // BUILDFLAG(ENABLE_AI_CHAT)
#if BUILDFLAG(ENABLE_IPFS)
void ClearIPFSCache();
void WaitForIPFSRepoGC(base::Process process);
Expand Down
7 changes: 7 additions & 0 deletions browser/browsing_data/brave_clear_browsing_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base/run_loop.h"
#include "base/scoped_multi_source_observation.h"
#include "base/trace_event/trace_event.h"
#include "brave/components/ai_chat/common/buildflags/buildflags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browsing_data/chrome_browsing_data_remover_constants.h"
#include "chrome/browser/lifetime/browser_shutdown.h"
Expand Down Expand Up @@ -102,6 +103,12 @@ bool BrowsingDataRemovalWatcher::GetClearBrowsingDataOnExitSettings(
if (prefs->GetBoolean(browsing_data::prefs::kDeleteSiteSettingsOnExit))
*remove_mask |= chrome_browsing_data_remover::DATA_TYPE_CONTENT_SETTINGS;

#if BUILDFLAG(ENABLE_AI_CHAT)
if (prefs->GetBoolean(browsing_data::prefs::kDeleteBraveLeoHistoryOnExit)) {
*remove_mask |= chrome_browsing_data_remover::DATA_TYPE_BRAVE_LEO_HISTORY;
}
#endif // BUILDFLAG(ENABLE_AI_CHAT)

return (*remove_mask != 0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "base/task/single_thread_task_runner.h"
#include "base/test/scoped_feature_list.h"
#include "brave/browser/browsing_data/brave_clear_browsing_data.h"
#include "brave/components/ai_chat/common/buildflags/buildflags.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/browsing_data/chrome_browsing_data_remover_constants.h"
#include "chrome/browser/profiles/profile.h"
Expand Down Expand Up @@ -160,6 +161,10 @@ class BraveClearDataOnExitTest
true);
prefService->SetBoolean(browsing_data::prefs::kDeleteSiteSettingsOnExit,
true);
#if BUILDFLAG(ENABLE_AI_CHAT)
prefService->SetBoolean(browsing_data::prefs::kDeleteBraveLeoHistoryOnExit,
true);
#endif // BUILDFLAG(ENABLE_AI_CHAT)
}

uint64_t GetRemoveMaskAll() {
Expand All @@ -169,6 +174,9 @@ class BraveClearDataOnExitTest
chrome_browsing_data_remover::DATA_TYPE_SITE_DATA |
chrome_browsing_data_remover::DATA_TYPE_PASSWORDS |
chrome_browsing_data_remover::DATA_TYPE_FORM_DATA |
#if BUILDFLAG(ENABLE_AI_CHAT)
chrome_browsing_data_remover::DATA_TYPE_BRAVE_LEO_HISTORY |
#endif // BUILDFLAG(ENABLE_AI_CHAT)
chrome_browsing_data_remover::DATA_TYPE_CONTENT_SETTINGS;
}

Expand Down
4 changes: 4 additions & 0 deletions browser/extensions/api/settings_private/brave_prefs_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ const PrefsUtil::TypedPrefMap& BravePrefsUtil::GetAllowlistedKeys() {
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_allowlist)[browsing_data::prefs::kDeleteHostedAppsDataOnExit] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_allowlist)[browsing_data::prefs::kDeleteBraveLeoHistory] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_allowlist)[browsing_data::prefs::kDeleteBraveLeoHistoryOnExit] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_allowlist)[kAlwaysShowBookmarkBarOnNTP] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_allowlist)[kMRUCyclingEnabled] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
sub-label="[[counters.cookies]]"
no-set-pref>
</settings-checkbox>
<settings-checkbox id="leoResetOnExitCheckbox"
pref="{{prefs.browser.clear_data.brave_leo_on_exit}}"
label="$i18n{leoClearHistoryData}"
sub-label="$i18n{leoClearHistoryDataSubLabel}"
hidden="[[!isLeoAssistantAndHistoryAllowed_]]"
no-set-pref>
</settings-checkbox>
<settings-checkbox id="cacheCheckboxOnExit"
class="cache-checkbox"
pref="{{prefs.browser.clear_data.cache_on_exit}}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ Polymer({
},
},

isLeoAssistantAndHistoryAllowed_: {
type: Boolean,
value: function() {
return loadTimeData.getBoolean('isLeoAssistantAllowed')
&& loadTimeData.getBoolean('isLeoAssistantHistoryAllowed');
},
}
},

listeners: {'settings-boolean-control-change': 'updateModified_'},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ class BraveLeoAssistantPageElement extends BraveLeoAssistantPageBase {
BraveLeoAssistantBrowserProxyImpl.getInstance()

onResetAssistantData_() {
this.browserProxy_.resetLeoData()
const message =
this.i18n('braveLeoAssistantResetAndClearDataConfirmationText')
if(window.confirm(message)) {
this.browserProxy_.resetLeoData()
}
}

override ready () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,37 @@ RegisterPolymerTemplateModifications({
} else {
rewardsResetLink.textContent = loadTimeData.getString('resetRewardsData')
}

// Append Leo reset checkbox
const isLeoAssistantAndHistoryAllowed =
loadTimeData.getBoolean('isLeoAssistantAllowed')
&& loadTimeData.getBoolean('isLeoAssistantHistoryAllowed')
if (isLeoAssistantAndHistoryAllowed) {
const cacheCheckbox = templateContent
.querySelector('[id="cacheCheckbox"]')
if (!cacheCheckbox) {
console.error(`[Brave Settings Overrides] cannot find
'id="cacheCheckbox"' in clear-browsing-data-dialog`)
return
}
cacheCheckbox.insertAdjacentHTML(
'beforebegin',
getTrustedHTML`
<settings-checkbox
id="leoResetCheckbox"
pref="{{prefs.browser.clear_data.brave_leo}}"
label="[[i18n('leoClearHistoryData')]]"
sub-label="[[i18n('leoClearHistoryDataSubLabel')]]"
disabled="[[clearingInProgress_]]"
no-set-pref>
</settings-checkbox>`)

const leoResetCheckbox =
templateContent.querySelector('[id="leoResetCheckbox"]')
if (!leoResetCheckbox) {
console.error(
'[Brave Settings Overrides] Couldn\'t find Leo reset link')
}
}
}
})
3 changes: 3 additions & 0 deletions browser/ui/webui/brave_settings_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,11 @@ void BraveSettingsUI::AddResources(content::WebUIDataSource* html_source,
#if BUILDFLAG(ENABLE_AI_CHAT)
html_source->AddBoolean("isLeoAssistantAllowed",
ai_chat::features::IsAIChatEnabled());
html_source->AddBoolean("isLeoAssistantHistoryAllowed",
ai_chat::features::IsAIChatHistoryEnabled());
#else
html_source->AddBoolean("isLeoAssistantAllowed", false);
html_source->AddBoolean("isLeoAssistantHistoryAllowed", false);
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,12 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source,
IDS_SETTINGS_LEO_ASSISTANT_SHOW_SUGGESTED_PROMPTS_LABEL},
{"braveLeoAssistantResetAndClearDataLabel",
IDS_SETTINGS_LEO_ASSISTANT_RESET_AND_CLEAR_DATA_LABEL},
{"braveLeoAssistantResetAndClearDataConfirmationText",
IDS_SETTINGS_LEO_ASSISTANT_RESET_AND_CLEAR_DATA_CONFIRMATION_LABEL},
{"leoClearHistoryData",
IDS_SETTINGS_LEO_ASSISTANT_CLEAR_HISTORY_DATA_LABEL},
{"leoClearHistoryDataSubLabel",
IDS_SETTINGS_LEO_ASSISTANT_CLEAR_HISTORY_DATA_SUBLABEL},

// New Tab Page
{"braveNewTab", IDS_SETTINGS_NEW_TAB},
Expand Down
1 change: 1 addition & 0 deletions build/config/brave_build.gni
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import("//brave/browser/resources/history/sources.gni")
import("//brave/browser/resources/settings/sources.gni")
import("//brave/browser/ui/color/sources.gni")
import("//brave/build/mac/config.gni")
import("//brave/components/browsing_data/core/sources.gni")
import("//brave/components/content_settings/core/browser/sources.gni")
import("//brave/components/omnibox/browser/sources.gni")
import("//brave/components/search_engines/sources.gni")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@
* 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/. */

#include "brave/components/ai_chat/common/buildflags/buildflags.h"

#if !BUILDFLAG(ENABLE_AI_CHAT)
#define BRAVE_CLEAR_BROWSING_DATA \
remove_mask |= BrowsingDataRemover::DATA_TYPE_DOWNLOADS; \
break;
#else // BUILDFLAG(ENABLE_AI_CHAT)
#define BRAVE_CLEAR_BROWSING_DATA \
remove_mask |= BrowsingDataRemover::DATA_TYPE_DOWNLOADS; \
break; \
case browsing_data::BrowsingDataType::BRAVE_AI_CHAT: \
remove_mask |= chrome_browsing_data_remover::DATA_TYPE_BRAVE_LEO_HISTORY; \
break;
#endif // BUILDFLAG(ENABLE_AI_CHAT)

#include "src/chrome/browser/android/browsing_data/browsing_data_bridge.cc"
#undef BRAVE_CLEAR_BROWSING_DATA
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_BROWSING_DATA_CHROME_BROWSING_DATA_REMOVER_CONSTANTS_H_
#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_BROWSING_DATA_CHROME_BROWSING_DATA_REMOVER_CONSTANTS_H_

#include "brave/components/ai_chat/common/buildflags/buildflags.h"

#include "src/chrome/browser/browsing_data/chrome_browsing_data_remover_constants.h" // IWYU pragma: export

namespace chrome_browsing_data_remover {
constexpr DataType GetBraveDataTypeValue(const int index) {
return DataType(1) << (63 - index);
}

#if BUILDFLAG(ENABLE_AI_CHAT)
constexpr DataType DATA_TYPE_BRAVE_LEO_HISTORY = GetBraveDataTypeValue(0);
#endif // BUILDFLAG(ENABLE_AI_CHAT)
} // namespace chrome_browsing_data_remover

#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_BROWSING_DATA_CHROME_BROWSING_DATA_REMOVER_CONSTANTS_H_
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* 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/. */

#include "brave/components/ai_chat/common/buildflags/buildflags.h"
#include "chrome/browser/browsing_data/browsing_data_important_sites_util.h"
#include "chrome/browser/profiles/profile.h"

Expand All @@ -25,7 +26,21 @@ void BraveRemoveJumplist(Profile* profile) {
} \
browsing_data_important_sites_util
#endif

#if BUILDFLAG(ENABLE_AI_CHAT)
#define NUM_TYPES \
BRAVE_AI_CHAT: \
remove_mask |= chrome_browsing_data_remover::DATA_TYPE_BRAVE_LEO_HISTORY; \
break; \
case BrowsingDataType::NUM_TYPES
#endif // BUILDFLAG(ENABLE_AI_CHAT)

#include "src/chrome/browser/ui/webui/settings/settings_clear_browsing_data_handler.cc"

#if BUILDFLAG(ENABLE_AI_CHAT)
#undef NUM_TYPES
#endif // BUILDFLAG(ENABLE_AI_CHAT)

#if BUILDFLAG(IS_WIN)
#undef browsing_data_important_sites_util
#endif
3 changes: 3 additions & 0 deletions chromium_src/components/browsing_data/core/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include_rules = [
"+brave/components/ai_chat/common/buildflags/buildflags.h",
]
Loading