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 "chrome/browser/extensions/chrome_extension_function.h" | 10 #include "chrome/browser/extensions/chrome_extension_function.h" |
11 #include "chrome/browser/sessions/tab_restore_service.h" | 11 #include "chrome/browser/sessions/tab_restore_service.h" |
12 #include "chrome/browser/sessions/tab_restore_service_observer.h" | 12 #include "chrome/browser/sessions/tab_restore_service_observer.h" |
13 #include "chrome/common/extensions/api/sessions.h" | 13 #include "chrome/common/extensions/api/sessions.h" |
14 #include "chrome/common/extensions/api/tabs.h" | 14 #include "chrome/common/extensions/api/tabs.h" |
15 #include "chrome/common/extensions/api/windows.h" | 15 #include "chrome/common/extensions/api/windows.h" |
| 16 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| 17 #include "extensions/browser/event_router.h" |
16 | 18 |
17 class Profile; | 19 class Profile; |
18 | 20 |
19 namespace browser_sync { | 21 namespace browser_sync { |
20 struct SyncedSession; | 22 struct SyncedSession; |
21 } | 23 } |
22 | 24 |
23 namespace extensions { | 25 namespace extensions { |
24 | 26 |
25 class SessionId; | 27 class SessionId; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 private: | 74 private: |
73 void SetInvalidIdError(const std::string& invalid_id); | 75 void SetInvalidIdError(const std::string& invalid_id); |
74 void SetResultRestoredTab(const content::WebContents* contents); | 76 void SetResultRestoredTab(const content::WebContents* contents); |
75 bool SetResultRestoredWindow(int window_id); | 77 bool SetResultRestoredWindow(int window_id); |
76 bool RestoreMostRecentlyClosed(Browser* browser); | 78 bool RestoreMostRecentlyClosed(Browser* browser); |
77 bool RestoreLocalSession(const SessionId& session_id, Browser* browser); | 79 bool RestoreLocalSession(const SessionId& session_id, Browser* browser); |
78 bool RestoreForeignSession(const SessionId& session_id, | 80 bool RestoreForeignSession(const SessionId& session_id, |
79 Browser* browser); | 81 Browser* browser); |
80 }; | 82 }; |
81 | 83 |
| 84 class SessionsEventRouter : public TabRestoreServiceObserver { |
| 85 public: |
| 86 explicit SessionsEventRouter(Profile* profile); |
| 87 virtual ~SessionsEventRouter(); |
| 88 |
| 89 // Observer callback for TabRestoreServiceObserver. Sends data on |
| 90 // recently closed tabs to the javascript side of this page to |
| 91 // display to the user. |
| 92 virtual void TabRestoreServiceChanged(TabRestoreService* service) OVERRIDE; |
| 93 |
| 94 // Observer callback to notice when our associated TabRestoreService |
| 95 // is destroyed. |
| 96 virtual void TabRestoreServiceDestroyed(TabRestoreService* service) OVERRIDE; |
| 97 |
| 98 private: |
| 99 Profile* profile_; |
| 100 |
| 101 // TabRestoreService that we are observing. |
| 102 TabRestoreService* tab_restore_service_; |
| 103 |
| 104 DISALLOW_COPY_AND_ASSIGN(SessionsEventRouter); |
| 105 }; |
| 106 |
| 107 class SessionsAPI : public BrowserContextKeyedAPI, |
| 108 public extensions::EventRouter::Observer { |
| 109 public: |
| 110 explicit SessionsAPI(content::BrowserContext* context); |
| 111 virtual ~SessionsAPI(); |
| 112 |
| 113 // BrowserContextKeyedService implementation. |
| 114 virtual void Shutdown() OVERRIDE; |
| 115 |
| 116 // BrowserContextKeyedAPI implementation. |
| 117 static BrowserContextKeyedAPIFactory<SessionsAPI>* GetFactoryInstance(); |
| 118 |
| 119 // EventRouter::Observer implementation. |
| 120 virtual void OnListenerAdded(const extensions::EventListenerInfo& details) |
| 121 OVERRIDE; |
| 122 |
| 123 private: |
| 124 friend class BrowserContextKeyedAPIFactory<SessionsAPI>; |
| 125 |
| 126 content::BrowserContext* browser_context_; |
| 127 |
| 128 // BrowserContextKeyedAPI implementation. |
| 129 static const char* service_name() { |
| 130 return "SessionsAPI"; |
| 131 } |
| 132 static const bool kServiceIsNULLWhileTesting = true; |
| 133 |
| 134 // Created lazily upon OnListenerAdded. |
| 135 scoped_ptr<SessionsEventRouter> sessions_event_router_; |
| 136 |
| 137 DISALLOW_COPY_AND_ASSIGN(SessionsAPI); |
| 138 }; |
| 139 |
82 } // namespace extensions | 140 } // namespace extensions |
83 | 141 |
84 #endif // CHROME_BROWSER_EXTENSIONS_API_SESSIONS_SESSIONS_API_H__ | 142 #endif // CHROME_BROWSER_EXTENSIONS_API_SESSIONS_SESSIONS_API_H__ |
OLD | NEW |