-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added SystemNudgePauseManager to support system nudge pause
This CL added a SystemNudgePauseManager to manage all SystemNudgeController so that we could add a ScopedNudgePause to suppress them. SystemNudgePauseManager has a static getter to get the singleton. When a ScopedNudgePause is constructed, the manager will suppress all the system nudges immediately until ScopedNudgePause is destroyed. Unittests are added in SystemNudgeTest. Bug: b:271480256 Change-Id: I79ea2a3e263e3546c9239d9099c25855c1496085 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4736620 Reviewed-by: Ahmed Fakhry <afakhry@chromium.org> Commit-Queue: Sylvie Liu <sylvieliu@chromium.org> Reviewed-by: Alex Newcomer <newcomer@chromium.org> Cr-Commit-Position: refs/heads/main@{#1184302}
- Loading branch information
Sylvie Liu
authored and
Chromium LUCI CQ
committed
Aug 16, 2023
1 parent
e757559
commit e13f7b8
Showing
19 changed files
with
375 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "ash/public/cpp/system/scoped_nudge_pause.h" | ||
|
||
#include "ash/constants/ash_features.h" | ||
#include "ash/public/cpp/system/anchored_nudge_manager.h" | ||
#include "ash/public/cpp/system/system_nudge_pause_manager.h" | ||
|
||
namespace ash { | ||
|
||
ScopedNudgePause::ScopedNudgePause() { | ||
if (features::IsSystemNudgeV2Enabled()) { | ||
AnchoredNudgeManager::Get()->Pause(); | ||
} | ||
SystemNudgePauseManager::Get()->Pause(); | ||
} | ||
|
||
ScopedNudgePause::~ScopedNudgePause() { | ||
if (features::IsSystemNudgeV2Enabled()) { | ||
AnchoredNudgeManager::Get()->Resume(); | ||
} | ||
SystemNudgePauseManager::Get()->Resume(); | ||
} | ||
|
||
} // namespace ash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef ASH_PUBLIC_CPP_SYSTEM_SCOPED_NUDGE_PAUSE_H_ | ||
#define ASH_PUBLIC_CPP_SYSTEM_SCOPED_NUDGE_PAUSE_H_ | ||
|
||
#include "ash/public/cpp/ash_public_export.h" | ||
|
||
namespace ash { | ||
|
||
// An object that pauses both anchored nudge and system nudge for its lifetime. | ||
// TODO(b/295378782): Move this class to `AnchoredNudgeManager` once complete | ||
// migrating all nudges to `AnchoredNudgeManager`. | ||
class ASH_PUBLIC_EXPORT ScopedNudgePause { | ||
public: | ||
ScopedNudgePause(); | ||
ScopedNudgePause(const ScopedNudgePause&) = delete; | ||
ScopedNudgePause& operator=(const ScopedNudgePause&) = delete; | ||
~ScopedNudgePause(); | ||
}; | ||
|
||
} // namespace ash | ||
|
||
#endif // ASH_PUBLIC_CPP_SYSTEM_SCOPED_NUDGE_PAUSE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "ash/public/cpp/system/system_nudge_pause_manager.h" | ||
|
||
#include "base/check_op.h" | ||
|
||
namespace ash { | ||
|
||
namespace { | ||
|
||
SystemNudgePauseManager* g_instance = nullptr; | ||
|
||
} // namespace | ||
|
||
// static | ||
SystemNudgePauseManager* SystemNudgePauseManager::Get() { | ||
return g_instance; | ||
} | ||
|
||
SystemNudgePauseManager::SystemNudgePauseManager() { | ||
CHECK(!g_instance); | ||
g_instance = this; | ||
} | ||
|
||
SystemNudgePauseManager::~SystemNudgePauseManager() { | ||
CHECK_EQ(this, g_instance); | ||
g_instance = nullptr; | ||
} | ||
|
||
} // namespace ash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef ASH_PUBLIC_CPP_SYSTEM_SYSTEM_NUDGE_PAUSE_MANAGER_H_ | ||
#define ASH_PUBLIC_CPP_SYSTEM_SYSTEM_NUDGE_PAUSE_MANAGER_H_ | ||
|
||
#include <memory> | ||
|
||
#include "ash/public/cpp/ash_public_export.h" | ||
|
||
namespace ash { | ||
|
||
class ScopedNudgePause; | ||
class SystemNudgeController; | ||
|
||
// Public interface to manage `SystemNudgeController`. This is needed for | ||
// `ScopedNudgePause` since we need a singleton class to manage all the | ||
// `SystemNudgeController`s to respond to `ScopedNudgePause`'s construction or | ||
// destruction. | ||
class ASH_PUBLIC_EXPORT SystemNudgePauseManager { | ||
public: | ||
// Returns the singleton `SystemNudgePauseManager`. | ||
static SystemNudgePauseManager* Get(); | ||
|
||
// Creates a `ScopedNudgePause`. | ||
virtual std::unique_ptr<ScopedNudgePause> CreateScopedPause() = 0; | ||
|
||
protected: | ||
SystemNudgePauseManager(); | ||
virtual ~SystemNudgePauseManager(); | ||
|
||
private: | ||
friend class ScopedNudgePause; | ||
|
||
// `Pause()` will stop all the nudges from showing up, until `Resume()` is | ||
// called. | ||
virtual void Pause() = 0; | ||
virtual void Resume() = 0; | ||
}; | ||
|
||
} // namespace ash | ||
|
||
#endif // ASH_PUBLIC_CPP_SYSTEM_SYSTEM_NUDGE_PAUSE_MANAGER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.