Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / webui / foreign_session_handler.h
blob9ae4212f612b81f4d9f72211ec03b57b287e0450
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 "components/sync_driver/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 // Returns a pointer to the current session model associator or NULL.
54 static sync_driver::OpenTabsUIDelegate* GetOpenTabsUIDelegate(
55 content::WebUI* web_ui);
57 private:
58 // Determines how ForeignSessionHandler will interact with the new tab page.
59 void Observe(int type,
60 const content::NotificationSource& source,
61 const content::NotificationDetails& details) override;
63 // Returns true if tab sync is enabled for this profile, otherwise false.
64 bool IsTabSyncEnabled();
66 // Returns a string used to show the user when a session was last modified.
67 base::string16 FormatSessionTime(const base::Time& time);
69 // Determines which session is to be opened, and then calls
70 // OpenForeignSession, to begin the process of opening a new browser window.
71 // This is a javascript callback handler.
72 void HandleOpenForeignSession(const base::ListValue* args);
74 // Determines whether foreign sessions should be obtained from the sync model.
75 // This is a javascript callback handler, and it is also called when the sync
76 // model has changed and the new tab page needs to reflect the changes.
77 void HandleGetForeignSessions(const base::ListValue* args);
79 // Delete a foreign session. This will remove it from the list of foreign
80 // sessions on all devices. It will reappear if the session is re-activated
81 // on the original device.
82 // This is a javascript callback handler.
83 void HandleDeleteForeignSession(const base::ListValue* args);
85 void HandleSetForeignSessionCollapsed(const base::ListValue* args);
87 // The Registrar used to register ForeignSessionHandler for notifications.
88 content::NotificationRegistrar registrar_;
90 // The time at which this WebUI was created. Used to calculate how long
91 // the WebUI was present before the sessions data was visible.
92 base::TimeTicks load_attempt_time_;
94 DISALLOW_COPY_AND_ASSIGN(ForeignSessionHandler);
97 } // namespace browser_sync
99 #endif // CHROME_BROWSER_UI_WEBUI_FOREIGN_SESSION_HANDLER_H_