OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_WEBUI_FOREIGN_SESSION_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_FOREIGN_SESSION_HANDLER_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_FOREIGN_SESSION_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_FOREIGN_SESSION_HANDLER_H_ |
7 | 7 |
8 #include <string> | |
9 #include <vector> | 8 #include <vector> |
10 | 9 |
11 #include "base/macros.h" | 10 #include "base/macros.h" |
12 #include "base/scoped_observer.h" | 11 #include "base/scoped_observer.h" |
13 #include "base/time/time.h" | 12 #include "base/time/time.h" |
14 #include "chrome/browser/sessions/session_service.h" | 13 #include "chrome/browser/sessions/session_service.h" |
15 #include "components/sync/driver/sync_service_observer.h" | 14 #include "components/sync/driver/sync_service_observer.h" |
16 #include "components/sync_sessions/open_tabs_ui_delegate.h" | 15 #include "components/sync_sessions/open_tabs_ui_delegate.h" |
17 #include "content/public/browser/web_ui.h" | 16 #include "content/public/browser/web_ui.h" |
18 #include "content/public/browser/web_ui_message_handler.h" | 17 #include "content/public/browser/web_ui_message_handler.h" |
19 | 18 |
20 namespace sessions { | 19 namespace sessions { |
21 struct SessionTab; | 20 struct SessionTab; |
22 struct SessionWindow; | 21 struct SessionWindow; |
23 } | 22 } |
24 | 23 |
25 namespace syncer { | 24 namespace sync_driver { |
26 class SyncService; | 25 class SyncService; |
27 } | 26 } |
28 | 27 |
29 namespace user_prefs { | 28 namespace user_prefs { |
30 class PrefRegistrySyncable; | 29 class PrefRegistrySyncable; |
31 } | 30 } |
32 | 31 |
33 namespace browser_sync { | 32 namespace browser_sync { |
34 | 33 |
35 class ForeignSessionHandler : public content::WebUIMessageHandler, | 34 class ForeignSessionHandler : public content::WebUIMessageHandler, |
36 public syncer::SyncServiceObserver { | 35 public sync_driver::SyncServiceObserver { |
37 public: | 36 public: |
38 // Invalid value, used to note that we don't have a tab or window number. | 37 // Invalid value, used to note that we don't have a tab or window number. |
39 static const int kInvalidId = -1; | 38 static const int kInvalidId = -1; |
40 | 39 |
41 // WebUIMessageHandler implementation. | 40 // WebUIMessageHandler implementation. |
42 void RegisterMessages() override; | 41 void RegisterMessages() override; |
43 | 42 |
44 ForeignSessionHandler(); | 43 ForeignSessionHandler(); |
45 ~ForeignSessionHandler() override; | 44 ~ForeignSessionHandler() override; |
46 | 45 |
47 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 46 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
48 | 47 |
49 static void OpenForeignSessionTab(content::WebUI* web_ui, | 48 static void OpenForeignSessionTab(content::WebUI* web_ui, |
50 const std::string& session_string_value, | 49 const std::string& session_string_value, |
51 SessionID::id_type window_num, | 50 SessionID::id_type window_num, |
52 SessionID::id_type tab_id, | 51 SessionID::id_type tab_id, |
53 const WindowOpenDisposition& disposition); | 52 const WindowOpenDisposition& disposition); |
54 | 53 |
55 static void OpenForeignSessionWindows(content::WebUI* web_ui, | 54 static void OpenForeignSessionWindows(content::WebUI* web_ui, |
56 const std::string& session_string_value, | 55 const std::string& session_string_value, |
57 SessionID::id_type window_num); | 56 SessionID::id_type window_num); |
58 | 57 |
59 // Returns a pointer to the current session model associator or NULL. | 58 // Returns a pointer to the current session model associator or NULL. |
60 static sync_sessions::OpenTabsUIDelegate* GetOpenTabsUIDelegate( | 59 static sync_sessions::OpenTabsUIDelegate* GetOpenTabsUIDelegate( |
61 content::WebUI* web_ui); | 60 content::WebUI* web_ui); |
62 | 61 |
63 private: | 62 private: |
64 // syncer::SyncServiceObserver: | 63 // sync_driver::SyncServiceObserver: |
65 void OnStateChanged() override {} | 64 void OnStateChanged() override {} |
66 void OnSyncConfigurationCompleted() override; | 65 void OnSyncConfigurationCompleted() override; |
67 void OnForeignSessionUpdated() override; | 66 void OnForeignSessionUpdated() override; |
68 | 67 |
69 // Returns true if tab sync is enabled for this profile, otherwise false. | 68 // Returns true if tab sync is enabled for this profile, otherwise false. |
70 bool IsTabSyncEnabled(); | 69 bool IsTabSyncEnabled(); |
71 | 70 |
72 // Returns a string used to show the user when a session was last modified. | 71 // Returns a string used to show the user when a session was last modified. |
73 base::string16 FormatSessionTime(const base::Time& time); | 72 base::string16 FormatSessionTime(const base::Time& time); |
74 | 73 |
75 // Determines which session is to be opened, and then calls | 74 // Determines which session is to be opened, and then calls |
76 // OpenForeignSession, to begin the process of opening a new browser window. | 75 // OpenForeignSession, to begin the process of opening a new browser window. |
77 // This is a javascript callback handler. | 76 // This is a javascript callback handler. |
78 void HandleOpenForeignSession(const base::ListValue* args); | 77 void HandleOpenForeignSession(const base::ListValue* args); |
79 | 78 |
80 // Determines whether foreign sessions should be obtained from the sync model. | 79 // Determines whether foreign sessions should be obtained from the sync model. |
81 // This is a javascript callback handler, and it is also called when the sync | 80 // This is a javascript callback handler, and it is also called when the sync |
82 // model has changed and the new tab page needs to reflect the changes. | 81 // model has changed and the new tab page needs to reflect the changes. |
83 void HandleGetForeignSessions(const base::ListValue* args); | 82 void HandleGetForeignSessions(const base::ListValue* args); |
84 | 83 |
85 // Delete a foreign session. This will remove it from the list of foreign | 84 // Delete a foreign session. This will remove it from the list of foreign |
86 // sessions on all devices. It will reappear if the session is re-activated | 85 // sessions on all devices. It will reappear if the session is re-activated |
87 // on the original device. | 86 // on the original device. |
88 // This is a javascript callback handler. | 87 // This is a javascript callback handler. |
89 void HandleDeleteForeignSession(const base::ListValue* args); | 88 void HandleDeleteForeignSession(const base::ListValue* args); |
90 | 89 |
91 void HandleSetForeignSessionCollapsed(const base::ListValue* args); | 90 void HandleSetForeignSessionCollapsed(const base::ListValue* args); |
92 | 91 |
93 // ScopedObserver used to observe the ProfileSyncService. | 92 // ScopedObserver used to observe the ProfileSyncService. |
94 ScopedObserver<syncer::SyncService, syncer::SyncServiceObserver> | 93 ScopedObserver<sync_driver::SyncService, sync_driver::SyncServiceObserver> |
95 scoped_observer_; | 94 scoped_observer_; |
96 | 95 |
97 // The time at which this WebUI was created. Used to calculate how long | 96 // The time at which this WebUI was created. Used to calculate how long |
98 // the WebUI was present before the sessions data was visible. | 97 // the WebUI was present before the sessions data was visible. |
99 base::TimeTicks load_attempt_time_; | 98 base::TimeTicks load_attempt_time_; |
100 | 99 |
101 DISALLOW_COPY_AND_ASSIGN(ForeignSessionHandler); | 100 DISALLOW_COPY_AND_ASSIGN(ForeignSessionHandler); |
102 }; | 101 }; |
103 | 102 |
104 } // namespace browser_sync | 103 } // namespace browser_sync |
105 | 104 |
106 #endif // CHROME_BROWSER_UI_WEBUI_FOREIGN_SESSION_HANDLER_H_ | 105 #endif // CHROME_BROWSER_UI_WEBUI_FOREIGN_SESSION_HANDLER_H_ |
OLD | NEW |