| Index: chrome/browser/extensions/api/sessions/sessions_api.cc
|
| diff --git a/chrome/browser/extensions/api/sessions/sessions_api.cc b/chrome/browser/extensions/api/sessions/sessions_api.cc
|
| index eca014ed685d40de884cc93d2fedac96cc8b1c3e..0774d825355a421f81ca57fa871857c6e2188bc1 100644
|
| --- a/chrome/browser/extensions/api/sessions/sessions_api.cc
|
| +++ b/chrome/browser/extensions/api/sessions/sessions_api.cc
|
| @@ -35,6 +35,7 @@
|
| #include "content/public/browser/web_contents.h"
|
| #include "extensions/browser/extension_function_dispatcher.h"
|
| #include "extensions/browser/extension_function_registry.h"
|
| +#include "extensions/browser/extension_system.h"
|
| #include "extensions/common/error_utils.h"
|
| #include "net/base/net_util.h"
|
| #include "ui/base/layout.h"
|
| @@ -593,4 +594,59 @@ bool SessionsRestoreFunction::RunImpl() {
|
| : RestoreLocalSession(*session_id, browser);
|
| }
|
|
|
| +SessionsEventRouter::SessionsEventRouter(Profile* profile)
|
| + : profile_(profile),
|
| + tab_restore_service_(TabRestoreServiceFactory::GetForProfile(profile)) {
|
| + // TabRestoreServiceFactory::GetForProfile() can return NULL (i.e., when in
|
| + // incognito mode)
|
| + if (tab_restore_service_) {
|
| + tab_restore_service_->LoadTabsFromLastSession();
|
| + tab_restore_service_->AddObserver(this);
|
| + }
|
| +}
|
| +
|
| +SessionsEventRouter::~SessionsEventRouter() {
|
| + if (tab_restore_service_)
|
| + tab_restore_service_->RemoveObserver(this);
|
| +}
|
| +
|
| +void SessionsEventRouter::TabRestoreServiceChanged(
|
| + TabRestoreService* service) {
|
| + scoped_ptr<base::ListValue> args(new base::ListValue());
|
| + EventRouter::Get(profile_)->BroadcastEvent(make_scoped_ptr(
|
| + new Event(api::sessions::OnChanged::kEventName, args.Pass())));
|
| +}
|
| +
|
| +void SessionsEventRouter::TabRestoreServiceDestroyed(
|
| + TabRestoreService* service) {
|
| + tab_restore_service_ = NULL;
|
| +}
|
| +
|
| +SessionsAPI::SessionsAPI(content::BrowserContext* context)
|
| + : browser_context_(context) {
|
| + EventRouter::Get(browser_context_)->RegisterObserver(this,
|
| + api::sessions::OnChanged::kEventName);
|
| +}
|
| +
|
| +SessionsAPI::~SessionsAPI() {
|
| +}
|
| +
|
| +void SessionsAPI::Shutdown() {
|
| + EventRouter::Get(browser_context_)->UnregisterObserver(this);
|
| +}
|
| +
|
| +static base::LazyInstance<BrowserContextKeyedAPIFactory<SessionsAPI> >
|
| + g_factory = LAZY_INSTANCE_INITIALIZER;
|
| +
|
| +BrowserContextKeyedAPIFactory<SessionsAPI>*
|
| +SessionsAPI::GetFactoryInstance() {
|
| + return g_factory.Pointer();
|
| +}
|
| +
|
| +void SessionsAPI::OnListenerAdded(const EventListenerInfo& details) {
|
| + sessions_event_router_.reset(
|
| + new SessionsEventRouter(Profile::FromBrowserContext(browser_context_)));
|
| + EventRouter::Get(browser_context_)->UnregisterObserver(this);
|
| +}
|
| +
|
| } // namespace extensions
|
|
|