| 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 "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "chrome/browser/extensions/chrome_extension_function.h" | 11 #include "chrome/browser/extensions/chrome_extension_function.h" |
| 12 #include "chrome/common/extensions/api/sessions.h" | 12 #include "chrome/common/extensions/api/sessions.h" |
| 13 #include "chrome/common/extensions/api/tabs.h" | 13 #include "chrome/common/extensions/api/tabs.h" |
| 14 #include "chrome/common/extensions/api/windows.h" | 14 #include "chrome/common/extensions/api/windows.h" |
| 15 #include "components/sessions/core/tab_restore_service.h" | 15 #include "components/sessions/core/tab_restore_service.h" |
| 16 #include "components/sessions/core/tab_restore_service_observer.h" | 16 #include "components/sessions/core/tab_restore_service_observer.h" |
| 17 #include "extensions/browser/browser_context_keyed_api_factory.h" | 17 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| 18 #include "extensions/browser/event_router.h" | 18 #include "extensions/browser/event_router.h" |
| 19 | 19 |
| 20 class Profile; | 20 class Profile; |
| 21 | 21 |
| 22 namespace sync_sessions { | 22 namespace sync_sessions { |
| 23 struct SyncedSession; | 23 struct SyncedSession; |
| 24 } | 24 } |
| 25 | 25 |
| 26 namespace extensions { | 26 namespace extensions { |
| 27 | 27 |
| 28 class SessionId; | 28 class SessionId; |
| 29 | 29 |
| 30 class SessionsGetRecentlyClosedFunction : public ChromeSyncExtensionFunction { | 30 class SessionsGetRecentlyClosedFunction : public UIThreadExtensionFunction { |
| 31 protected: | 31 protected: |
| 32 ~SessionsGetRecentlyClosedFunction() override {} | 32 ~SessionsGetRecentlyClosedFunction() override {} |
| 33 bool RunSync() override; | 33 ResponseAction Run() override; |
| 34 DECLARE_EXTENSION_FUNCTION("sessions.getRecentlyClosed", | 34 DECLARE_EXTENSION_FUNCTION("sessions.getRecentlyClosed", |
| 35 SESSIONS_GETRECENTLYCLOSED) | 35 SESSIONS_GETRECENTLYCLOSED) |
| 36 | 36 |
| 37 private: | 37 private: |
| 38 api::tabs::Tab CreateTabModel(const sessions::TabRestoreService::Tab& tab, | 38 api::tabs::Tab CreateTabModel(const sessions::TabRestoreService::Tab& tab, |
| 39 bool active); | 39 bool active); |
| 40 std::unique_ptr<api::windows::Window> CreateWindowModel( | 40 std::unique_ptr<api::windows::Window> CreateWindowModel( |
| 41 const sessions::TabRestoreService::Window& window); | 41 const sessions::TabRestoreService::Window& window); |
| 42 std::unique_ptr<api::sessions::Session> CreateSessionModel( | 42 std::unique_ptr<api::sessions::Session> CreateSessionModel( |
| 43 const sessions::TabRestoreService::Entry& entry); | 43 const sessions::TabRestoreService::Entry& entry); |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 class SessionsGetDevicesFunction : public ChromeSyncExtensionFunction { | 46 class SessionsGetDevicesFunction : public UIThreadExtensionFunction { |
| 47 protected: | 47 protected: |
| 48 ~SessionsGetDevicesFunction() override {} | 48 ~SessionsGetDevicesFunction() override {} |
| 49 bool RunSync() override; | 49 ResponseAction Run() override; |
| 50 DECLARE_EXTENSION_FUNCTION("sessions.getDevices", SESSIONS_GETDEVICES) | 50 DECLARE_EXTENSION_FUNCTION("sessions.getDevices", SESSIONS_GETDEVICES) |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 api::tabs::Tab CreateTabModel(const std::string& session_tag, | 53 api::tabs::Tab CreateTabModel(const std::string& session_tag, |
| 54 const sessions::SessionTab& tab, | 54 const sessions::SessionTab& tab, |
| 55 int tab_index, | 55 int tab_index, |
| 56 bool active); | 56 bool active); |
| 57 std::unique_ptr<api::windows::Window> CreateWindowModel( | 57 std::unique_ptr<api::windows::Window> CreateWindowModel( |
| 58 const sessions::SessionWindow& window, | 58 const sessions::SessionWindow& window, |
| 59 const std::string& session_tag); | 59 const std::string& session_tag); |
| 60 std::unique_ptr<api::sessions::Session> CreateSessionModel( | 60 std::unique_ptr<api::sessions::Session> CreateSessionModel( |
| 61 const sessions::SessionWindow& window, | 61 const sessions::SessionWindow& window, |
| 62 const std::string& session_tag); | 62 const std::string& session_tag); |
| 63 api::sessions::Device CreateDeviceModel( | 63 api::sessions::Device CreateDeviceModel( |
| 64 const sync_sessions::SyncedSession* session); | 64 const sync_sessions::SyncedSession* session); |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 class SessionsRestoreFunction : public ChromeSyncExtensionFunction { | 67 class SessionsRestoreFunction : public UIThreadExtensionFunction { |
| 68 protected: | 68 protected: |
| 69 ~SessionsRestoreFunction() override {} | 69 ~SessionsRestoreFunction() override {} |
| 70 bool RunSync() override; | 70 ResponseAction Run() override; |
| 71 DECLARE_EXTENSION_FUNCTION("sessions.restore", SESSIONS_RESTORE) | 71 DECLARE_EXTENSION_FUNCTION("sessions.restore", SESSIONS_RESTORE) |
| 72 | 72 |
| 73 private: | 73 private: |
| 74 void SetInvalidIdError(const std::string& invalid_id); | 74 ResponseValue GetRestoredTabResult(content::WebContents* contents); |
| 75 void SetResultRestoredTab(content::WebContents* contents); | 75 ResponseValue GetRestoredWindowResult(int window_id); |
| 76 bool SetResultRestoredWindow(int window_id); | 76 ResponseValue RestoreMostRecentlyClosed(Browser* browser); |
| 77 bool RestoreMostRecentlyClosed(Browser* browser); | 77 ResponseValue RestoreLocalSession(const SessionId& session_id, |
| 78 bool RestoreLocalSession(const SessionId& session_id, Browser* browser); | 78 Browser* browser); |
| 79 bool RestoreForeignSession(const SessionId& session_id, | 79 ResponseValue RestoreForeignSession(const SessionId& session_id, |
| 80 Browser* browser); | 80 Browser* browser); |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 class SessionsEventRouter : public sessions::TabRestoreServiceObserver { | 83 class SessionsEventRouter : public sessions::TabRestoreServiceObserver { |
| 84 public: | 84 public: |
| 85 explicit SessionsEventRouter(Profile* profile); | 85 explicit SessionsEventRouter(Profile* profile); |
| 86 ~SessionsEventRouter() override; | 86 ~SessionsEventRouter() override; |
| 87 | 87 |
| 88 // Observer callback for TabRestoreServiceObserver. Sends data on | 88 // Observer callback for TabRestoreServiceObserver. Sends data on |
| 89 // recently closed tabs to the javascript side of this page to | 89 // recently closed tabs to the javascript side of this page to |
| 90 // display to the user. | 90 // display to the user. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 | 132 |
| 133 // Created lazily upon OnListenerAdded. | 133 // Created lazily upon OnListenerAdded. |
| 134 std::unique_ptr<SessionsEventRouter> sessions_event_router_; | 134 std::unique_ptr<SessionsEventRouter> sessions_event_router_; |
| 135 | 135 |
| 136 DISALLOW_COPY_AND_ASSIGN(SessionsAPI); | 136 DISALLOW_COPY_AND_ASSIGN(SessionsAPI); |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 } // namespace extensions | 139 } // namespace extensions |
| 140 | 140 |
| 141 #endif // CHROME_BROWSER_EXTENSIONS_API_SESSIONS_SESSIONS_API_H__ | 141 #endif // CHROME_BROWSER_EXTENSIONS_API_SESSIONS_SESSIONS_API_H__ |
| OLD | NEW |