Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Unified Diff: chrome/browser/extensions/api/sessions/sessions_api.h

Issue 201393002: Add onChanged callback for chrome.sessions API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/extensions/api/sessions/sessions_api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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__
« no previous file with comments | « no previous file | chrome/browser/extensions/api/sessions/sessions_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698