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

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

Issue 1400823003: Creates BrowserTabStripTracker to consolidate common code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review feedback and git cl format Created 5 years, 2 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 74a12c99fd671f29742ba823ca74fe382316d891..504acf67047ee1eea49b29a4fe51646e37e9209b 100644
--- a/chrome/browser/extensions/api/tabs/tabs_event_router.cc
+++ b/chrome/browser/extensions/api/tabs/tabs_event_router.cc
@@ -118,47 +118,21 @@ bool TabsEventRouter::TabEntry::SetMuted(bool new_val) {
}
TabsEventRouter::TabsEventRouter(Profile* profile)
- : profile_(profile), favicon_scoped_observer_(this) {
+ : profile_(profile),
+ favicon_scoped_observer_(this),
+ browser_tab_strip_tracker_(this, this, this) {
DCHECK(!profile->IsOffTheRecord());
- BrowserList::AddObserver(this);
-
- // Init() can happen after the browser is running, so catch up with any
- // windows that already exist.
- for (chrome::BrowserIterator it; !it.done(); it.Next()) {
- RegisterForBrowserNotifications(*it);
-
- // Also catch up our internal bookkeeping of tab entries.
- Browser* browser = *it;
- if (ExtensionTabUtil::BrowserSupportsTabs(browser)) {
- for (int i = 0; i < browser->tab_strip_model()->count(); ++i) {
- WebContents* contents = browser->tab_strip_model()->GetWebContentsAt(i);
- int tab_id = ExtensionTabUtil::GetTabId(contents);
- tab_entries_[tab_id] = make_linked_ptr(new TabEntry(contents));
- }
- }
- }
+ browser_tab_strip_tracker_.Init(
+ BrowserTabStripTracker::InitWith::ALL_BROWERS);
}
TabsEventRouter::~TabsEventRouter() {
- BrowserList::RemoveObserver(this);
-}
-
-void TabsEventRouter::OnBrowserAdded(Browser* browser) {
- RegisterForBrowserNotifications(browser);
}
-void TabsEventRouter::RegisterForBrowserNotifications(Browser* browser) {
- if (!profile_->IsSameProfile(browser->profile()) ||
- !ExtensionTabUtil::BrowserSupportsTabs(browser))
- return;
- // Start listening to TabStripModel events for this browser.
- TabStripModel* tab_strip = browser->tab_strip_model();
- tab_strip->AddObserver(this);
-
- for (int i = 0; i < tab_strip->count(); ++i) {
- RegisterForTabNotifications(tab_strip->GetWebContentsAt(i));
- }
+bool TabsEventRouter::ShouldTrackBrowser(Browser* browser) {
+ return profile_->IsSameProfile(browser->profile()) &&
+ ExtensionTabUtil::BrowserSupportsTabs(browser);
}
void TabsEventRouter::RegisterForTabNotifications(WebContents* contents) {
@@ -190,14 +164,6 @@ void TabsEventRouter::UnregisterForTabNotifications(WebContents* contents) {
ZoomController::FromWebContents(contents)->RemoveObserver(this);
}
-void TabsEventRouter::OnBrowserRemoved(Browser* browser) {
- if (!profile_->IsSameProfile(browser->profile()))
- return;
-
- // Stop listening to TabStripModel events for this browser.
- browser->tab_strip_model()->RemoveObserver(this);
-}
-
void TabsEventRouter::OnBrowserSetLastActive(Browser* browser) {
TabsWindowsAPI* tabs_window_api = TabsWindowsAPI::Get(profile_);
if (tabs_window_api) {
@@ -240,12 +206,16 @@ void TabsEventRouter::TabCreatedAt(WebContents* contents,
void TabsEventRouter::TabInsertedAt(WebContents* contents,
int index,
bool active) {
- // If tab is new, send created event.
int tab_id = ExtensionTabUtil::GetTabId(contents);
if (GetTabEntry(contents).get() == NULL) {
tab_entries_[tab_id] = make_linked_ptr(new TabEntry(contents));
- TabCreatedAt(contents, index, active);
+ // We've never seen this tab, send create event as long as we're not in the
+ // constructor.
+ if (browser_tab_strip_tracker_.is_processing_initial_browsers())
+ RegisterForTabNotifications(contents);
+ else
+ TabCreatedAt(contents, index, active);
return;
}

Powered by Google App Engine
This is Rietveld 408576698