message_view_factory.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ASH_SYSTEM_MESSAGE_CENTER_MESSAGE_VIEW_FACTORY_H_
  5. #define ASH_SYSTEM_MESSAGE_CENTER_MESSAGE_VIEW_FACTORY_H_
  6. #include "ash/ash_export.h"
  7. #include <memory>
  8. #include <string>
  9. #include "base/callback_forward.h"
  10. namespace message_center {
  11. class MessageView;
  12. class Notification;
  13. } // namespace message_center
  14. namespace ash {
  15. // Creates appropriate MessageViews for notifications depending on the
  16. // notification type.
  17. class ASH_EXPORT MessageViewFactory {
  18. public:
  19. // A function that creates MessageView for a NOTIFICATION_TYPE_CUSTOM
  20. // notification.
  21. using CustomMessageViewFactoryFunction =
  22. base::RepeatingCallback<std::unique_ptr<message_center::MessageView>(
  23. const message_center::Notification&,
  24. bool shown_in_popup)>;
  25. // Create appropriate MessageViews based on the given notification.
  26. static std::unique_ptr<message_center::MessageView> Create(
  27. const message_center::Notification& notification,
  28. bool shown_in_popup);
  29. // Sets the function that will be invoked to create a custom notification view
  30. // for a specific |custom_view_type|. This should be a repeating callback.
  31. // It's an error to attempt to show a custom notification without first having
  32. // called this function. The |custom_view_type| on the notification should
  33. // also match the type used here.
  34. static void SetCustomNotificationViewFactory(
  35. const std::string& custom_view_type,
  36. const CustomMessageViewFactoryFunction& factory_function);
  37. static bool HasCustomNotificationViewFactory(
  38. const std::string& custom_view_type);
  39. static void ClearCustomNotificationViewFactory(
  40. const std::string& custom_view_type);
  41. };
  42. } // namespace ash
  43. #endif // ASH_SYSTEM_MESSAGE_CENTER_MESSAGE_VIEW_FACTORY_H_