1 // Copyright 2013 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.
5 #ifndef CHROME_BROWSER_UI_ASH_MULTI_USER_MULTI_USER_WINDOW_MANAGER_H_
6 #define CHROME_BROWSER_UI_ASH_MULTI_USER_MULTI_USER_WINDOW_MANAGER_H_
21 class MultiUserWindowManagerChromeOS;
23 // The MultiUserWindowManager manages windows from multiple users by presenting
24 // only user relevant windows to the current user. The manager is automatically
25 // determining the window ownership from browser and application windows and
26 // puts them onto the correct "desktop".
27 // Un-owned windows will be visible on all users desktop's and owned windows can
28 // only be presented on one desktop. If a window should get moved to another
29 // user's desktop |ShowWindowForUser| can be called.
30 // Windows which are neither a browser nor an app can be associated with a user
31 // through |SetWindowOwner|.
32 // This class will also switch the desktop upon user change.
34 // - There is no need to "unregister" a window from an owner. The class will
35 // clean automatically all references of that window upon destruction.
36 // - User changes will be tracked via observer. No need to call.
37 // - All child windows will be owned by the same owner as its parent.
38 class MultiUserWindowManager {
40 // Observer to notify of any window owner changes.
43 // Invoked when the new window is created and the manager start to track its
45 virtual void OnOwnerEntryAdded(aura::Window* window) {}
46 // Invoked when the owner of the window tracked by the manager is changed.
47 virtual void OnOwnerEntryChanged(aura::Window* window) {}
48 // Invoked when the window is destroyed and the manager stop to track its
50 virtual void OnOwnerEntryRemoved(aura::Window* window) {}
53 virtual ~Observer() {}
56 // The multi profile mode in use.
57 enum MultiProfileMode {
58 MULTI_PROFILE_MODE_UNINITIALIZED, // Not initialized yet.
59 MULTI_PROFILE_MODE_OFF, // Single user mode.
60 MULTI_PROFILE_MODE_SEPARATED, // Each user has his own desktop.
61 MULTI_PROFILE_MODE_MIXED // All users mix windows freely.
64 // Creates an instance of the MultiUserWindowManager.
65 // Note: This function might fail if due to the desired mode the
66 // MultiUserWindowManager is not required.
67 static MultiUserWindowManager* CreateInstance();
69 // Gets the instance of the object. If the multi profile mode is not enabled
70 // this will return NULL.
71 static MultiUserWindowManager* GetInstance();
73 // Return the current multi profile mode operation. If CreateInstance was not
74 // yet called (or was already destroyed), MULTI_PROFILE_MODE_UNINITIALIZED
76 static MultiProfileMode GetMultiProfileMode();
78 // Removes the instance.
79 static void DeleteInstance();
81 // A function to set an |instance| of a created MultiUserWinwdowManager object
82 // with a given |mode| for test purposes.
83 static void SetInstanceForTest(MultiUserWindowManager* instance,
84 MultiProfileMode mode);
86 // Assigns an owner to a passed window. Note that this window's parent should
87 // be a direct child of the root window.
88 // A user switch will automatically change the visibility - and - if the
89 // current user is not the owner it will immediately hidden. If the window
90 // had already be registered this function will run into a DCHECK violation.
91 virtual void SetWindowOwner(
92 aura::Window* window, const std::string& user_id) = 0;
94 // See who owns this window. The return value is the user id or an empty
95 // string if not assigned yet.
96 virtual const std::string& GetWindowOwner(aura::Window* window) = 0;
98 // Allows to show an owned window for another users. If the window is not
99 // owned, this call will return immediately. (The FileManager for example
100 // might be available for every user and not belong explicitly to one).
101 // Note that a window can only be shown on one desktop at a time. Note that
102 // when the window gets minimized, it will automatically fall back to the
104 virtual void ShowWindowForUser(
105 aura::Window* window, const std::string& user_id) = 0;
107 // Returns true when windows are shared among users.
108 virtual bool AreWindowsSharedAmongUsers() = 0;
110 // Get the owners for the visible windows and set them to |user_ids|.
111 virtual void GetOwnersOfVisibleWindows(std::set<std::string>* user_ids) = 0;
113 // A query call for a given window to see if it is on the given user's
115 virtual bool IsWindowOnDesktopOfUser(aura::Window* window,
116 const std::string& user_id) = 0;
118 // Get the user on which the window is currently shown. If an empty string is
119 // passed back the window will be presented for every user.
120 virtual const std::string& GetUserPresentingWindow(aura::Window* window) = 0;
122 // Adds user to monitor starting and running V1/V2 application windows.
123 // Returns immediately if the user (identified by a |profile|) is already
124 // known to the manager. Note: This function is not implemented as a
125 // SessionStateObserver to coordinate the timing of the addition with other
127 virtual void AddUser(Profile* profile) = 0;
129 // Manages observers.
130 virtual void AddObserver(Observer* observer) = 0;
131 virtual void RemoveObserver(Observer* observer) = 0;
134 virtual ~MultiUserWindowManager() {}
137 // Caching the current multi profile mode since the detection is expensive.
138 static MultiProfileMode multi_user_mode_;
141 } // namespace chrome
143 #endif // CHROME_BROWSER_UI_ASH_MULTI_USER_MULTI_USER_WINDOW_MANAGER_H_