Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / ash / multi_user / multi_user_window_manager.h
blob2496ea52d60dd270879365505d0af3505064e5ac
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_
8 #include <map>
9 #include <set>
10 #include <string>
12 class Browser;
14 namespace content {
15 class BrowserContext;
18 namespace aura {
19 class Window;
22 namespace chrome {
24 class MultiUserWindowManagerChromeOS;
26 // The MultiUserWindowManager manages windows from multiple users by presenting
27 // only user relevant windows to the current user. The manager is automatically
28 // determining the window ownership from browser and application windows and
29 // puts them onto the correct "desktop".
30 // Un-owned windows will be visible on all users desktop's and owned windows can
31 // only be presented on one desktop. If a window should get moved to another
32 // user's desktop |ShowWindowForUser| can be called.
33 // Windows which are neither a browser nor an app can be associated with a user
34 // through |SetWindowOwner|.
35 // This class will also switch the desktop upon user change.
36 // Note:
37 // - There is no need to "unregister" a window from an owner. The class will
38 // clean automatically all references of that window upon destruction.
39 // - User changes will be tracked via observer. No need to call.
40 // - All child windows will be owned by the same owner as its parent.
41 class MultiUserWindowManager {
42 public:
43 // Observer to notify of any window owner changes.
44 class Observer {
45 public:
46 // Invoked when the new window is created and the manager start to track its
47 // owner.
48 virtual void OnOwnerEntryAdded(aura::Window* window) {}
49 // Invoked when the owner of the window tracked by the manager is changed.
50 virtual void OnOwnerEntryChanged(aura::Window* window) {}
51 // Invoked when the window is destroyed and the manager stop to track its
52 // owner.
53 virtual void OnOwnerEntryRemoved(aura::Window* window) {}
55 protected:
56 virtual ~Observer() {}
59 // The multi profile mode in use.
60 enum MultiProfileMode {
61 MULTI_PROFILE_MODE_UNINITIALIZED, // Not initialized yet.
62 MULTI_PROFILE_MODE_OFF, // Single user mode.
63 MULTI_PROFILE_MODE_SEPARATED, // Each user has his own desktop.
64 MULTI_PROFILE_MODE_MIXED // All users mix windows freely.
67 // Creates an instance of the MultiUserWindowManager.
68 // Note: This function might fail if due to the desired mode the
69 // MultiUserWindowManager is not required.
70 static MultiUserWindowManager* CreateInstance();
72 // Gets the instance of the object. If the multi profile mode is not enabled
73 // this will return NULL.
74 static MultiUserWindowManager* GetInstance();
76 // Return the current multi profile mode operation. If CreateInstance was not
77 // yet called (or was already destroyed), MULTI_PROFILE_MODE_UNINITIALIZED
78 // will get returned.
79 static MultiProfileMode GetMultiProfileMode();
81 // Whether or not the window's title should show the avatar. On chromeos,
82 // this is true when the owner of the window is different from the owner of
83 // the desktop.
84 static bool ShouldShowAvatar(aura::Window* window);
86 // Removes the instance.
87 static void DeleteInstance();
89 // A function to set an |instance| of a created MultiUserWinwdowManager object
90 // with a given |mode| for test purposes.
91 static void SetInstanceForTest(MultiUserWindowManager* instance,
92 MultiProfileMode mode);
94 // Assigns an owner to a passed window. Note that this window's parent should
95 // be a direct child of the root window.
96 // A user switch will automatically change the visibility - and - if the
97 // current user is not the owner it will immediately hidden. If the window
98 // had already be registered this function will run into a DCHECK violation.
99 virtual void SetWindowOwner(
100 aura::Window* window, const std::string& user_id) = 0;
102 // See who owns this window. The return value is the user id or an empty
103 // string if not assigned yet.
104 virtual const std::string& GetWindowOwner(aura::Window* window) const = 0;
106 // Allows to show an owned window for another users. If the window is not
107 // owned, this call will return immediately. (The FileManager for example
108 // might be available for every user and not belong explicitly to one).
109 // Note that a window can only be shown on one desktop at a time. Note that
110 // when the window gets minimized, it will automatically fall back to the
111 // owner's desktop.
112 virtual void ShowWindowForUser(
113 aura::Window* window, const std::string& user_id) = 0;
115 // Returns true when windows are shared among users.
116 virtual bool AreWindowsSharedAmongUsers() const = 0;
118 // Get the owners for the visible windows and set them to |user_ids|.
119 virtual void GetOwnersOfVisibleWindows(
120 std::set<std::string>* user_ids) const = 0;
122 // A query call for a given window to see if it is on the given user's
123 // desktop.
124 virtual bool IsWindowOnDesktopOfUser(aura::Window* window,
125 const std::string& user_id) const = 0;
127 // Get the user on which the window is currently shown. If an empty string is
128 // passed back the window will be presented for every user.
129 virtual const std::string& GetUserPresentingWindow(
130 aura::Window* window) const = 0;
132 // Adds user to monitor starting and running V1/V2 application windows.
133 // Returns immediately if the user (identified by a |profile|) is already
134 // known to the manager. Note: This function is not implemented as a
135 // SessionStateObserver to coordinate the timing of the addition with other
136 // modules.
137 virtual void AddUser(content::BrowserContext* profile) = 0;
139 // Manages observers.
140 virtual void AddObserver(Observer* observer) = 0;
141 virtual void RemoveObserver(Observer* observer) = 0;
143 protected:
144 virtual ~MultiUserWindowManager() {}
146 private:
147 // Caching the current multi profile mode since the detection is expensive.
148 static MultiProfileMode multi_user_mode_;
151 } // namespace chrome
153 #endif // CHROME_BROWSER_UI_ASH_MULTI_USER_MULTI_USER_WINDOW_MANAGER_H_