OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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_EXTENSIONS_API_SESSIONS_SESSIONS_API_H__ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SESSIONS_SESSIONS_API_H__ |
6 #define CHROME_BROWSER_EXTENSIONS_API_SESSIONS_SESSIONS_API_H__ | 6 #define CHROME_BROWSER_EXTENSIONS_API_SESSIONS_SESSIONS_API_H__ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "chrome/browser/extensions/chrome_extension_function.h" | 10 #include "chrome/browser/extensions/chrome_extension_function.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 struct SyncedSession; | 22 struct SyncedSession; |
23 } | 23 } |
24 | 24 |
25 namespace extensions { | 25 namespace extensions { |
26 | 26 |
27 class SessionId; | 27 class SessionId; |
28 | 28 |
29 class SessionsGetRecentlyClosedFunction : public ChromeSyncExtensionFunction { | 29 class SessionsGetRecentlyClosedFunction : public ChromeSyncExtensionFunction { |
30 protected: | 30 protected: |
31 virtual ~SessionsGetRecentlyClosedFunction() {} | 31 virtual ~SessionsGetRecentlyClosedFunction() {} |
32 virtual bool RunSync() OVERRIDE; | 32 virtual bool RunSync() override; |
33 DECLARE_EXTENSION_FUNCTION("sessions.getRecentlyClosed", | 33 DECLARE_EXTENSION_FUNCTION("sessions.getRecentlyClosed", |
34 SESSIONS_GETRECENTLYCLOSED) | 34 SESSIONS_GETRECENTLYCLOSED) |
35 | 35 |
36 private: | 36 private: |
37 scoped_ptr<api::tabs::Tab> CreateTabModel(const TabRestoreService::Tab& tab, | 37 scoped_ptr<api::tabs::Tab> CreateTabModel(const TabRestoreService::Tab& tab, |
38 int session_id, | 38 int session_id, |
39 int selected_index); | 39 int selected_index); |
40 scoped_ptr<api::windows::Window> CreateWindowModel( | 40 scoped_ptr<api::windows::Window> CreateWindowModel( |
41 const TabRestoreService::Window& window, | 41 const TabRestoreService::Window& window, |
42 int session_id); | 42 int session_id); |
43 scoped_ptr<api::sessions::Session> CreateSessionModel( | 43 scoped_ptr<api::sessions::Session> CreateSessionModel( |
44 const TabRestoreService::Entry* entry); | 44 const TabRestoreService::Entry* entry); |
45 }; | 45 }; |
46 | 46 |
47 class SessionsGetDevicesFunction : public ChromeSyncExtensionFunction { | 47 class SessionsGetDevicesFunction : public ChromeSyncExtensionFunction { |
48 protected: | 48 protected: |
49 virtual ~SessionsGetDevicesFunction() {} | 49 virtual ~SessionsGetDevicesFunction() {} |
50 virtual bool RunSync() OVERRIDE; | 50 virtual bool RunSync() override; |
51 DECLARE_EXTENSION_FUNCTION("sessions.getDevices", SESSIONS_GETDEVICES) | 51 DECLARE_EXTENSION_FUNCTION("sessions.getDevices", SESSIONS_GETDEVICES) |
52 | 52 |
53 private: | 53 private: |
54 scoped_ptr<api::tabs::Tab> CreateTabModel(const std::string& session_tag, | 54 scoped_ptr<api::tabs::Tab> CreateTabModel(const std::string& session_tag, |
55 const SessionTab& tab, | 55 const SessionTab& tab, |
56 int tab_index, | 56 int tab_index, |
57 int selected_index); | 57 int selected_index); |
58 scoped_ptr<api::windows::Window> CreateWindowModel( | 58 scoped_ptr<api::windows::Window> CreateWindowModel( |
59 const SessionWindow& window, | 59 const SessionWindow& window, |
60 const std::string& session_tag); | 60 const std::string& session_tag); |
61 scoped_ptr<api::sessions::Session> CreateSessionModel( | 61 scoped_ptr<api::sessions::Session> CreateSessionModel( |
62 const SessionWindow& window, | 62 const SessionWindow& window, |
63 const std::string& session_tag); | 63 const std::string& session_tag); |
64 scoped_ptr<api::sessions::Device> CreateDeviceModel( | 64 scoped_ptr<api::sessions::Device> CreateDeviceModel( |
65 const browser_sync::SyncedSession* session); | 65 const browser_sync::SyncedSession* session); |
66 }; | 66 }; |
67 | 67 |
68 class SessionsRestoreFunction : public ChromeSyncExtensionFunction { | 68 class SessionsRestoreFunction : public ChromeSyncExtensionFunction { |
69 protected: | 69 protected: |
70 virtual ~SessionsRestoreFunction() {} | 70 virtual ~SessionsRestoreFunction() {} |
71 virtual bool RunSync() OVERRIDE; | 71 virtual bool RunSync() override; |
72 DECLARE_EXTENSION_FUNCTION("sessions.restore", SESSIONS_RESTORE) | 72 DECLARE_EXTENSION_FUNCTION("sessions.restore", SESSIONS_RESTORE) |
73 | 73 |
74 private: | 74 private: |
75 void SetInvalidIdError(const std::string& invalid_id); | 75 void SetInvalidIdError(const std::string& invalid_id); |
76 void SetResultRestoredTab(content::WebContents* contents); | 76 void SetResultRestoredTab(content::WebContents* contents); |
77 bool SetResultRestoredWindow(int window_id); | 77 bool SetResultRestoredWindow(int window_id); |
78 bool RestoreMostRecentlyClosed(Browser* browser); | 78 bool RestoreMostRecentlyClosed(Browser* browser); |
79 bool RestoreLocalSession(const SessionId& session_id, Browser* browser); | 79 bool RestoreLocalSession(const SessionId& session_id, Browser* browser); |
80 bool RestoreForeignSession(const SessionId& session_id, | 80 bool RestoreForeignSession(const SessionId& session_id, |
81 Browser* browser); | 81 Browser* browser); |
82 }; | 82 }; |
83 | 83 |
84 class SessionsEventRouter : public TabRestoreServiceObserver { | 84 class SessionsEventRouter : public TabRestoreServiceObserver { |
85 public: | 85 public: |
86 explicit SessionsEventRouter(Profile* profile); | 86 explicit SessionsEventRouter(Profile* profile); |
87 virtual ~SessionsEventRouter(); | 87 virtual ~SessionsEventRouter(); |
88 | 88 |
89 // Observer callback for TabRestoreServiceObserver. Sends data on | 89 // Observer callback for TabRestoreServiceObserver. Sends data on |
90 // recently closed tabs to the javascript side of this page to | 90 // recently closed tabs to the javascript side of this page to |
91 // display to the user. | 91 // display to the user. |
92 virtual void TabRestoreServiceChanged(TabRestoreService* service) OVERRIDE; | 92 virtual void TabRestoreServiceChanged(TabRestoreService* service) override; |
93 | 93 |
94 // Observer callback to notice when our associated TabRestoreService | 94 // Observer callback to notice when our associated TabRestoreService |
95 // is destroyed. | 95 // is destroyed. |
96 virtual void TabRestoreServiceDestroyed(TabRestoreService* service) OVERRIDE; | 96 virtual void TabRestoreServiceDestroyed(TabRestoreService* service) override; |
97 | 97 |
98 private: | 98 private: |
99 Profile* profile_; | 99 Profile* profile_; |
100 | 100 |
101 // TabRestoreService that we are observing. | 101 // TabRestoreService that we are observing. |
102 TabRestoreService* tab_restore_service_; | 102 TabRestoreService* tab_restore_service_; |
103 | 103 |
104 DISALLOW_COPY_AND_ASSIGN(SessionsEventRouter); | 104 DISALLOW_COPY_AND_ASSIGN(SessionsEventRouter); |
105 }; | 105 }; |
106 | 106 |
107 class SessionsAPI : public BrowserContextKeyedAPI, | 107 class SessionsAPI : public BrowserContextKeyedAPI, |
108 public extensions::EventRouter::Observer { | 108 public extensions::EventRouter::Observer { |
109 public: | 109 public: |
110 explicit SessionsAPI(content::BrowserContext* context); | 110 explicit SessionsAPI(content::BrowserContext* context); |
111 virtual ~SessionsAPI(); | 111 virtual ~SessionsAPI(); |
112 | 112 |
113 // BrowserContextKeyedService implementation. | 113 // BrowserContextKeyedService implementation. |
114 virtual void Shutdown() OVERRIDE; | 114 virtual void Shutdown() override; |
115 | 115 |
116 // BrowserContextKeyedAPI implementation. | 116 // BrowserContextKeyedAPI implementation. |
117 static BrowserContextKeyedAPIFactory<SessionsAPI>* GetFactoryInstance(); | 117 static BrowserContextKeyedAPIFactory<SessionsAPI>* GetFactoryInstance(); |
118 | 118 |
119 // EventRouter::Observer implementation. | 119 // EventRouter::Observer implementation. |
120 virtual void OnListenerAdded(const extensions::EventListenerInfo& details) | 120 virtual void OnListenerAdded(const extensions::EventListenerInfo& details) |
121 OVERRIDE; | 121 override; |
122 | 122 |
123 private: | 123 private: |
124 friend class BrowserContextKeyedAPIFactory<SessionsAPI>; | 124 friend class BrowserContextKeyedAPIFactory<SessionsAPI>; |
125 | 125 |
126 content::BrowserContext* browser_context_; | 126 content::BrowserContext* browser_context_; |
127 | 127 |
128 // BrowserContextKeyedAPI implementation. | 128 // BrowserContextKeyedAPI implementation. |
129 static const char* service_name() { | 129 static const char* service_name() { |
130 return "SessionsAPI"; | 130 return "SessionsAPI"; |
131 } | 131 } |
132 static const bool kServiceIsNULLWhileTesting = true; | 132 static const bool kServiceIsNULLWhileTesting = true; |
133 | 133 |
134 // Created lazily upon OnListenerAdded. | 134 // Created lazily upon OnListenerAdded. |
135 scoped_ptr<SessionsEventRouter> sessions_event_router_; | 135 scoped_ptr<SessionsEventRouter> sessions_event_router_; |
136 | 136 |
137 DISALLOW_COPY_AND_ASSIGN(SessionsAPI); | 137 DISALLOW_COPY_AND_ASSIGN(SessionsAPI); |
138 }; | 138 }; |
139 | 139 |
140 } // namespace extensions | 140 } // namespace extensions |
141 | 141 |
142 #endif // CHROME_BROWSER_EXTENSIONS_API_SESSIONS_SESSIONS_API_H__ | 142 #endif // CHROME_BROWSER_EXTENSIONS_API_SESSIONS_SESSIONS_API_H__ |
OLD | NEW |