| // Copyright 2021 The Chromium Authors. All rights reserved. | 
 | // Use of this source code is governed by a BSD-style license that can be | 
 | // found in the LICENSE file. | 
 |  | 
 | #ifndef CHROME_BROWSER_CHROMEOS_FULL_RESTORE_ARC_WINDOW_HANDLER_H_ | 
 | #define CHROME_BROWSER_CHROMEOS_FULL_RESTORE_ARC_WINDOW_HANDLER_H_ | 
 |  | 
 | #include "base/memory/weak_ptr.h" | 
 | #include "base/observer_list.h" | 
 | #include "base/observer_list_types.h" | 
 | #include "components/exo/client_controlled_shell_surface.h" | 
 | #include "components/exo/wm_helper.h" | 
 |  | 
 | namespace full_restore { | 
 | struct AppRestoreData; | 
 | } | 
 |  | 
 | namespace chromeos { | 
 | namespace full_restore { | 
 |  | 
 | // The ArcWindowHandler class provides control for ARC ghost window. | 
 | class ArcWindowHandler { | 
 |   // Map from window_session_id to exo::ClientControlledShellSurface. | 
 |   using ShellSurfaceMap = | 
 |       std::map<int, std::unique_ptr<exo::ClientControlledShellSurface>>; | 
 |  | 
 |   // This class populates the exo::ShellSurfaceBase to PropertyHandler by | 
 |   // the corresponding window session id. | 
 |   class WindowSessionResolver : public exo::WMHelper::AppPropertyResolver { | 
 |    public: | 
 |     explicit WindowSessionResolver(ShellSurfaceMap* session_id_map); | 
 |     WindowSessionResolver(const WindowSessionResolver&) = delete; | 
 |     WindowSessionResolver& operator=(const WindowSessionResolver&) = delete; | 
 |     ~WindowSessionResolver() override = default; | 
 |  | 
 |     // exo::WMHelper::AppPropertyResolver: | 
 |     void PopulateProperties( | 
 |         const Params& params, | 
 |         ui::PropertyHandler& out_properties_container) override; | 
 |  | 
 |    private: | 
 |     ShellSurfaceMap* session_id_map_; | 
 |   }; | 
 |  | 
 |  public: | 
 |   // This class is used to notify observers that AppInstance is connected. | 
 |   class Observer : public base::CheckedObserver { | 
 |    public: | 
 |     // Observer for app instance connection ready. | 
 |     virtual void OnAppInstanceConnected() {} | 
 |  | 
 |     // Observer for ghost window close event. | 
 |     virtual void OnWindowCloseRequested(int window_id) {} | 
 |  | 
 |    protected: | 
 |     ~Observer() override = default; | 
 |   }; | 
 |  | 
 |   ArcWindowHandler(); | 
 |   ArcWindowHandler(const ArcWindowHandler&) = delete; | 
 |   ArcWindowHandler& operator=(const ArcWindowHandler&) = delete; | 
 |   ~ArcWindowHandler(); | 
 |  | 
 |   void LaunchArcGhostWindow(const std::string& app_id, | 
 |                             int32_t session_id, | 
 |                             ::full_restore::AppRestoreData* restore_data); | 
 |  | 
 |   void CloseWindow(int session_id); | 
 |  | 
 |   void AddObserver(Observer* observer); | 
 |   void RemoveObserver(Observer* observer); | 
 |   bool HasObserver(Observer* observer); | 
 |  | 
 |   void OnAppInstanceConnected(); | 
 |  | 
 |  private: | 
 |   // Map window session id to ClientControlledShellSurface. | 
 |   ShellSurfaceMap session_id_to_shell_surface_; | 
 |  | 
 |   base::ObserverList<Observer> observer_list_; | 
 |  | 
 |   base::WeakPtrFactory<ArcWindowHandler> weak_ptr_factory_{this}; | 
 | }; | 
 |  | 
 | }  // namespace full_restore | 
 | }  // namespace chromeos | 
 |  | 
 | #endif  // CHROME_BROWSER_CHROMEOS_FULL_RESTORE_ARC_WINDOW_HANDLER_H_ |