Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(477)

Side by Side Diff: chrome/browser/ui/webui/foreign_session_handler.h

Issue 1406943004: [sync] Isolate FOREIGN_SESSION_UPDATED notification in ProfileSyncService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <vector> 8 #include <vector>
9 9
10 #include "base/scoped_observer.h" 10 #include "base/scoped_observer.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "chrome/browser/sessions/session_service.h" 12 #include "chrome/browser/sessions/session_service.h"
13 #include "components/sync_driver/open_tabs_ui_delegate.h" 13 #include "components/sync_driver/open_tabs_ui_delegate.h"
14 #include "components/sync_driver/sync_service_observer.h" 14 #include "components/sync_driver/sync_service_observer.h"
15 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h"
17 #include "content/public/browser/web_ui.h" 15 #include "content/public/browser/web_ui.h"
18 #include "content/public/browser/web_ui_message_handler.h" 16 #include "content/public/browser/web_ui_message_handler.h"
19 17
20 namespace sessions { 18 namespace sessions {
21 struct SessionTab; 19 struct SessionTab;
22 struct SessionWindow; 20 struct SessionWindow;
23 } 21 }
24 22
25 namespace sync_driver { 23 namespace sync_driver {
26 class SyncService; 24 class SyncService;
27 } 25 }
28 26
29 namespace user_prefs { 27 namespace user_prefs {
30 class PrefRegistrySyncable; 28 class PrefRegistrySyncable;
31 } 29 }
32 30
33 namespace browser_sync { 31 namespace browser_sync {
34 32
35 class ForeignSessionHandler : public content::WebUIMessageHandler, 33 class ForeignSessionHandler : public content::WebUIMessageHandler,
36 public content::NotificationObserver,
37 public sync_driver::SyncServiceObserver { 34 public sync_driver::SyncServiceObserver {
38 public: 35 public:
39 // Invalid value, used to note that we don't have a tab or window number. 36 // Invalid value, used to note that we don't have a tab or window number.
40 static const int kInvalidId = -1; 37 static const int kInvalidId = -1;
41 38
42 // WebUIMessageHandler implementation. 39 // WebUIMessageHandler implementation.
43 void RegisterMessages() override; 40 void RegisterMessages() override;
44 41
45 ForeignSessionHandler(); 42 ForeignSessionHandler();
46 ~ForeignSessionHandler() override; 43 ~ForeignSessionHandler() override;
47 44
48 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 45 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
49 46
50 static void OpenForeignSessionTab(content::WebUI* web_ui, 47 static void OpenForeignSessionTab(content::WebUI* web_ui,
51 const std::string& session_string_value, 48 const std::string& session_string_value,
52 SessionID::id_type window_num, 49 SessionID::id_type window_num,
53 SessionID::id_type tab_id, 50 SessionID::id_type tab_id,
54 const WindowOpenDisposition& disposition); 51 const WindowOpenDisposition& disposition);
55 52
56 static void OpenForeignSessionWindows(content::WebUI* web_ui, 53 static void OpenForeignSessionWindows(content::WebUI* web_ui,
57 const std::string& session_string_value, 54 const std::string& session_string_value,
58 SessionID::id_type window_num); 55 SessionID::id_type window_num);
59 56
60 // Returns a pointer to the current session model associator or NULL. 57 // Returns a pointer to the current session model associator or NULL.
61 static sync_driver::OpenTabsUIDelegate* GetOpenTabsUIDelegate( 58 static sync_driver::OpenTabsUIDelegate* GetOpenTabsUIDelegate(
62 content::WebUI* web_ui); 59 content::WebUI* web_ui);
63 60
64 private: 61 private:
65 // Determines how ForeignSessionHandler will interact with the new tab page.
66 void Observe(int type,
67 const content::NotificationSource& source,
68 const content::NotificationDetails& details) override;
69
70 // sync_driver::SyncServiceObserver: 62 // sync_driver::SyncServiceObserver:
71 void OnStateChanged() override {} 63 void OnStateChanged() override {}
72 void OnSyncConfigurationCompleted() override; 64 void OnSyncConfigurationCompleted() override;
65 void OnForeignSessionUpdated() override;
73 66
74 // Returns true if tab sync is enabled for this profile, otherwise false. 67 // Returns true if tab sync is enabled for this profile, otherwise false.
75 bool IsTabSyncEnabled(); 68 bool IsTabSyncEnabled();
76 69
77 // Returns a string used to show the user when a session was last modified. 70 // Returns a string used to show the user when a session was last modified.
78 base::string16 FormatSessionTime(const base::Time& time); 71 base::string16 FormatSessionTime(const base::Time& time);
79 72
80 // Determines which session is to be opened, and then calls 73 // Determines which session is to be opened, and then calls
81 // OpenForeignSession, to begin the process of opening a new browser window. 74 // OpenForeignSession, to begin the process of opening a new browser window.
82 // This is a javascript callback handler. 75 // This is a javascript callback handler.
83 void HandleOpenForeignSession(const base::ListValue* args); 76 void HandleOpenForeignSession(const base::ListValue* args);
84 77
85 // Determines whether foreign sessions should be obtained from the sync model. 78 // Determines whether foreign sessions should be obtained from the sync model.
86 // This is a javascript callback handler, and it is also called when the sync 79 // This is a javascript callback handler, and it is also called when the sync
87 // model has changed and the new tab page needs to reflect the changes. 80 // model has changed and the new tab page needs to reflect the changes.
88 void HandleGetForeignSessions(const base::ListValue* args); 81 void HandleGetForeignSessions(const base::ListValue* args);
89 82
90 // Delete a foreign session. This will remove it from the list of foreign 83 // Delete a foreign session. This will remove it from the list of foreign
91 // sessions on all devices. It will reappear if the session is re-activated 84 // sessions on all devices. It will reappear if the session is re-activated
92 // on the original device. 85 // on the original device.
93 // This is a javascript callback handler. 86 // This is a javascript callback handler.
94 void HandleDeleteForeignSession(const base::ListValue* args); 87 void HandleDeleteForeignSession(const base::ListValue* args);
95 88
96 void HandleSetForeignSessionCollapsed(const base::ListValue* args); 89 void HandleSetForeignSessionCollapsed(const base::ListValue* args);
97 90
98 // The Registrar used to register ForeignSessionHandler for notifications.
99 content::NotificationRegistrar registrar_;
100
101 // ScopedObserver used to observe the ProfileSyncService. 91 // ScopedObserver used to observe the ProfileSyncService.
102 ScopedObserver<sync_driver::SyncService, sync_driver::SyncServiceObserver> 92 ScopedObserver<sync_driver::SyncService, sync_driver::SyncServiceObserver>
103 scoped_observer_; 93 scoped_observer_;
104 94
105 // The time at which this WebUI was created. Used to calculate how long 95 // The time at which this WebUI was created. Used to calculate how long
106 // the WebUI was present before the sessions data was visible. 96 // the WebUI was present before the sessions data was visible.
107 base::TimeTicks load_attempt_time_; 97 base::TimeTicks load_attempt_time_;
108 98
109 DISALLOW_COPY_AND_ASSIGN(ForeignSessionHandler); 99 DISALLOW_COPY_AND_ASSIGN(ForeignSessionHandler);
110 }; 100 };
111 101
112 } // namespace browser_sync 102 } // namespace browser_sync
113 103
114 #endif // CHROME_BROWSER_UI_WEBUI_FOREIGN_SESSION_HANDLER_H_ 104 #endif // CHROME_BROWSER_UI_WEBUI_FOREIGN_SESSION_HANDLER_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service.cc ('k') | chrome/browser/ui/webui/foreign_session_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698