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 // The multi profile mode in use.
41 enum MultiProfileMode
{
42 MULTI_PROFILE_MODE_UNINITIALIZED
, // Not initialized yet.
43 MULTI_PROFILE_MODE_OFF
, // Single user mode.
44 MULTI_PROFILE_MODE_SEPARATED
, // Each user has his own desktop.
45 MULTI_PROFILE_MODE_MIXED
// All users mix windows freely.
48 // Creates an instance of the MultiUserWindowManager.
49 // Note: This function might fail if due to the desired mode the
50 // MultiUserWindowManager is not required.
51 static MultiUserWindowManager
* CreateInstance();
53 // Gets the instance of the object. If the multi profile mode is not enabled
54 // this will return NULL.
55 static MultiUserWindowManager
* GetInstance();
57 // Return the current multi profile mode operation. If CreateInstance was not
58 // yet called (or was already destroyed), MULTI_PROFILE_MODE_UNINITIALIZED
60 static MultiProfileMode
GetMultiProfileMode();
62 // Removes the instance.
63 static void DeleteInstance();
65 // A function to set an |instance| of a created MultiUserWinwdowManager object
66 // with a given |mode| for test purposes.
67 static void SetInstanceForTest(MultiUserWindowManager
* instance
,
68 MultiProfileMode mode
);
70 // Assigns an owner to a passed window. Note that this window's parent should
71 // be a direct child of the root window.
72 // A user switch will automatically change the visibility - and - if the
73 // current user is not the owner it will immediately hidden. If the window
74 // had already be registered this function will run into a DCHECK violation.
75 virtual void SetWindowOwner(
76 aura::Window
* window
, const std::string
& user_id
) = 0;
78 // See who owns this window. The return value is the user id or an empty
79 // string if not assigned yet.
80 virtual const std::string
& GetWindowOwner(aura::Window
* window
) = 0;
82 // Allows to show an owned window for another users. If the window is not
83 // owned, this call will return immediately. (The FileManager for example
84 // might be available for every user and not belong explicitly to one).
85 // Note that a window can only be shown on one desktop at a time. Note that
86 // when the window gets minimized, it will automatically fall back to the
88 virtual void ShowWindowForUser(
89 aura::Window
* window
, const std::string
& user_id
) = 0;
91 // Returns true when windows are shared among users.
92 virtual bool AreWindowsSharedAmongUsers() = 0;
94 // Get the owners for the visible windows and set them to |user_ids|.
95 virtual void GetOwnersOfVisibleWindows(std::set
<std::string
>* user_ids
) = 0;
97 // A query call for a given window to see if it is on the given user's
99 virtual bool IsWindowOnDesktopOfUser(aura::Window
* window
,
100 const std::string
& user_id
) = 0;
102 // Get the user on which the window is currently shown. If an empty string is
103 // passed back the window will be presented for every user.
104 virtual const std::string
& GetUserPresentingWindow(aura::Window
* window
) = 0;
106 // Adds user to monitor starting and running V1/V2 application windows.
107 // Returns immediately if the user (identified by a |profile|) is already
108 // known to the manager. Note: This function is not implemented as a
109 // SessionStateObserver to coordinate the timing of the addition with other
111 virtual void AddUser(Profile
* profile
) = 0;
114 virtual ~MultiUserWindowManager() {}
117 // Caching the current multi profile mode since the detection is expensive.
118 static MultiProfileMode multi_user_mode_
;
121 } // namespace chrome
123 #endif // CHROME_BROWSER_UI_ASH_MULTI_USER_MULTI_USER_WINDOW_MANAGER_H_