From: uazo Date: Thu, 16 Feb 2023 15:28:16 +0000 Subject: Add setting to clear data on exit License: GPL-2.0-or-later - https://spdx.org/licenses/GPL-2.0-or-later.html --- chrome/android/chrome_java_sources.gni | 1 + .../chrome/browser/ChromeTabbedActivity.java | 7 +- .../ClearBrowsingDataFragment.java | 6 ++ .../ClearBrowsingDataFragmentAtStart.java | 74 +++++++++++++++++++ .../ClearBrowsingDataTabsFragment.java | 7 +- chrome/app/settings_strings.grdp | 10 +++ .../browsing_data/browsing_data_bridge.cc | 2 +- .../chrome_browsing_data_lifetime_manager.cc | 22 +++++- .../chrome_browsing_data_remover_delegate.cc | 11 +++ .../api/settings_private/prefs_util.cc | 17 +++++ .../browser/profiles/ProfileManagerUtils.java | 5 ++ .../profiles/android/profile_manager_utils.cc | 5 ++ chrome/browser/profiles/profile_manager.cc | 13 ++++ chrome/browser/profiles/profile_manager.h | 2 + .../clear_browsing_data_dialog.html | 44 +++++++++++ .../clear_browsing_data_dialog.ts | 1 + .../strings/android_chrome_strings.grd | 3 + .../settings_localized_strings_provider.cc | 1 + .../core/browsing_data_policies_utils.cc | 20 ++--- .../core/browsing_data_policies_utils.h | 11 +++ .../browsing_data/core/browsing_data_utils.cc | 34 +++++++++ .../core/clear_browsing_data_tab.h | 2 +- components/browsing_data/core/pref_names.cc | 27 +++++++ components/browsing_data/core/pref_names.h | 9 +++ content/browser/storage_partition_impl.cc | 1 + 25 files changed, 319 insertions(+), 16 deletions(-) create mode 100644 chrome/android/java/src/org/chromium/chrome/browser/browsing_data/ClearBrowsingDataFragmentAtStart.java diff --git a/chrome/android/chrome_java_sources.gni b/chrome/android/chrome_java_sources.gni --- a/chrome/android/chrome_java_sources.gni +++ b/chrome/android/chrome_java_sources.gni @@ -303,6 +303,7 @@ chrome_java_sources = [ "java/src/org/chromium/chrome/browser/browsing_data/ClearBrowsingDataFragmentAdvanced.java", "java/src/org/chromium/chrome/browser/browsing_data/ClearBrowsingDataFragmentBasic.java", "java/src/org/chromium/chrome/browser/browsing_data/ClearBrowsingDataTabsFragment.java", + "java/src/org/chromium/chrome/browser/browsing_data/ClearBrowsingDataFragmentAtStart.java", "java/src/org/chromium/chrome/browser/browsing_data/ConfirmImportantSitesDialogFragment.java", "java/src/org/chromium/chrome/browser/browsing_data/OtherFormsOfHistoryDialogFragment.java", "java/src/org/chromium/chrome/browser/browsing_data/UrlFilter.java", diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ChromeTabbedActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/ChromeTabbedActivity.java --- a/chrome/android/java/src/org/chromium/chrome/browser/ChromeTabbedActivity.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/ChromeTabbedActivity.java @@ -146,6 +146,7 @@ import org.chromium.chrome.browser.profiles.ProfileManager; import org.chromium.chrome.browser.quick_delete.QuickDeleteController; import org.chromium.chrome.browser.quick_delete.QuickDeleteDelegateImpl; import org.chromium.chrome.browser.quick_delete.QuickDeleteMetricsDelegate; +import org.chromium.chrome.browser.profiles.ProfileManagerUtils; import org.chromium.chrome.browser.read_later.ReadingListBackPressHandler; import org.chromium.chrome.browser.read_later.ReadingListUtils; import org.chromium.chrome.browser.reengagement.ReengagementNotificationController; @@ -1307,7 +1308,11 @@ public class ChromeTabbedActivity extends ChromeActivity. +*/ + +package org.chromium.chrome.browser.browsing_data; + +import android.content.Context; +import android.os.Bundle; +import android.view.View; + +import androidx.annotation.IntDef; +import androidx.preference.Preference; + +import org.chromium.base.Callback; +import org.chromium.chrome.R; +import org.chromium.chrome.browser.profiles.Profile; +import org.chromium.components.browser_ui.settings.SpinnerPreference; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.util.Arrays; +import java.util.List; + +public class ClearBrowsingDataFragmentAtStart extends ClearBrowsingDataFragment { + static final String PREF_TIME_RANGE = "time_period_spinner"; + + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + super.onCreatePreferences(savedInstanceState, rootKey); + + SpinnerPreference spinner = (SpinnerPreference) findPreference(PREF_TIME_RANGE); + if (spinner != null) { + getPreferenceScreen().removePreference(spinner); + } + } + + private boolean isHistorySyncEnabled() { + return false; + } + + @Override + protected int getClearBrowsingDataTabType() { + return ClearBrowsingDataTab.AT_START; + } + + @Override + protected List getDialogOptions() { + return Arrays.asList(DialogOption.CLEAR_HISTORY, DialogOption.CLEAR_COOKIES_AND_SITE_DATA, + DialogOption.CLEAR_CACHE, DialogOption.CLEAR_PASSWORDS, + DialogOption.CLEAR_FORM_DATA, DialogOption.CLEAR_SITE_SETTINGS); + } + + @Override + protected void onClearBrowsingData() { + } + + @Override + protected boolean shouldClearBrowsingData() { + return false; + } +} diff --git a/chrome/android/java/src/org/chromium/chrome/browser/browsing_data/ClearBrowsingDataTabsFragment.java b/chrome/android/java/src/org/chromium/chrome/browser/browsing_data/ClearBrowsingDataTabsFragment.java --- a/chrome/android/java/src/org/chromium/chrome/browser/browsing_data/ClearBrowsingDataTabsFragment.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/browsing_data/ClearBrowsingDataTabsFragment.java @@ -27,7 +27,7 @@ import org.chromium.chrome.browser.settings.SettingsActivity; * Fragment with a {@link TabLayout} containing a basic and an advanced version of the CBD dialog. */ public class ClearBrowsingDataTabsFragment extends Fragment { - public static final int CBD_TAB_COUNT = 2; + public static final int CBD_TAB_COUNT = 3; private ClearBrowsingDataFetcher mFetcher; @@ -84,6 +84,8 @@ public class ClearBrowsingDataTabsFragment extends Fragment { return getActivity().getString(R.string.clear_browsing_data_basic_tab_title); case 1: return getActivity().getString(R.string.prefs_section_advanced); + case 2: + return getActivity().getString(R.string.clear_browsing_data_atstart_tab_title); default: throw new RuntimeException("invalid position: " + position); } @@ -121,6 +123,9 @@ public class ClearBrowsingDataTabsFragment extends Fragment { case 1: fragment = new ClearBrowsingDataFragmentAdvanced(); break; + case 2: + fragment = new ClearBrowsingDataFragmentAtStart(); + break; default: throw new RuntimeException("invalid position: " + position); } diff --git a/chrome/app/settings_strings.grdp b/chrome/app/settings_strings.grdp --- a/chrome/app/settings_strings.grdp +++ b/chrome/app/settings_strings.grdp @@ -2333,6 +2333,16 @@ Clear browsing data + + + At Close + + + + + At Startup + + Clear history, cookies, cache, and more diff --git a/chrome/browser/android/browsing_data/browsing_data_bridge.cc b/chrome/browser/android/browsing_data/browsing_data_bridge.cc --- a/chrome/browser/android/browsing_data/browsing_data_bridge.cc +++ b/chrome/browser/android/browsing_data/browsing_data_bridge.cc @@ -326,7 +326,7 @@ static void JNI_BrowsingDataBridge_SetLastClearBrowsingDataTab( const JavaParamRef& obj, jint tab_index) { DCHECK_GE(tab_index, 0); - DCHECK_LT(tab_index, 2); + DCHECK_LT(tab_index, 3); GetPrefService()->SetInteger(browsing_data::prefs::kLastClearBrowsingDataTab, tab_index); } diff --git a/chrome/browser/browsing_data/chrome_browsing_data_lifetime_manager.cc b/chrome/browser/browsing_data/chrome_browsing_data_lifetime_manager.cc --- a/chrome/browser/browsing_data/chrome_browsing_data_lifetime_manager.cc +++ b/chrome/browser/browsing_data/chrome_browsing_data_lifetime_manager.cc @@ -312,8 +312,25 @@ void ChromeBrowsingDataLifetimeManager::Shutdown() { void ChromeBrowsingDataLifetimeManager::ClearBrowsingDataForOnExitPolicy( bool keep_browser_alive) { - const base::Value::List& data_types = profile_->GetPrefs()->GetList( - browsing_data::prefs::kClearBrowsingDataOnExitList); + base::Value::List data_types = profile_->GetPrefs()->GetList( + browsing_data::prefs::kClearBrowsingDataOnExitList).Clone(); + + if (profile_->GetPrefs()->GetBoolean(browsing_data::prefs::kDeleteBrowsingHistoryAtStart)) + data_types.Append(browsing_data::policy_data_types::kBrowsingHistoryName); + if (profile_->GetPrefs()->GetBoolean(browsing_data::prefs::kDeletePasswordsAtStart)) + data_types.Append(browsing_data::policy_data_types::kPasswordSigninName); + if (profile_->GetPrefs()->GetBoolean(browsing_data::prefs::kDeleteFormDataAtStart)) + data_types.Append(browsing_data::policy_data_types::kAutofillName); + if (profile_->GetPrefs()->GetBoolean(browsing_data::prefs::kDeleteSiteSettingsAtStart)) + data_types.Append(browsing_data::policy_data_types::kSiteSettingsName); + if (profile_->GetPrefs()->GetBoolean(browsing_data::prefs::kDeleteHostedAppsDataAtStart)) + data_types.Append(browsing_data::policy_data_types::kHostedAppDataName); + if (profile_->GetPrefs()->GetBoolean(browsing_data::prefs::kDeleteDownloadHistoryAtStart)) + data_types.Append(browsing_data::policy_data_types::kDownloadHistoryName); + if (profile_->GetPrefs()->GetBoolean(browsing_data::prefs::kDeleteCookiesAtStart)) + data_types.Append(browsing_data::policy_data_types::kCookiesAndOtherSiteDataName); + if (profile_->GetPrefs()->GetBoolean(browsing_data::prefs::kDeleteCacheAtStart)) + data_types.Append(browsing_data::policy_data_types::kCachedImagesAndFilesName); if (!data_types.empty() && IsConditionSatisfiedForBrowsingDataRemoval(GetSyncTypesForPolicyPref( @@ -422,6 +439,7 @@ void ChromeBrowsingDataLifetimeManager::StartScheduledBrowsingDataRemoval() { bool ChromeBrowsingDataLifetimeManager:: IsConditionSatisfiedForBrowsingDataRemoval( const syncer::UserSelectableTypeSet sync_types) { + if ((true)) return true; bool sync_disabled = !SyncServiceFactory::IsSyncAllowed(profile_); // Return the state of sync if // `features::kDataRetentionPoliciesDisableSyncTypesNeeded` is disabled or if diff --git a/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc b/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc --- a/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc +++ b/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc @@ -427,6 +427,9 @@ void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData( delete_end_, CreateTaskCompletionClosure(TracingDataType::kHistory), &history_task_tracker_); } + } + + if (remove_mask & content::BrowsingDataRemover::DATA_TYPE_CACHE) { if (ClipboardRecentContent::GetInstance()) ClipboardRecentContent::GetInstance()->SuppressClipboardContent(); @@ -477,7 +480,9 @@ void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData( prerender::NoStatePrefetchManager::CLEAR_PRERENDER_CONTENTS | prerender::NoStatePrefetchManager::CLEAR_PRERENDER_HISTORY); } + } + if ((remove_mask & constants::DATA_TYPE_HISTORY) && may_delete_history) { // The saved Autofill profiles and credit cards can include the origin from // which these profiles and credit cards were learned. These are a form of // history, so clear them as well. @@ -498,7 +503,9 @@ void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData( if (data_manager) data_manager->Refresh(); } + } + if (remove_mask & content::BrowsingDataRemover::DATA_TYPE_CACHE) { base::ThreadPool::PostTaskAndReply( FROM_HERE, {base::TaskPriority::USER_VISIBLE, base::MayBlock()}, base::BindOnce( @@ -573,9 +580,13 @@ void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData( } device_event_log::Clear(delete_begin_, delete_end_); + } + if ((remove_mask & constants::DATA_TYPE_HISTORY) && may_delete_history) { CreateCrashUploadList()->Clear(delete_begin_, delete_end_); + } + if (remove_mask & content::BrowsingDataRemover::DATA_TYPE_CACHE) { content::BackgroundTracingManager::GetInstance().DeleteTracesInDateRange( delete_begin_, delete_end_); diff --git a/chrome/browser/extensions/api/settings_private/prefs_util.cc b/chrome/browser/extensions/api/settings_private/prefs_util.cc --- a/chrome/browser/extensions/api/settings_private/prefs_util.cc +++ b/chrome/browser/extensions/api/settings_private/prefs_util.cc @@ -517,6 +517,23 @@ const PrefsUtil::TypedPrefMap& PrefsUtil::GetAllowlistedKeys() { (*s_allowlist)[browsing_data::prefs::kLastClearBrowsingDataTab] = settings_api::PrefType::PREF_TYPE_NUMBER; + (*s_allowlist)[browsing_data::prefs::kDeleteBrowsingHistoryAtStart] = + settings_api::PrefType::PREF_TYPE_BOOLEAN; + (*s_allowlist)[browsing_data::prefs::kDeleteDownloadHistoryAtStart] = + settings_api::PrefType::PREF_TYPE_BOOLEAN; + (*s_allowlist)[browsing_data::prefs::kDeleteCacheAtStart] = + settings_api::PrefType::PREF_TYPE_BOOLEAN; + (*s_allowlist)[browsing_data::prefs::kDeleteCookiesAtStart] = + settings_api::PrefType::PREF_TYPE_BOOLEAN; + (*s_allowlist)[browsing_data::prefs::kDeletePasswordsAtStart] = + settings_api::PrefType::PREF_TYPE_BOOLEAN; + (*s_allowlist)[browsing_data::prefs::kDeleteFormDataAtStart] = + settings_api::PrefType::PREF_TYPE_BOOLEAN; + (*s_allowlist)[browsing_data::prefs::kDeleteSiteSettingsAtStart] = + settings_api::PrefType::PREF_TYPE_BOOLEAN; + (*s_allowlist)[browsing_data::prefs::kDeleteHostedAppsDataAtStart] = + settings_api::PrefType::PREF_TYPE_BOOLEAN; + // Accessibility. (*s_allowlist)[::prefs::kAccessibilityImageLabelsEnabled] = settings_api::PrefType::PREF_TYPE_BOOLEAN; diff --git a/chrome/browser/profiles/android/java/src/org/chromium/chrome/browser/profiles/ProfileManagerUtils.java b/chrome/browser/profiles/android/java/src/org/chromium/chrome/browser/profiles/ProfileManagerUtils.java --- a/chrome/browser/profiles/android/java/src/org/chromium/chrome/browser/profiles/ProfileManagerUtils.java +++ b/chrome/browser/profiles/android/java/src/org/chromium/chrome/browser/profiles/ProfileManagerUtils.java @@ -52,9 +52,14 @@ public class ProfileManagerUtils { } } + public static void removeBrowsingDataAtStart() { + ProfileManagerUtilsJni.get().removeBrowsingDataAtStart(); + } + @NativeMethods interface Natives { void flushPersistentDataForAllProfiles(); void removeSessionCookiesForAllProfiles(); + void removeBrowsingDataAtStart(); } } diff --git a/chrome/browser/profiles/android/profile_manager_utils.cc b/chrome/browser/profiles/android/profile_manager_utils.cc --- a/chrome/browser/profiles/android/profile_manager_utils.cc +++ b/chrome/browser/profiles/android/profile_manager_utils.cc @@ -67,3 +67,8 @@ static void JNI_ProfileManagerUtils_RemoveSessionCookiesForAllProfiles( g_browser_process->profile_manager()->GetLoadedProfiles(), RemoveSessionCookiesForProfile); } + +static void JNI_ProfileManagerUtils_RemoveBrowsingDataAtStart( + JNIEnv* env) { + g_browser_process->profile_manager()->RemoveBrowsingDataAtStart(); +} diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profiles/profile_manager.cc --- a/chrome/browser/profiles/profile_manager.cc +++ b/chrome/browser/profiles/profile_manager.cc @@ -1492,6 +1492,19 @@ void ProfileManager::DoFinalInit(ProfileInfo* profile_info, } } +void ProfileManager::RemoveBrowsingDataAtStart() { + base::ranges::for_each( + GetLoadedProfiles(), + [](Profile* profile) { + auto* browsing_data_lifetime_manager = + ChromeBrowsingDataLifetimeManagerFactory::GetForProfile(profile); + if (browsing_data_lifetime_manager && !profile->IsOffTheRecord()) { + browsing_data_lifetime_manager->ClearBrowsingDataForOnExitPolicy( + /*keep_browser_alive=*/false); + } + }); +} + void ProfileManager::DoFinalInitForServices(Profile* profile, bool go_off_the_record) { if (!do_final_services_init_ || diff --git a/chrome/browser/profiles/profile_manager.h b/chrome/browser/profiles/profile_manager.h --- a/chrome/browser/profiles/profile_manager.h +++ b/chrome/browser/profiles/profile_manager.h @@ -202,6 +202,8 @@ class ProfileManager : public Profile::Delegate { // profiles. std::vector GetLoadedProfiles() const; + void RemoveBrowsingDataAtStart(); + // If a profile with the given path is currently managed by this object and // fully initialized, return a pointer to the corresponding Profile object; // otherwise return null. diff --git a/chrome/browser/resources/settings/clear_browsing_data_dialog/clear_browsing_data_dialog.html b/chrome/browser/resources/settings/clear_browsing_data_dialog/clear_browsing_data_dialog.html --- a/chrome/browser/resources/settings/clear_browsing_data_dialog/clear_browsing_data_dialog.html +++ b/chrome/browser/resources/settings/clear_browsing_data_dialog/clear_browsing_data_dialog.html @@ -284,6 +284,50 @@ disabled="[[clearingInProgress_]]" no-set-pref> +
+ + + + + + + + + + + + + + + + +
diff --git a/chrome/browser/resources/settings/clear_browsing_data_dialog/clear_browsing_data_dialog.ts b/chrome/browser/resources/settings/clear_browsing_data_dialog/clear_browsing_data_dialog.ts --- a/chrome/browser/resources/settings/clear_browsing_data_dialog/clear_browsing_data_dialog.ts +++ b/chrome/browser/resources/settings/clear_browsing_data_dialog/clear_browsing_data_dialog.ts @@ -194,6 +194,7 @@ export class SettingsClearBrowsingDataDialogElement extends value: () => [loadTimeData.getString('basicPageTitle'), loadTimeData.getString('advancedPageTitle'), + loadTimeData.getString('atStartPageTitle'), ], }, diff --git a/chrome/browser/ui/android/strings/android_chrome_strings.grd b/chrome/browser/ui/android/strings/android_chrome_strings.grd --- a/chrome/browser/ui/android/strings/android_chrome_strings.grd +++ b/chrome/browser/ui/android/strings/android_chrome_strings.grd @@ -1635,6 +1635,9 @@ Your Google account may have other forms of browsing history like searches and a Basic + + At Startup + Your Google Account may have other forms of browsing history at <link>myactivity.google.com</link>. diff --git a/chrome/browser/ui/webui/settings/settings_localized_strings_provider.cc b/chrome/browser/ui/webui/settings/settings_localized_strings_provider.cc --- a/chrome/browser/ui/webui/settings/settings_localized_strings_provider.cc +++ b/chrome/browser/ui/webui/settings/settings_localized_strings_provider.cc @@ -1584,6 +1584,7 @@ void AddPrivacyStrings(content::WebUIDataSource* html_source, {"clearedData", IDS_SETTINGS_CLEARED_DATA}, {"clearBrowsingData", IDS_SETTINGS_CLEAR_BROWSING_DATA}, {"clearBrowsingDataDescription", IDS_SETTINGS_CLEAR_DATA_DESCRIPTION}, + {"atStartPageTitle", IDS_CLEAR_BROWSING_DATA_ATSTART_TAB_TITLE}, {"titleAndCount", IDS_SETTINGS_TITLE_AND_COUNT}, {"safeBrowsingEnableExtendedReportingDesc", IDS_SETTINGS_SAFEBROWSING_ENABLE_REPORTING_DESC}, diff --git a/components/browsing_data/core/browsing_data_policies_utils.cc b/components/browsing_data/core/browsing_data_policies_utils.cc --- a/components/browsing_data/core/browsing_data_policies_utils.cc +++ b/components/browsing_data/core/browsing_data_policies_utils.cc @@ -17,21 +17,21 @@ namespace browsing_data { -namespace { - namespace policy_data_types { // Data retention policy types that require sync to be disabled. -constexpr char kBrowsingHistoryName[] = "browsing_history"; -constexpr char kPasswordSigninName[] = "password_signin"; -constexpr char kAutofillName[] = "autofill"; -constexpr char kSiteSettingsName[] = "site_settings"; +extern constexpr char kBrowsingHistoryName[] = "browsing_history"; +extern constexpr char kPasswordSigninName[] = "password_signin"; +extern constexpr char kAutofillName[] = "autofill"; +extern constexpr char kSiteSettingsName[] = "site_settings"; // Data retention policy types that do not require sync to be disabled. -constexpr char kHostedAppDataName[] = "hosted_app_data"; -constexpr char kDownloadHistoryName[] = "download_history"; -constexpr char kCookiesAndOtherSiteDataName[] = "cookies_and_other_site_data"; -constexpr char kCachedImagesAndFilesName[] = "cached_images_and_files"; +extern constexpr char kHostedAppDataName[] = "hosted_app_data"; +extern constexpr char kDownloadHistoryName[] = "download_history"; +extern constexpr char kCookiesAndOtherSiteDataName[] = "cookies_and_other_site_data"; +extern constexpr char kCachedImagesAndFilesName[] = "cached_images_and_files"; } // namespace policy_data_types +namespace { + // The format of the log message shown in chrome://policy/logs when sync types // are automatically disabled. constexpr char kDisabledSyncTypesLogFormat[] = diff --git a/components/browsing_data/core/browsing_data_policies_utils.h b/components/browsing_data/core/browsing_data_policies_utils.h --- a/components/browsing_data/core/browsing_data_policies_utils.h +++ b/components/browsing_data/core/browsing_data_policies_utils.h @@ -12,6 +12,17 @@ namespace browsing_data { +namespace policy_data_types { +extern const char kBrowsingHistoryName[]; +extern const char kDownloadHistoryName[]; +extern const char kCookiesAndOtherSiteDataName[]; +extern const char kCachedImagesAndFilesName[]; +extern const char kPasswordSigninName[]; +extern const char kAutofillName[]; +extern const char kSiteSettingsName[]; +extern const char kHostedAppDataName[]; +} // namespace policy_data_types + // The data types of the BrowsingDataSettings policy. enum class PolicyDataType { kBrowsingHistory = 0, diff --git a/components/browsing_data/core/browsing_data_utils.cc b/components/browsing_data/core/browsing_data_utils.cc --- a/components/browsing_data/core/browsing_data_utils.cc +++ b/components/browsing_data/core/browsing_data_utils.cc @@ -318,6 +318,40 @@ bool GetDeletionPreferenceFromDataType( BrowsingDataType data_type, ClearBrowsingDataTab clear_browsing_data_tab, std::string* out_pref) { + if (clear_browsing_data_tab == ClearBrowsingDataTab::AT_START) { + switch (data_type) { + case BrowsingDataType::HISTORY: + *out_pref = prefs::kDeleteBrowsingHistoryAtStart; + return true; + case BrowsingDataType::CACHE: + *out_pref = prefs::kDeleteCacheAtStart; + return true; + case BrowsingDataType::COOKIES: + *out_pref = prefs::kDeleteCookiesAtStart; + return true; + case BrowsingDataType::PASSWORDS: + *out_pref = prefs::kDeletePasswordsAtStart; + return true; + case BrowsingDataType::FORM_DATA: + *out_pref = prefs::kDeleteFormDataAtStart; + return true; + case BrowsingDataType::BOOKMARKS: + return false; + case BrowsingDataType::SITE_SETTINGS: + *out_pref = prefs::kDeleteSiteSettingsAtStart; + return true; + case BrowsingDataType::DOWNLOADS: + *out_pref = prefs::kDeleteDownloadHistoryAtStart; + return true; + case BrowsingDataType::HOSTED_APPS_DATA: + *out_pref = prefs::kDeleteHostedAppsDataAtStart; + return true; + case BrowsingDataType::NUM_TYPES: + NOTREACHED(); // This is not an actual type. + return false; + } + } + if (clear_browsing_data_tab == ClearBrowsingDataTab::BASIC) { switch (data_type) { case BrowsingDataType::HISTORY: diff --git a/components/browsing_data/core/clear_browsing_data_tab.h b/components/browsing_data/core/clear_browsing_data_tab.h --- a/components/browsing_data/core/clear_browsing_data_tab.h +++ b/components/browsing_data/core/clear_browsing_data_tab.h @@ -18,7 +18,7 @@ namespace browsing_data { // // A Java counterpart will be generated for this enum. // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.browsing_data -enum class ClearBrowsingDataTab { BASIC, ADVANCED, NUM_TYPES }; +enum class ClearBrowsingDataTab { BASIC, ADVANCED, AT_START, NUM_TYPES }; } // namespace browsing_data diff --git a/components/browsing_data/core/pref_names.cc b/components/browsing_data/core/pref_names.cc --- a/components/browsing_data/core/pref_names.cc +++ b/components/browsing_data/core/pref_names.cc @@ -26,6 +26,16 @@ const char kClearBrowsingDataOnExitDeletionPending[] = // delete just before browser shutdown. const char kClearBrowsingDataOnExitList[] = "browser.clear_data.clear_on_exit"; +// Clear Browsing Data dialog datatype preferences. +const char kDeleteBrowsingHistoryAtStart[] = "browser.clear_data.browsing_history_at_start"; +const char kDeleteDownloadHistoryAtStart[] = "browser.clear_data.download_history_at_start"; +const char kDeleteCacheAtStart[] = "browser.clear_data.cache_at_start"; +const char kDeleteCookiesAtStart[] = "browser.clear_data.cookies_at_start"; +const char kDeletePasswordsAtStart[] = "browser.clear_data.passwords_at_start"; +const char kDeleteFormDataAtStart[] = "browser.clear_data.form_data_at_start"; +const char kDeleteHostedAppsDataAtStart[] = "browser.clear_data.hosted_apps_data_at_start"; +const char kDeleteSiteSettingsAtStart[] = "browser.clear_data.site_settings_at_start"; + // Clear browsing data deletion time period. const char kDeleteTimePeriod[] = "browser.clear_data.time_period"; const char kDeleteTimePeriodBasic[] = "browser.clear_data.time_period_basic"; @@ -85,6 +95,23 @@ void RegisterBrowserUserPrefs(user_prefs::PrefRegistrySyncable* registry) { registry->RegisterIntegerPref( kClearBrowsingDataHistoryNoticeShownTimes, 0); + registry->RegisterBooleanPref( + kDeleteBrowsingHistoryAtStart, false); + registry->RegisterBooleanPref( + kDeleteDownloadHistoryAtStart, false); + registry->RegisterBooleanPref( + kDeleteCacheAtStart, false); + registry->RegisterBooleanPref( + kDeleteCookiesAtStart, false); + registry->RegisterBooleanPref( + kDeletePasswordsAtStart, false); + registry->RegisterBooleanPref( + kDeleteFormDataAtStart, false); + registry->RegisterBooleanPref( + kDeleteHostedAppsDataAtStart, false); + registry->RegisterBooleanPref( + kDeleteSiteSettingsAtStart, false); + #if !BUILDFLAG(IS_IOS) registry->RegisterBooleanPref( kDeleteDownloadHistory, true, diff --git a/components/browsing_data/core/pref_names.h b/components/browsing_data/core/pref_names.h --- a/components/browsing_data/core/pref_names.h +++ b/components/browsing_data/core/pref_names.h @@ -17,6 +17,15 @@ extern const char kBrowsingDataLifetime[]; extern const char kClearBrowsingDataOnExitDeletionPending[]; extern const char kClearBrowsingDataOnExitList[]; +extern const char kDeleteBrowsingHistoryAtStart[]; +extern const char kDeleteDownloadHistoryAtStart[]; +extern const char kDeleteCacheAtStart[]; +extern const char kDeleteCookiesAtStart[]; +extern const char kDeletePasswordsAtStart[]; +extern const char kDeleteFormDataAtStart[]; +extern const char kDeleteHostedAppsDataAtStart[]; +extern const char kDeleteSiteSettingsAtStart[]; + extern const char kDeleteTimePeriod[]; extern const char kDeleteTimePeriodBasic[]; diff --git a/content/browser/storage_partition_impl.cc b/content/browser/storage_partition_impl.cc --- a/content/browser/storage_partition_impl.cc +++ b/content/browser/storage_partition_impl.cc @@ -1542,6 +1542,7 @@ void StoragePartitionImpl::Initialize( .AppendASCII("Code Cache"); } DCHECK_GE(settings.size_in_bytes(), 0); + base::DeletePathRecursively(code_cache_path); GetGeneratedCodeCacheContext()->Initialize(code_cache_path, settings.size_in_bytes()); } -- 2.25.1