Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / webui / foreign_session_handler.h
blob81e96ab9ed415f823fca28a991a0e2fbf17a506e
1 // Copyright 2012 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_WEBUI_FOREIGN_SESSION_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_FOREIGN_SESSION_HANDLER_H_
8 #include <vector>
10 #include "base/time/time.h"
11 #include "chrome/browser/sessions/session_service.h"
12 #include "chrome/browser/sync/open_tabs_ui_delegate.h"
13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h"
15 #include "content/public/browser/web_ui.h"
16 #include "content/public/browser/web_ui_message_handler.h"
18 namespace sessions {
19 struct SessionTab;
20 struct SessionWindow;
23 namespace user_prefs {
24 class PrefRegistrySyncable;
27 namespace browser_sync {
29 class ForeignSessionHandler : public content::WebUIMessageHandler,
30 public content::NotificationObserver {
31 public:
32 // Invalid value, used to note that we don't have a tab or window number.
33 static const int kInvalidId = -1;
35 // WebUIMessageHandler implementation.
36 void RegisterMessages() override;
38 ForeignSessionHandler();
39 ~ForeignSessionHandler() override {}
41 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
43 static void OpenForeignSessionTab(content::WebUI* web_ui,
44 const std::string& session_string_value,
45 SessionID::id_type window_num,
46 SessionID::id_type tab_id,
47 const WindowOpenDisposition& disposition);
49 static void OpenForeignSessionWindows(content::WebUI* web_ui,
50 const std::string& session_string_value,
51 SessionID::id_type window_num);
53 // Helper method to create JSON compatible objects from Session objects.
54 static bool SessionTabToValue(const ::sessions::SessionTab& tab,
55 base::DictionaryValue* dictionary);
57 // Returns a pointer to the current session model associator or NULL.
58 static OpenTabsUIDelegate* GetOpenTabsUIDelegate(content::WebUI* web_ui);
60 private:
61 // Determines how ForeignSessionHandler will interact with the new tab page.
62 void Observe(int type,
63 const content::NotificationSource& source,
64 const content::NotificationDetails& details) override;
66 // Returns true if tab sync is enabled for this profile, otherwise false.
67 bool IsTabSyncEnabled();
69 // Returns a string used to show the user when a session was last modified.
70 base::string16 FormatSessionTime(const base::Time& time);
72 // Determines which session is to be opened, and then calls
73 // OpenForeignSession, to begin the process of opening a new browser window.
74 // This is a javascript callback handler.
75 void HandleOpenForeignSession(const base::ListValue* args);
77 // Determines whether foreign sessions should be obtained from the sync model.
78 // This is a javascript callback handler, and it is also called when the sync
79 // model has changed and the new tab page needs to reflect the changes.
80 void HandleGetForeignSessions(const base::ListValue* args);
82 // Delete a foreign session. This will remove it from the list of foreign
83 // sessions on all devices. It will reappear if the session is re-activated
84 // on the original device.
85 // This is a javascript callback handler.
86 void HandleDeleteForeignSession(const base::ListValue* args);
88 void HandleSetForeignSessionCollapsed(const base::ListValue* args);
90 // Helper method to create JSON compatible objects from Session objects.
91 bool SessionWindowToValue(const ::sessions::SessionWindow& window,
92 base::DictionaryValue* dictionary);
94 // The Registrar used to register ForeignSessionHandler for notifications.
95 content::NotificationRegistrar registrar_;
97 DISALLOW_COPY_AND_ASSIGN(ForeignSessionHandler);
100 } // namespace browser_sync
102 #endif // CHROME_BROWSER_UI_WEBUI_FOREIGN_SESSION_HANDLER_H_