lacros_save_handler.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright 2022 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_LACROS_SAVE_HANDLER_H_
  5. #define COMPONENTS_APP_RESTORE_LACROS_SAVE_HANDLER_H_
  6. #include <map>
  7. #include "base/component_export.h"
  8. #include "base/files/file_path.h"
  9. namespace app_restore {
  10. struct WindowInfo;
  11. } // namespace app_restore
  12. namespace aura {
  13. class Window;
  14. } // namespace aura
  15. namespace full_restore {
  16. // LacrosSaveHandler is a helper class for FullRestoreSaveHandler to handle
  17. // Lacros windows special cases, e.g. Lacros window id, etc.
  18. class COMPONENT_EXPORT(APP_RESTORE) LacrosSaveHandler {
  19. public:
  20. explicit LacrosSaveHandler(const base::FilePath& profile_path);
  21. LacrosSaveHandler(const LacrosSaveHandler&) = delete;
  22. LacrosSaveHandler& operator=(const LacrosSaveHandler&) = delete;
  23. ~LacrosSaveHandler();
  24. // Invoked when `window` is initialized.
  25. void OnWindowInitialized(aura::Window* window);
  26. // Invoked when `window` is destroyed.
  27. void OnWindowDestroyed(aura::Window* window);
  28. // Invoked when Lacros browser window is created.
  29. void OnBrowserWindowAdded(aura::Window* const window, bool is_browser_app);
  30. // Invoked when an Chrome app Lacros window is created. `app_id` is the
  31. // AppService id, and `window_id` is the wayland app_id property for the
  32. // window.
  33. void OnAppWindowAdded(const std::string& app_id,
  34. const std::string& lacros_window_id);
  35. // Invoked when an Chrome app Lacros window is removed. `app_id` is the
  36. // AppService id, and `window_id` is the wayland app_id property for the
  37. // window.
  38. void OnAppWindowRemoved(const std::string& app_id,
  39. const std::string& lacros_window_id);
  40. // Saves `window_info`.
  41. void ModifyWindowInfo(const app_restore::WindowInfo& window_info);
  42. // Returns the app id that associates with `window`.
  43. std::string GetAppId(aura::Window* window);
  44. // Returns the window id that associates with `window` of a chrome app.
  45. // Returns -1 if the window is not in `window_candidates_`.
  46. int GetLacrosChromeAppWindowId(aura::Window* window) const;
  47. private:
  48. friend class FullRestoreSaveHandlerTestApi;
  49. struct WindowData {
  50. std::string app_id;
  51. uint32_t window_id = 0;
  52. };
  53. // The primary user profile path.
  54. base::FilePath profile_path_;
  55. // `window_id_` is used to record the current used window id. When a new
  56. // Lacros window is created, ++window_id to generate the new window id.
  57. uint32_t window_id_ = 0;
  58. // |window_candidates_| is used to record the map from the exo application id
  59. // to `app_id` and `window_id`. `app_id` might be changed for Chrome app
  60. // windows because the Lacros app id is set for all Lacros windows, and when
  61. // OnAppWindowAdded is called, `app_id` is modified to the Chrome app id. The
  62. // record is removed when the window is destroyed.
  63. std::map<std::string, WindowData> window_candidates_;
  64. // The map from the lacros window id to the app id for Chrome app windows.
  65. std::map<std::string, std::string> lacros_window_id_to_app_id_;
  66. };
  67. } // namespace full_restore
  68. #endif // COMPONENTS_APP_RESTORE_LACROS_SAVE_HANDLER_H_