Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / ash / multi_user / multi_user_window_manager.h
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 <set>
10 #include <string>
11
12 class Browser;
13 class Profile;
14
15 namespace aura {
16 class Window;
17 }
18
19 namespace chrome {
20
21 class MultiUserWindowManagerChromeOS;
22
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.
33 // Note:
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 {
39  public:
40   // Observer to notify of any window owner changes.
41   class Observer {
42    public:
43     // Invoked when the new window is created and the manager start to track its
44     // owner.
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
49     // owner.
50     virtual void OnOwnerEntryRemoved(aura::Window* window) {}
51
52    protected:
53     virtual ~Observer() {}
54   };
55
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.
62   };
63
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();
68
69   // Gets the instance of the object. If the multi profile mode is not enabled
70   // this will return NULL.
71   static MultiUserWindowManager* GetInstance();
72
73   // Return the current multi profile mode operation. If CreateInstance was not
74   // yet called (or was already destroyed), MULTI_PROFILE_MODE_UNINITIALIZED
75   // will get returned.
76   static MultiProfileMode GetMultiProfileMode();
77
78   // Removes the instance.
79   static void DeleteInstance();
80
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);
85
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;
93
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;
97
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
103   // owner's desktop.
104   virtual void ShowWindowForUser(
105       aura::Window* window, const std::string& user_id) = 0;
106
107   // Returns true when windows are shared among users.
108   virtual bool AreWindowsSharedAmongUsers() = 0;
109
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;
112
113   // A query call for a given window to see if it is on the given user's
114   // desktop.
115   virtual bool IsWindowOnDesktopOfUser(aura::Window* window,
116                                        const std::string& user_id) = 0;
117
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;
121
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
126   // modules.
127   virtual void AddUser(Profile* profile) = 0;
128
129   // Manages observers.
130   virtual void AddObserver(Observer* observer) = 0;
131   virtual void RemoveObserver(Observer* observer) = 0;
132
133  protected:
134   virtual ~MultiUserWindowManager() {}
135
136  private:
137   // Caching the current multi profile mode since the detection is expensive.
138   static MultiProfileMode multi_user_mode_;
139 };
140
141 }  // namespace chrome
142
143 #endif  // CHROME_BROWSER_UI_ASH_MULTI_USER_MULTI_USER_WINDOW_MANAGER_H_