Skip to content

Commit

Permalink
Reland "Multipaste: Add flag for resetting nudge prefs on new session"
Browse files Browse the repository at this point in the history
This is a reland of 315d5cd

The original change was reverted because of test failures due to the
feature not being added to tools/metrics/histograms/enums.xml.

Original change's description:
> Multipaste: Add flag for resetting nudge prefs on new session
>
> Add a flag which, when enabled, will reset the clipboard nudge prefs
> on a new user session. This will allow the nudge to be shown again.
>
> Bug: 1140656
> Change-Id: I312f05eed655fc1657843d2b7a45214bb671bebe
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2489020
> Reviewed-by: Alex Newcomer <newcomer@chromium.org>
> Commit-Queue: Matthew Mourgos <mmourgos@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#819483}

Bug: 1140656
Change-Id: I476e50a8ce89a810608636123bf0187e9f360b49
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2490853
Commit-Queue: Matthew Mourgos <mmourgos@chromium.org>
Reviewed-by: Alex Newcomer <newcomer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819686}
  • Loading branch information
Matthew Mourgos authored and Commit Bot committed Oct 22, 2020
1 parent 3e58147 commit dfd6d85
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 1 deletion.
13 changes: 13 additions & 0 deletions ash/clipboard/clipboard_nudge_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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<ClipboardNudge>();
Expand Down
7 changes: 6 additions & 1 deletion ash/clipboard/clipboard_nudge_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand All @@ -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();

Expand Down
5 changes: 5 additions & 0 deletions chrome/browser/about_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions chrome/browser/flag-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
6 changes: 6 additions & 0 deletions chrome/browser/flag_descriptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/flag_descriptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[];

Expand Down
9 changes: 9 additions & 0 deletions chromeos/constants/chromeos_features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -730,6 +735,10 @@ bool IsClipboardHistoryEnabled() {
base::FeatureList::IsEnabled(kClipboardHistorySimpleRender);
}

bool IsClipboardHistoryNudgeSessionResetEnabled() {
return base::FeatureList::IsEnabled(kClipboardHistoryNudgeSessionReset);
}

bool IsClipboardHistorySimpleRenderEnabled() {
return base::FeatureList::IsEnabled(kClipboardHistorySimpleRender);
}
Expand Down
4 changes: 4 additions & 0 deletions chromeos/constants/chromeos_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions tools/metrics/histograms/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42882,6 +42882,7 @@ from previous Chrome versions.
<int value="-850821337" label="WebContentsForceDark:enabled"/>
<int value="-848691867" label="DesktopPWAWindowing:enabled"/>
<int value="-847216521" label="ChromeDuplex:enabled"/>
<int value="-844786349" label="ClipboardHistoryNudgeSessionReset:enabled"/>
<int value="-844537521" label="HttpFormWarning:disabled"/>
<int value="-844381918" label="ArcNativeBridgeExperiment:disabled"/>
<int value="-843496368" label="AutofillRejectCompanyBirthyear:disabled"/>
Expand Down Expand Up @@ -44972,6 +44973,7 @@ from previous Chrome versions.
<int value="1283956865" label="force-tablet-mode"/>
<int value="1283960113" label="disable-fixed-position-compositing"/>
<int value="1284910808" label="disable-checker-imaging"/>
<int value="1285169797" label="ClipboardHistoryNudgeSessionReset:disabled"/>
<int value="1285905715" label="WebXRHitTest:enabled"/>
<int value="1287625114" label="EnableIncognitoShortcutOnDesktop:disabled"/>
<int value="1289433604" label="RecoverFromNeverSaveAndroid:enabled"/>
Expand Down

0 comments on commit dfd6d85

Please sign in to comment.