app_restore_utils.h 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 COMPONENTS_APP_RESTORE_APP_RESTORE_UTILS_H_
  5. #define COMPONENTS_APP_RESTORE_APP_RESTORE_UTILS_H_
  6. #include "base/component_export.h"
  7. #include "ui/views/widget/widget.h"
  8. namespace app_restore {
  9. struct WindowInfo;
  10. // For ARC session id, 1 ~ 1000000000 is used as the window id for all new app
  11. // launching. 1000000001 - INT_MAX is used as the session id for all restored
  12. // app launching read from the full restore file.
  13. //
  14. // Assuming each day the new windows launched account is 1M, the above scope is
  15. // enough for 3 years (1000 days). So there should be enough number to be
  16. // assigned for ARC session ids.
  17. constexpr int32_t kArcSessionIdOffsetForRestoredLaunching = 1000000000;
  18. // If the ARC task is not created when the window is initialized, set the
  19. // restore window id as -1, to add the ARC app window to the hidden container.
  20. constexpr int32_t kParentToHiddenContainer = -1;
  21. // Returns true if `window` is an ARC window. Otherwise, returns false.
  22. bool IsArcWindow(aura::Window* window);
  23. // Returns true if `window` is a Lacros window. Otherwise, returns false.
  24. bool IsLacrosWindow(aura::Window* window);
  25. // Returns true if there is a window info for `restore_window_id` from desk
  26. // templates or full restore, depending on which one is thought to be launching
  27. // apps currently. Otherwise, returns false. This interface can't be used for
  28. // ARC app windows.
  29. COMPONENT_EXPORT(APP_RESTORE)
  30. bool HasWindowInfo(int32_t restore_window_id);
  31. // Applies properties from `window_info` to the given `property_handler`.
  32. // This is called from `GetWindowInfo()` when window is
  33. // created, or from the ArcReadHandler when a task is ready for a full
  34. // restore window that has already been created.
  35. COMPONENT_EXPORT(APP_RESTORE)
  36. void ApplyProperties(WindowInfo* window_info,
  37. ui::PropertyHandler* property_handler);
  38. // Modifies `out_params` based on the window info associated with
  39. // `restore_window_id`.
  40. COMPONENT_EXPORT(APP_RESTORE)
  41. void ModifyWidgetParams(int32_t restore_window_id,
  42. views::Widget::InitParams* out_params);
  43. // Fetches the restore window id from the restore data for the given `app_id`.
  44. // `app_id` should be a Chrome app id.
  45. COMPONENT_EXPORT(APP_RESTORE)
  46. int32_t FetchRestoreWindowId(const std::string& app_id);
  47. // Generates the ARC session id (1,000,000,001 - INT_MAX) for restored ARC
  48. // apps.
  49. COMPONENT_EXPORT(APP_RESTORE) int32_t CreateArcSessionId();
  50. // Sets `arc_session_id` for `window_id`. `arc session id` is assigned when ARC
  51. // apps are restored.
  52. COMPONENT_EXPORT(APP_RESTORE)
  53. void SetArcSessionIdForWindowId(int32_t arc_session_id, int32_t window_id);
  54. // Associates `desk_template_launch_id` with `arc_session_id`.
  55. COMPONENT_EXPORT(APP_RESTORE)
  56. void SetDeskTemplateLaunchIdForArcSessionId(int32_t arc_session_id,
  57. int32_t desk_template_launch_id);
  58. // Returns the restore window id for the ARC app's `task_id`.
  59. COMPONENT_EXPORT(APP_RESTORE)
  60. int32_t GetArcRestoreWindowIdForTaskId(int32_t task_id);
  61. // Returns the restore window id for the ARC app's `session_id`.
  62. COMPONENT_EXPORT(APP_RESTORE)
  63. int32_t GetArcRestoreWindowIdForSessionId(int32_t session_id);
  64. // Remove the "_crx_" prefix from a given `app_name` to get the app id.
  65. COMPONENT_EXPORT(APP_RESTORE)
  66. std::string GetAppIdFromAppName(const std::string& app_name);
  67. // Returns the Lacros window id for `window`.
  68. const std::string GetLacrosWindowId(aura::Window* window);
  69. // Returns the restore window id for the Lacros window with `lacros_window_id`.
  70. COMPONENT_EXPORT(APP_RESTORE)
  71. int32_t GetLacrosRestoreWindowId(const std::string& lacros_window_id);
  72. } // namespace app_restore
  73. #endif // COMPONENTS_APP_RESTORE_APP_RESTORE_UTILS_H_