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

Unified Diff: chrome/browser/ui/tab_webcontents_tracker.cc

Issue 14518005: Add TabWebContentsTracker (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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/ui/tab_webcontents_tracker.cc
diff --git a/chrome/browser/ui/tab_webcontents_tracker.cc b/chrome/browser/ui/tab_webcontents_tracker.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e7415f28eda8a8600214b812ac7ee2dda67b4a7a
--- /dev/null
+++ b/chrome/browser/ui/tab_webcontents_tracker.cc
@@ -0,0 +1,90 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/tab_webcontents_tracker.h"
+
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "content/public/browser/web_contents.h"
+
+// static
+TabWebContentsTracker* TabWebContentsTracker::GetInstance() {
+ return Singleton<TabWebContentsTracker,
+ DefaultSingletonTraits<TabWebContentsTracker> >::get();
Bernhard Bauer 2013/04/26 16:30:10 I think DefaultSingletonTraits is the default, so
+}
+
+TabWebContentsTracker::TabWebContentsTracker() {
+ BrowserList::AddObserver(this);
+ // Add as observer of all tab strip models currently available.
+ BrowserList* browser_list =
+ BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE);
+ BrowserList::const_iterator it = browser_list->begin();
Bernhard Bauer 2013/04/26 16:30:10 Could you put this into a for loop? That's slightl
+ while (it != browser_list->end()) {
+ (*it)->tab_strip_model()->AddObserver(this);
+ ++it;
+ }
+}
+
+TabWebContentsTracker::~TabWebContentsTracker() {
+ BrowserList::RemoveObserver(this);
+}
+
+void TabWebContentsTracker::OnBrowserAdded(Browser* browser) {
+ browser->tab_strip_model()->AddObserver(this);
+}
+
+void TabWebContentsTracker::OnBrowserRemoved(Browser* browser) {
+ browser->tab_strip_model()->RemoveObserver(this);
+}
+
+void TabWebContentsTracker::ActiveTabChanged(content::WebContents* old_contents,
+ content::WebContents* new_contents,
+ int index,
+ int reason) {
+ FOR_EACH_OBSERVER(
Bernhard Bauer 2013/04/26 16:30:10 Hmm... Instead of forwarding all these methods fro
+ Observer,
+ observer_list_,
+ OnActiveTabChanged(old_contents, new_contents, index, reason));
+}
+
+void TabWebContentsTracker::TabInsertedAt(content::WebContents* contents,
+ int index,
+ bool foreground) {
+ FOR_EACH_OBSERVER(
+ Observer, observer_list_, OnTabInsertedAt(contents, index, foreground));
+}
+
+void TabWebContentsTracker::TabClosingAt(TabStripModel* tab_strip_model,
+ content::WebContents* contents,
+ int index) {
+ FOR_EACH_OBSERVER(Observer,
+ observer_list_,
+ OnTabClosingAt(tab_strip_model, contents, index));
+}
+
+void TabWebContentsTracker::TabDetachedAt(content::WebContents* contents,
+ int index) {
+ FOR_EACH_OBSERVER(Observer, observer_list_, OnTabDetachedAt(contents, index));
+}
+
+void TabWebContentsTracker::TabReplacedAt(TabStripModel* tab_strip_model,
+ content::WebContents* old_contents,
+ content::WebContents* new_contents,
+ int index) {
+ FOR_EACH_OBSERVER(
+ Observer,
+ observer_list_,
+ OnTabReplacedAt(tab_strip_model, old_contents, new_contents, index));
+}
+
+// static
+void TabWebContentsTracker::AddObserver(Observer* observer) {
+ GetInstance()->observer_list_.AddObserver(observer);
+}
+
+// static
+void TabWebContentsTracker::RemoveObserver(Observer* observer) {
+ GetInstance()->observer_list_.RemoveObserver(observer);
+}

Powered by Google App Engine
This is Rietveld 408576698