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. 4 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_ 7 8 #include <map> 9 #include <string> 10 11 class Browser; 12 class Profile; 13 14 namespace aura { 15 class Window; 16 } 17 18 namespace chrome { 19 20 class MultiUserWindowManagerChromeOS; 21 22 // The MultiUserWindowManager manages windows from multiple users by presenting 23 // only user relevant windows to the current user. The manager is automatically 24 // determining the window ownership from browser and application windows and 25 // puts them onto the correct "desktop". 26 // Un-owned windows will be visible on all users desktop's and owned windows can 27 // only be presented on one desktop. If a window should get moved to another 28 // user's desktop |ShowWindowForUser| can be called. 29 // Windows which are neither a browser nor an app can be associated with a user 30 // through |SetWindowOwner|. 31 // This class will also switch the desktop upon user change. 32 // Note: 33 // - There is no need to "unregister" a window from an owner. The class will 34 // clean automatically all references of that window upon destruction. 35 // - User changes will be tracked via observer. No need to call. 36 // - All child windows will be owned by the same owner as its parent. 37 class MultiUserWindowManager { 38 public: 39 // The multi profile mode in use. 40 enum MultiProfileMode { 41 MULTI_PROFILE_MODE_UNINITIALIZED, // Not initialized yet. 42 MULTI_PROFILE_MODE_OFF, // Single user mode. 43 MULTI_PROFILE_MODE_SEPARATED, // Each user has his own desktop. 44 MULTI_PROFILE_MODE_MIXED // All users mix windows freely. 45 }; 46 47 // Creates an instance of the MultiUserWindowManager. 48 // Note: This function might fail if due to the desired mode the 49 // MultiUserWindowManager is not required. 50 static MultiUserWindowManager* CreateInstance(); 51 52 // Gets the instance of the object. If the multi profile mode is not enabled 53 // this will return NULL. 54 static MultiUserWindowManager* GetInstance(); 55 56 // Return the current multi profile mode operation. If CreateInstance was not 57 // yet called (or was already destroyed), MULTI_PROFILE_MODE_UNINITIALIZED 58 // will get returned. 59 static MultiProfileMode GetMultiProfileMode(); 60 61 // Removes the instance. 62 static void DeleteInstance(); 63 64 // A function to set an |instance| of a created MultiUserWinwdowManager object 65 // with a given |mode| for test purposes. 66 static void SetInstanceForTest(MultiUserWindowManager* instance, 67 MultiProfileMode mode); 68 69 // Assigns an owner to a passed window. Note that this window's parent should 70 // be a direct child of the root window. 71 // A user switch will automatically change the visibility - and - if the 72 // current user is not the owner it will immediately hidden. If the window 73 // had already be registered this function will run into a DCHECK violation. 74 virtual void SetWindowOwner( 75 aura::Window* window, const std::string& user_id) = 0; 76 77 // See who owns this window. The return value is the user id or an empty 78 // string if not assigned yet. 79 virtual const std::string& GetWindowOwner(aura::Window* window) = 0; 80 81 // Allows to show an owned window for another users. If the window is not 82 // owned, this call will return immediately. (The FileManager for example 83 // might be available for every user and not belong explicitly to one). 84 // Note that a window can only be shown on one desktop at a time. Note that 85 // when the window gets minimized, it will automatically fall back to the 86 // owner's desktop. 87 virtual void ShowWindowForUser( 88 aura::Window* window, const std::string& user_id) = 0; 89 90 // Returns true when windows are shared among users. 91 virtual bool AreWindowsSharedAmongUsers() = 0; 92 93 // A query call for a given window to see if it is on the given user's 94 // desktop. 95 virtual bool IsWindowOnDesktopOfUser(aura::Window* window, 96 const std::string& user_id) = 0; 97 98 // Get the user on which the window is currently shown. If an empty string is 99 // passed back the window will be presented for every user. 100 virtual const std::string& GetUserPresentingWindow(aura::Window* window) = 0; 101 102 // Adds user to monitor starting and running V1/V2 application windows. 103 // Returns immediately if the user (identified by a |profile|) is already 104 // known to the manager. Note: This function is not implemented as a 105 // SessionStateObserver to coordinate the timing of the addition with other 106 // modules. 107 virtual void AddUser(Profile* profile) = 0; 108 109 protected: 110 virtual ~MultiUserWindowManager() {} 111 112 private: 113 // Caching the current multi profile mode since the detection is expensive. 114 static MultiProfileMode multi_user_mode_; 115 }; 116 117 } // namespace chrome 118 119 #endif // CHROME_BROWSER_UI_ASH_MULTI_USER_MULTI_USER_WINDOW_MANAGER_H_ 120