Index: chrome/browser/extensions/api/sessions/sessions_api.h |
diff --git a/chrome/browser/extensions/api/sessions/sessions_api.h b/chrome/browser/extensions/api/sessions/sessions_api.h |
index e04401937f3d2c90cb4835d05e83cabe8354a367..49b00bb55c4bdfd4cfe42e5884b803ec0f6a94ee 100644 |
--- a/chrome/browser/extensions/api/sessions/sessions_api.h |
+++ b/chrome/browser/extensions/api/sessions/sessions_api.h |
@@ -13,6 +13,8 @@ |
#include "chrome/common/extensions/api/sessions.h" |
#include "chrome/common/extensions/api/tabs.h" |
#include "chrome/common/extensions/api/windows.h" |
+#include "extensions/browser/browser_context_keyed_api_factory.h" |
+#include "extensions/browser/event_router.h" |
class Profile; |
@@ -79,6 +81,62 @@ class SessionsRestoreFunction : public ChromeSyncExtensionFunction { |
Browser* browser); |
}; |
+class SessionsEventRouter : public TabRestoreServiceObserver { |
+ public: |
+ explicit SessionsEventRouter(Profile* profile); |
+ virtual ~SessionsEventRouter(); |
+ |
+ // Observer callback for TabRestoreServiceObserver. Sends data on |
+ // recently closed tabs to the javascript side of this page to |
+ // display to the user. |
+ virtual void TabRestoreServiceChanged(TabRestoreService* service) OVERRIDE; |
+ |
+ // Observer callback to notice when our associated TabRestoreService |
+ // is destroyed. |
+ virtual void TabRestoreServiceDestroyed(TabRestoreService* service) OVERRIDE; |
+ |
+ private: |
+ Profile* profile_; |
+ |
+ // TabRestoreService that we are observing. |
+ TabRestoreService* tab_restore_service_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(SessionsEventRouter); |
+}; |
+ |
+class SessionsAPI : public BrowserContextKeyedAPI, |
+ public extensions::EventRouter::Observer { |
+ public: |
+ explicit SessionsAPI(content::BrowserContext* context); |
+ virtual ~SessionsAPI(); |
+ |
+ // BrowserContextKeyedService implementation. |
+ virtual void Shutdown() OVERRIDE; |
+ |
+ // BrowserContextKeyedAPI implementation. |
+ static BrowserContextKeyedAPIFactory<SessionsAPI>* GetFactoryInstance(); |
+ |
+ // EventRouter::Observer implementation. |
+ virtual void OnListenerAdded(const extensions::EventListenerInfo& details) |
+ OVERRIDE; |
+ |
+ private: |
+ friend class BrowserContextKeyedAPIFactory<SessionsAPI>; |
+ |
+ content::BrowserContext* browser_context_; |
+ |
+ // BrowserContextKeyedAPI implementation. |
+ static const char* service_name() { |
+ return "SessionsAPI"; |
+ } |
+ static const bool kServiceIsNULLWhileTesting = true; |
+ |
+ // Created lazily upon OnListenerAdded. |
+ scoped_ptr<SessionsEventRouter> sessions_event_router_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(SessionsAPI); |
+}; |
+ |
} // namespace extensions |
#endif // CHROME_BROWSER_EXTENSIONS_API_SESSIONS_SESSIONS_API_H__ |