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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SESSIONS_SESSIONS_API_H__
6 #define CHROME_BROWSER_EXTENSIONS_API_SESSIONS_SESSIONS_API_H__
10 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h"
11 #include "chrome/browser/extensions/chrome_extension_function.h"
12 #include "chrome/browser/sessions/tab_restore_service.h"
13 #include "chrome/browser/sessions/tab_restore_service_observer.h"
14 #include "chrome/common/extensions/api/sessions.h"
15 #include "chrome/common/extensions/api/tabs.h"
16 #include "chrome/common/extensions/api/windows.h"
20 namespace browser_sync {
24 namespace extensions {
28 class SessionsGetRecentlyClosedFunction : public ChromeSyncExtensionFunction {
30 virtual ~SessionsGetRecentlyClosedFunction() {}
31 virtual bool RunImpl() OVERRIDE;
32 DECLARE_EXTENSION_FUNCTION("sessions.getRecentlyClosed",
33 SESSIONS_GETRECENTLYCLOSED)
36 scoped_ptr<api::tabs::Tab> CreateTabModel(const TabRestoreService::Tab& tab,
39 scoped_ptr<api::windows::Window> CreateWindowModel(
40 const TabRestoreService::Window& window,
42 scoped_ptr<api::sessions::Session> CreateSessionModel(
43 const TabRestoreService::Entry* entry);
46 class SessionsGetDevicesFunction : public ChromeSyncExtensionFunction {
48 virtual ~SessionsGetDevicesFunction() {}
49 virtual bool RunImpl() OVERRIDE;
50 DECLARE_EXTENSION_FUNCTION("sessions.getDevices", SESSIONS_GETDEVICES)
53 scoped_ptr<api::tabs::Tab> CreateTabModel(const std::string& session_tag,
54 const SessionTab& tab,
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);
67 class SessionsRestoreFunction : public ChromeSyncExtensionFunction {
69 virtual ~SessionsRestoreFunction() {}
70 virtual bool RunImpl() OVERRIDE;
71 DECLARE_EXTENSION_FUNCTION("sessions.restore", SESSIONS_RESTORE)
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,
83 class SessionsAPI : public ProfileKeyedAPI {
85 explicit SessionsAPI(Profile* profile);
86 virtual ~SessionsAPI();
88 // ProfileKeyedAPI implementation.
89 static ProfileKeyedAPIFactory<SessionsAPI>* GetFactoryInstance();
91 friend class ProfileKeyedAPIFactory<SessionsAPI>;
93 // ProfileKeyedAPI implementation.
94 static const char* service_name() {
97 static const bool kServiceIsNULLWhileTesting = true;
100 } // namespace extensions
102 #endif // CHROME_BROWSER_EXTENSIONS_API_SESSIONS_SESSIONS_API_H__