- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / api / sessions / sessions_api.h
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.
4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SESSIONS_SESSIONS_API_H__
6 #define CHROME_BROWSER_EXTENSIONS_API_SESSIONS_SESSIONS_API_H__
7
8 #include <string>
9
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"
17
18 class Profile;
19
20 namespace browser_sync {
21 struct SyncedSession;
22 }
23
24 namespace extensions {
25
26 class SessionId;
27
28 class SessionsGetRecentlyClosedFunction : public ChromeSyncExtensionFunction {
29  protected:
30   virtual ~SessionsGetRecentlyClosedFunction() {}
31   virtual bool RunImpl() OVERRIDE;
32   DECLARE_EXTENSION_FUNCTION("sessions.getRecentlyClosed",
33                              SESSIONS_GETRECENTLYCLOSED)
34
35  private:
36   scoped_ptr<api::tabs::Tab> CreateTabModel(const TabRestoreService::Tab& tab,
37                                             int session_id,
38                                             int selected_index);
39   scoped_ptr<api::windows::Window> CreateWindowModel(
40       const TabRestoreService::Window& window,
41       int session_id);
42   scoped_ptr<api::sessions::Session> CreateSessionModel(
43       const TabRestoreService::Entry* entry);
44 };
45
46 class SessionsGetDevicesFunction : public ChromeSyncExtensionFunction {
47  protected:
48   virtual ~SessionsGetDevicesFunction() {}
49   virtual bool RunImpl() OVERRIDE;
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);
65 };
66
67 class SessionsRestoreFunction : public ChromeSyncExtensionFunction {
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 {
84  public:
85   explicit SessionsAPI(Profile* profile);
86   virtual ~SessionsAPI();
87
88   // ProfileKeyedAPI implementation.
89   static ProfileKeyedAPIFactory<SessionsAPI>* GetFactoryInstance();
90  private:
91   friend class ProfileKeyedAPIFactory<SessionsAPI>;
92
93   // ProfileKeyedAPI implementation.
94   static const char* service_name() {
95     return "SessionsAPI";
96   }
97   static const bool kServiceIsNULLWhileTesting = true;
98 };
99
100 }  // namespace extensions
101
102 #endif  // CHROME_BROWSER_EXTENSIONS_API_SESSIONS_SESSIONS_API_H__