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