desk_template.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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_PUBLIC_CPP_DESK_TEMPLATE_H_
  5. #define ASH_PUBLIC_CPP_DESK_TEMPLATE_H_
  6. #include <string>
  7. #include "ash/public/cpp/ash_public_export.h"
  8. #include "base/guid.h"
  9. #include "base/time/time.h"
  10. #include "components/app_restore/restore_data.h"
  11. namespace aura {
  12. class Window;
  13. } // namespace aura
  14. namespace ash {
  15. // Indicates where a desk template originated from.
  16. enum class ASH_PUBLIC_EXPORT DeskTemplateSource {
  17. // Default value, indicates no value was set.
  18. kUnknownSource = 0,
  19. // Desk template created by the user.
  20. kUser,
  21. // Desk template pushed through policy.
  22. kPolicy
  23. };
  24. enum class ASH_PUBLIC_EXPORT DeskTemplateType {
  25. // Regular desk template.
  26. kTemplate = 0,
  27. // Desk saved for Save & Recall.
  28. kSaveAndRecall,
  29. // Unknown desk type. This desk is probably created by a later version and
  30. // should be ignored.
  31. kUnknown,
  32. };
  33. // Class to represent a desk template. It can be used to create a desk with
  34. // a certain set of application windows specified in |desk_restore_data_|.
  35. class ASH_PUBLIC_EXPORT DeskTemplate {
  36. public:
  37. // This constructor is used to instantiate DeskTemplate with a specific
  38. // source.
  39. DeskTemplate(base::GUID uuid,
  40. DeskTemplateSource source,
  41. const std::string& name,
  42. const base::Time created_time,
  43. DeskTemplateType type);
  44. DeskTemplate(const DeskTemplate&) = delete;
  45. DeskTemplate& operator=(const DeskTemplate&) = delete;
  46. ~DeskTemplate();
  47. // Returns whether desk templates support the `window`'s app type.
  48. static bool IsAppTypeSupported(aura::Window* window);
  49. // A special value to use as an icon identifier for an incognito window.
  50. static constexpr char kIncognitoWindowIdentifier[] = "incognito_window";
  51. const base::GUID& uuid() const { return uuid_; }
  52. DeskTemplateSource source() const { return source_; }
  53. base::Time created_time() const { return created_time_; }
  54. void set_updated_time(base::Time updated_time) {
  55. updated_time_ = updated_time;
  56. }
  57. void clear_updated_time() { updated_time_ = base::Time(); }
  58. const std::u16string& template_name() const { return template_name_; }
  59. void set_template_name(const std::u16string& template_name) {
  60. template_name_ = template_name;
  61. }
  62. DeskTemplateType type() const { return type_; }
  63. const ::app_restore::RestoreData* desk_restore_data() const {
  64. return desk_restore_data_.get();
  65. }
  66. ::app_restore::RestoreData* mutable_desk_restore_data() {
  67. return desk_restore_data_.get();
  68. }
  69. void set_desk_restore_data(
  70. std::unique_ptr<::app_restore::RestoreData> restore_data) {
  71. desk_restore_data_ = std::move(restore_data);
  72. }
  73. void set_launch_id(int32_t launch_id) { launch_id_ = launch_id; }
  74. int32_t launch_id() const { return launch_id_; }
  75. // Used in cases where copies of a DeskTemplate are needed to be made.
  76. // This specifically used in the DeskSyncBridge which requires a map
  77. // of DeskTemplate unique pointers to be valid and needs to pass
  78. // that information in DeskModel callbacks.
  79. std::unique_ptr<DeskTemplate> Clone() const;
  80. // Indicates the last time the user created or updated this template.
  81. // If this desk template was never updated since creation, its creation time
  82. // will be returned.
  83. base::Time GetLastUpdatedTime() const {
  84. return updated_time_.is_null() ? created_time_ : updated_time_;
  85. }
  86. // Indicates whether this template has been updated since creation.
  87. bool WasUpdatedSinceCreation() const { return !updated_time_.is_null(); }
  88. // Indicates whether this template can be modified by user.
  89. bool IsModifiable() const { return source_ == DeskTemplateSource::kUser; }
  90. // Sets `desk_index` as the desk to launch on for all windows in the template.
  91. void SetDeskIndex(int desk_index);
  92. // Returns `this` in string format. Used for feedback logs.
  93. std::string ToString() const;
  94. // Returns `this` in string format. Used for debugging.
  95. std::string ToDebugString() const;
  96. private:
  97. // Returns a string containing basic information for `this`. It could be used
  98. // for `ToString` and `ToDebugString` according to the given `for_debugging`.
  99. std::string GetDeskTemplateInfo(bool for_debugging) const;
  100. const base::GUID uuid_; // We utilize the string based base::GUID to uniquely
  101. // identify the template.
  102. // Indicates the source where this desk template originates from.
  103. const DeskTemplateSource source_;
  104. // The type of this desk template.
  105. const DeskTemplateType type_;
  106. const base::Time created_time_; // Template creation time.
  107. // Indicates the last time the user updated this template.
  108. // If this desk template was never updated since creation, this field will
  109. // have null value.
  110. base::Time updated_time_;
  111. std::u16string template_name_;
  112. // The id associated with a particular launch of this template. Must be
  113. // positive when launching.
  114. int32_t launch_id_ = 0;
  115. // Contains the app launching and window information that can be used to
  116. // create a new desk instance with the same set of apps/windows specified in
  117. // it.
  118. std::unique_ptr<::app_restore::RestoreData> desk_restore_data_;
  119. };
  120. } // namespace ash
  121. #endif // ASH_PUBLIC_CPP_DESK_TEMPLATE_H_