Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_SESSION_RESTORE_SESSION_RESTORE_API_H__ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SESSIONS_SESSIONS_API_H__ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_SESSION_RESTORE_SESSION_RESTORE_API_H__ | 6 #define CHROME_BROWSER_EXTENSIONS_API_SESSIONS_SESSIONS_API_H__ |
| 7 | |
| 8 #include <string> | |
| 7 | 9 |
| 8 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" | 10 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" |
| 9 #include "chrome/browser/extensions/extension_function.h" | 11 #include "chrome/browser/extensions/extension_function.h" |
| 10 #include "chrome/browser/sessions/tab_restore_service.h" | 12 #include "chrome/browser/sessions/tab_restore_service.h" |
| 11 #include "chrome/common/extensions/api/session_restore.h" | 13 #include "chrome/browser/sessions/tab_restore_service_observer.h" |
| 14 #include "chrome/common/extensions/api/sessions.h" | |
| 12 #include "chrome/common/extensions/api/tabs.h" | 15 #include "chrome/common/extensions/api/tabs.h" |
| 13 #include "chrome/common/extensions/api/windows.h" | 16 #include "chrome/common/extensions/api/windows.h" |
| 14 | 17 |
| 15 class Profile; | 18 class Profile; |
| 16 | 19 |
| 20 namespace browser_sync { | |
| 21 struct SyncedSession; | |
| 22 } | |
| 23 | |
| 17 namespace extensions { | 24 namespace extensions { |
| 18 | 25 |
| 19 class SessionRestoreGetRecentlyClosedFunction : public SyncExtensionFunction { | 26 struct SessionId; |
|
not at google - send to devlin
2013/08/19 19:34:40
forward declarations should still work for referen
Kristen Dwan
2013/08/19 21:35:05
Done.
| |
| 27 | |
| 28 class SessionsGetRecentlyClosedFunction : public SyncExtensionFunction { | |
| 20 protected: | 29 protected: |
| 21 virtual ~SessionRestoreGetRecentlyClosedFunction() {} | 30 virtual ~SessionsGetRecentlyClosedFunction() {} |
| 22 virtual bool RunImpl() OVERRIDE; | 31 virtual bool RunImpl() OVERRIDE; |
| 23 DECLARE_EXTENSION_FUNCTION("sessionRestore.getRecentlyClosed", | 32 DECLARE_EXTENSION_FUNCTION("sessions.getRecentlyClosed", |
| 24 SESSIONRESTORE_GETRECENTLYCLOSED) | 33 SESSIONS_GETRECENTLYCLOSED) |
| 25 | 34 |
| 26 private: | 35 private: |
| 27 scoped_ptr<api::tabs::Tab> CreateTabModel( | 36 scoped_ptr<api::tabs::Tab> CreateTabModel(const TabRestoreService::Tab& tab, |
| 28 const TabRestoreService::Tab& tab, int selected_index); | 37 int session_id, |
| 38 int selected_index); | |
| 29 scoped_ptr<api::windows::Window> CreateWindowModel( | 39 scoped_ptr<api::windows::Window> CreateWindowModel( |
| 30 const TabRestoreService::Window& window); | 40 const TabRestoreService::Window& window, |
| 31 scoped_ptr<api::session_restore::ClosedEntry> CreateEntryModel( | 41 int session_id); |
| 42 scoped_ptr<api::sessions::Session> CreateSessionModel( | |
| 32 const TabRestoreService::Entry* entry); | 43 const TabRestoreService::Entry* entry); |
| 33 }; | 44 }; |
| 34 | 45 |
| 35 class SessionRestoreRestoreFunction : public SyncExtensionFunction { | 46 class SessionsGetDevicesFunction : public SyncExtensionFunction { |
| 36 protected: | 47 protected: |
| 37 virtual ~SessionRestoreRestoreFunction() {} | 48 virtual ~SessionsGetDevicesFunction() {} |
| 38 virtual bool RunImpl() OVERRIDE; | 49 virtual bool RunImpl() OVERRIDE; |
| 39 DECLARE_EXTENSION_FUNCTION("sessionRestore.restore", SESSIONRESTORE_RESTORE) | 50 DECLARE_EXTENSION_FUNCTION("sessions.getDevices", SESSIONS_GETDEVICES) |
| 51 | |
| 52 private: | |
| 53 scoped_ptr<api::tabs::Tab> CreateTabModel(const std::string& session_tag, | |
| 54 const SessionTab& tab, | |
| 55 int tab_index, | |
| 56 int selected_index); | |
| 57 scoped_ptr<api::windows::Window> CreateWindowModel( | |
| 58 const SessionWindow& window, | |
| 59 const std::string& session_tag); | |
| 60 scoped_ptr<api::sessions::Session> CreateSessionModel( | |
| 61 const SessionWindow& window, | |
| 62 const std::string& session_tag); | |
| 63 scoped_ptr<api::sessions::Device> CreateDeviceModel( | |
| 64 const browser_sync::SyncedSession* session); | |
| 40 }; | 65 }; |
| 41 | 66 |
| 42 class SessionRestoreAPI : public ProfileKeyedAPI { | 67 class SessionsRestoreFunction : public SyncExtensionFunction { |
| 68 protected: | |
| 69 virtual ~SessionsRestoreFunction() {} | |
| 70 virtual bool RunImpl() OVERRIDE; | |
| 71 DECLARE_EXTENSION_FUNCTION("sessions.restore", SESSIONS_RESTORE) | |
| 72 | |
| 73 private: | |
| 74 void SetInvalidIdError(const std::string& invalid_id); | |
| 75 void SetResultRestoredTab(const content::WebContents* contents); | |
| 76 bool SetResultRestoredWindow(int window_id); | |
| 77 bool RestoreMostRecentlyClosed(Browser* browser); | |
| 78 bool RestoreLocalSession(const SessionId* session_id, Browser* browser); | |
| 79 bool RestoreForeignSession(const SessionId* session_id, | |
| 80 Browser* browser); | |
| 81 }; | |
| 82 | |
| 83 class SessionsAPI : public ProfileKeyedAPI { | |
| 43 public: | 84 public: |
| 44 explicit SessionRestoreAPI(Profile* profile); | 85 explicit SessionsAPI(Profile* profile); |
| 45 virtual ~SessionRestoreAPI(); | 86 virtual ~SessionsAPI(); |
| 46 | 87 |
| 47 // ProfileKeyedAPI implementation. | 88 // ProfileKeyedAPI implementation. |
| 48 static ProfileKeyedAPIFactory<SessionRestoreAPI>* GetFactoryInstance(); | 89 static ProfileKeyedAPIFactory<SessionsAPI>* GetFactoryInstance(); |
| 49 private: | 90 private: |
| 50 friend class ProfileKeyedAPIFactory<SessionRestoreAPI>; | 91 friend class ProfileKeyedAPIFactory<SessionsAPI>; |
| 51 | 92 |
| 52 // ProfileKeyedAPI implementation. | 93 // ProfileKeyedAPI implementation. |
| 53 static const char* service_name() { | 94 static const char* service_name() { |
| 54 return "SessionRestoreAPI"; | 95 return "SessionsAPI"; |
| 55 } | 96 } |
| 56 static const bool kServiceIsNULLWhileTesting = true; | 97 static const bool kServiceIsNULLWhileTesting = true; |
| 57 }; | 98 }; |
| 58 | 99 |
| 59 } // namespace extensions | 100 } // namespace extensions |
| 60 | 101 |
| 61 #endif // CHROME_BROWSER_EXTENSIONS_API_SESSION_RESTORE_SESSION_RESTORE_API_H__ | 102 #endif // CHROME_BROWSER_EXTENSIONS_API_SESSIONS_SESSIONS_API_H__ |
| OLD | NEW |