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

Unified Diff: chrome/browser/extensions/api/tabs/tabs_event_router.cc

Issue 2142413003: Adding Discarded property support for onUpdate function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@API_Discarded
Patch Set: nit missing end of line Created 4 years, 5 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
Index: chrome/browser/extensions/api/tabs/tabs_event_router.cc
diff --git a/chrome/browser/extensions/api/tabs/tabs_event_router.cc b/chrome/browser/extensions/api/tabs/tabs_event_router.cc
index 80c495c96736c1de6aa06d668eb52bdbe8adad82..84c5e15c106c2070ce36011c6129cec25280880a 100644
--- a/chrome/browser/extensions/api/tabs/tabs_event_router.cc
+++ b/chrome/browser/extensions/api/tabs/tabs_event_router.cc
@@ -11,10 +11,12 @@
#include "base/memory/ptr_util.h"
#include "base/values.h"
+#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/api/tabs/tabs_constants.h"
#include "chrome/browser/extensions/api/tabs/tabs_windows_api.h"
#include "chrome/browser/extensions/api/tabs/windows_event_router.h"
#include "chrome/browser/extensions/extension_tab_util.h"
+#include "chrome/browser/memory/tab_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
@@ -140,9 +142,14 @@ TabsEventRouter::TabsEventRouter(Profile* profile)
browser_tab_strip_tracker_.Init(
BrowserTabStripTracker::InitWith::ALL_BROWERS);
+
+ if (g_browser_process->GetTabManager())
Devlin 2016/07/29 16:01:09 Document when this is null.
Anderson Silva 2016/07/29 19:05:59 It shouldn't be null anymore as we included a tab_
+ g_browser_process->GetTabManager()->AddObserver(this);
Devlin 2016/07/29 16:01:09 Use a ScopedObserver.
Anderson Silva 2016/07/29 19:05:59 Done.
}
TabsEventRouter::~TabsEventRouter() {
+ if (g_browser_process->GetTabManager())
+ g_browser_process->GetTabManager()->RemoveObserver(this);
Devlin 2016/07/29 16:01:09 Is the TabManager guaranteed to outlive the TabsEv
Anderson Silva 2016/07/29 19:05:59 TabManager is created at the first time GetTabMana
Devlin 2016/07/29 20:17:33 Not strictly true. A ScopedObserver just automati
}
bool TabsEventRouter::ShouldTrackBrowser(Browser* browser) {
@@ -552,4 +559,16 @@ void TabsEventRouter::OnFaviconUpdated(
}
}
+void TabsEventRouter::OnDiscardedStateChange(WebContents* contents,
+ bool is_discarded) {
+ TabStripModel* tab_strip = nullptr;
+ int tab_index = -1;
+
+ if (ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index)) {
Devlin 2016/07/29 16:01:09 Why do we use this method here instead of e.g. Get
Anderson Silva 2016/07/29 19:05:59 I see this call just as a check that we can find a
Devlin 2016/07/29 20:17:33 Do we strictly need a tab strip associated? Or ca
+ std::set<std::string> changed_property_names;
+ changed_property_names.insert(tabs_constants::kDiscardedKey);
+ DispatchTabUpdatedEvent(contents, std::move(changed_property_names));
+ }
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698