diff --git a/ash/clipboard/clipboard_nudge_controller.cc b/ash/clipboard/clipboard_nudge_controller.cc index dd9eb3341a64c5..b93b2dcfaec34d 100644 --- a/ash/clipboard/clipboard_nudge_controller.cc +++ b/ash/clipboard/clipboard_nudge_controller.cc @@ -13,6 +13,7 @@ #include "base/logging.h" #include "base/no_destructor.h" #include "base/util/values/values_util.h" +#include "chromeos/constants/chromeos_features.h" #include "components/prefs/pref_registry_simple.h" #include "components/prefs/pref_service.h" #include "components/prefs/scoped_user_pref_update.h" @@ -33,11 +34,15 @@ ClipboardNudgeController::ClipboardNudgeController( : clipboard_history_(clipboard_history) { clipboard_history_->AddObserver(this); ui::ClipboardMonitor::GetInstance()->AddObserver(this); + if (chromeos::features::IsClipboardHistoryNudgeSessionResetEnabled()) + Shell::Get()->session_controller()->AddObserver(this); } ClipboardNudgeController::~ClipboardNudgeController() { clipboard_history_->RemoveObserver(this); ui::ClipboardMonitor::GetInstance()->RemoveObserver(this); + if (chromeos::features::IsClipboardHistoryNudgeSessionResetEnabled()) + Shell::Get()->session_controller()->RemoveObserver(this); } // static @@ -98,6 +103,14 @@ void ClipboardNudgeController::OnClipboardDataRead() { } } +void ClipboardNudgeController::OnActiveUserPrefServiceChanged( + PrefService* prefs) { + // Reset the nudge prefs so that the nudge can be shown again. + DictionaryPrefUpdate update(prefs, prefs::kMultipasteNudges); + update->SetIntPath(kShownCount, 0); + update->SetPath(kLastTimeShown, util::TimeToValue(base::Time())); +} + void ClipboardNudgeController::ShowNudge() { // Create and show the nudge. nudge_ = std::make_unique(); diff --git a/ash/clipboard/clipboard_nudge_controller.h b/ash/clipboard/clipboard_nudge_controller.h index a7c12bac44751f..27d6966e84e247 100644 --- a/ash/clipboard/clipboard_nudge_controller.h +++ b/ash/clipboard/clipboard_nudge_controller.h @@ -7,6 +7,7 @@ #include "ash/ash_export.h" #include "ash/clipboard/clipboard_history.h" +#include "ash/public/cpp/session/session_observer.h" #include "base/memory/weak_ptr.h" #include "base/time/clock.h" #include "base/timer/timer.h" @@ -31,7 +32,8 @@ enum class ClipboardState { }; class ASH_EXPORT ClipboardNudgeController : public ClipboardHistory::Observer, - public ui::ClipboardObserver { + public ui::ClipboardObserver, + public SessionObserver { public: ClipboardNudgeController(ClipboardHistory* clipboard_history); ClipboardNudgeController(const ClipboardNudgeController&) = delete; @@ -47,6 +49,9 @@ class ASH_EXPORT ClipboardNudgeController : public ClipboardHistory::Observer, // ui::ClipboardObserver: void OnClipboardDataRead() override; + // SessionObserver: + void OnActiveUserPrefServiceChanged(PrefService* prefs) override; + // Resets nudge state and show nudge timer. void HandleNudgeShown(); diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc index b0f1b583ecad15..797a43debbc844 100644 --- a/chrome/browser/about_flags.cc +++ b/chrome/browser/about_flags.cc @@ -6193,6 +6193,11 @@ const FeatureEntry kFeatureEntries[] = { {"enhanced_clipboard", flag_descriptions::kEnhancedClipboardName, flag_descriptions::kEnhancedClipboardDescription, kOsCrOS, FEATURE_VALUE_TYPE(chromeos::features::kClipboardHistory)}, + {"enhanced_clipboard_nudge_session_reset", + flag_descriptions::kEnhancedClipboardNudgeSessionResetName, + flag_descriptions::kEnhancedClipboardNudgeSessionResetDescription, kOsCrOS, + FEATURE_VALUE_TYPE( + chromeos::features::kClipboardHistoryNudgeSessionReset)}, {"enhanced_clipboard_simple_render", flag_descriptions::kEnhancedClipboardSimpleRenderName, flag_descriptions::kEnhancedClipboardSimpleRenderDescription, kOsCrOS, diff --git a/chrome/browser/flag-metadata.json b/chrome/browser/flag-metadata.json index 2351fe2e94fed4..f6c0d8be53ec8b 100644 --- a/chrome/browser/flag-metadata.json +++ b/chrome/browser/flag-metadata.json @@ -2423,6 +2423,11 @@ "owners": ["newcomer@chromium.org", "tbarzic@chromium.org"], "expiry_milestone": 90 }, + { + "name": "enhanced_clipboard_nudge_session_reset", + "owners":["mmourgos@chromium.org", "newcomer@chromium.org"], + "expiry_milestone": 90 + }, { "name": "enhanced_clipboard_simple_render", "owners":["newcomer@chromium.org", "gzadina@google.com"], diff --git a/chrome/browser/flag_descriptions.cc b/chrome/browser/flag_descriptions.cc index 67b94ed5a0e164..4217d608ba4d83 100644 --- a/chrome/browser/flag_descriptions.cc +++ b/chrome/browser/flag_descriptions.cc @@ -3898,6 +3898,12 @@ const char kEnhancedClipboardDescription[] = "history. Selecting something from the menu will result in a paste to the " "active window."; +extern const char kEnhancedClipboardNudgeSessionResetName[] = + "Enable resetting enhanced clipboard nudge data"; +extern const char kEnhancedClipboardNudgeSessionResetDescription[] = + "When enabled, this will reset the clipboard nudge shown data on every new " + "user session, allowing the nudge to be shown again."; + const char kEnhancedClipboardSimpleRenderName[] = "Only renders html in the Enhanced Clipboard if there are img or table " "tags"; diff --git a/chrome/browser/flag_descriptions.h b/chrome/browser/flag_descriptions.h index 5f8411e473eb55..172d6c015559b2 100644 --- a/chrome/browser/flag_descriptions.h +++ b/chrome/browser/flag_descriptions.h @@ -2256,6 +2256,9 @@ extern const char kDragToSnapInClamshellModeDescription[]; extern const char kEnhancedClipboardName[]; extern const char kEnhancedClipboardDescription[]; +extern const char kEnhancedClipboardNudgeSessionResetName[]; +extern const char kEnhancedClipboardNudgeSessionResetDescription[]; + extern const char kEnhancedClipboardSimpleRenderName[]; extern const char kEnhancedClipboardSimpleRenderDescription[]; diff --git a/chromeos/constants/chromeos_features.cc b/chromeos/constants/chromeos_features.cc index 6ff38bca814325..0c48e1c0cb2adc 100644 --- a/chromeos/constants/chromeos_features.cc +++ b/chromeos/constants/chromeos_features.cc @@ -327,6 +327,11 @@ const base::Feature kMojoDBusRelay{"MojoDBusRelay", const base::Feature kClipboardHistory{"ClipboardHistory", base::FEATURE_DISABLED_BY_DEFAULT}; +// If enabled, the clipboard nudge shown prefs will be reset at the start of +// each new user session. +const base::Feature kClipboardHistoryNudgeSessionReset{ + "ClipboardHistoryNudgeSessionReset", base::FEATURE_DISABLED_BY_DEFAULT}; + // Enables rendering html in Clipboard History only if an img or table tag is // present. const base::Feature kClipboardHistorySimpleRender{ @@ -730,6 +735,10 @@ bool IsClipboardHistoryEnabled() { base::FeatureList::IsEnabled(kClipboardHistorySimpleRender); } +bool IsClipboardHistoryNudgeSessionResetEnabled() { + return base::FeatureList::IsEnabled(kClipboardHistoryNudgeSessionReset); +} + bool IsClipboardHistorySimpleRenderEnabled() { return base::FeatureList::IsEnabled(kClipboardHistorySimpleRender); } diff --git a/chromeos/constants/chromeos_features.h b/chromeos/constants/chromeos_features.h index d522df97769737..c77b5e155f12b7 100644 --- a/chromeos/constants/chromeos_features.h +++ b/chromeos/constants/chromeos_features.h @@ -150,6 +150,8 @@ COMPONENT_EXPORT(CHROMEOS_CONSTANTS) extern const base::Feature kMojoDBusRelay; COMPONENT_EXPORT(CHROMEOS_CONSTANTS) extern const base::Feature kClipboardHistory; COMPONENT_EXPORT(CHROMEOS_CONSTANTS) +extern const base::Feature kClipboardHistoryNudgeSessionReset; +COMPONENT_EXPORT(CHROMEOS_CONSTANTS) extern const base::Feature kClipboardHistorySimpleRender; COMPONENT_EXPORT(CHROMEOS_CONSTANTS) extern const base::Feature kEnableFilesAppCopyImage; @@ -318,6 +320,8 @@ COMPONENT_EXPORT(CHROMEOS_CONSTANTS) bool IsLoginDisplayPasswordButtonEnabled(); COMPONENT_EXPORT(CHROMEOS_CONSTANTS) bool IsMinimumChromeVersionEnabled(); COMPONENT_EXPORT(CHROMEOS_CONSTANTS) bool IsClipboardHistoryEnabled(); COMPONENT_EXPORT(CHROMEOS_CONSTANTS) +bool IsClipboardHistoryNudgeSessionResetEnabled(); +COMPONENT_EXPORT(CHROMEOS_CONSTANTS) bool IsClipboardHistorySimpleRenderEnabled(); COMPONENT_EXPORT(CHROMEOS_CONSTANTS) bool IsOobeScreensPriorityEnabled(); COMPONENT_EXPORT(CHROMEOS_CONSTANTS) bool IsPhoneHubEnabled(); diff --git a/tools/metrics/histograms/enums.xml b/tools/metrics/histograms/enums.xml index ed8c97f8d6c442..5f6b888b67fcb5 100644 --- a/tools/metrics/histograms/enums.xml +++ b/tools/metrics/histograms/enums.xml @@ -42882,6 +42882,7 @@ from previous Chrome versions. + @@ -44972,6 +44973,7 @@ from previous Chrome versions. +