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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/tab_webcontents_tracker.h"
6
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_list.h"
9 #include "chrome/browser/ui/tabs/tab_strip_model.h"
10 #include "content/public/browser/web_contents.h"
11
12 // static
13 TabWebContentsTracker* TabWebContentsTracker::GetInstance() {
14 return Singleton<TabWebContentsTracker,
15 DefaultSingletonTraits<TabWebContentsTracker> >::get();
Bernhard Bauer 2013/04/26 16:30:10 I think DefaultSingletonTraits is the default, so
16 }
17
18 TabWebContentsTracker::TabWebContentsTracker() {
19 BrowserList::AddObserver(this);
20 // Add as observer of all tab strip models currently available.
21 BrowserList* browser_list =
22 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE);
23 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
24 while (it != browser_list->end()) {
25 (*it)->tab_strip_model()->AddObserver(this);
26 ++it;
27 }
28 }
29
30 TabWebContentsTracker::~TabWebContentsTracker() {
31 BrowserList::RemoveObserver(this);
32 }
33
34 void TabWebContentsTracker::OnBrowserAdded(Browser* browser) {
35 browser->tab_strip_model()->AddObserver(this);
36 }
37
38 void TabWebContentsTracker::OnBrowserRemoved(Browser* browser) {
39 browser->tab_strip_model()->RemoveObserver(this);
40 }
41
42 void TabWebContentsTracker::ActiveTabChanged(content::WebContents* old_contents,
43 content::WebContents* new_contents,
44 int index,
45 int reason) {
46 FOR_EACH_OBSERVER(
Bernhard Bauer 2013/04/26 16:30:10 Hmm... Instead of forwarding all these methods fro
47 Observer,
48 observer_list_,
49 OnActiveTabChanged(old_contents, new_contents, index, reason));
50 }
51
52 void TabWebContentsTracker::TabInsertedAt(content::WebContents* contents,
53 int index,
54 bool foreground) {
55 FOR_EACH_OBSERVER(
56 Observer, observer_list_, OnTabInsertedAt(contents, index, foreground));
57 }
58
59 void TabWebContentsTracker::TabClosingAt(TabStripModel* tab_strip_model,
60 content::WebContents* contents,
61 int index) {
62 FOR_EACH_OBSERVER(Observer,
63 observer_list_,
64 OnTabClosingAt(tab_strip_model, contents, index));
65 }
66
67 void TabWebContentsTracker::TabDetachedAt(content::WebContents* contents,
68 int index) {
69 FOR_EACH_OBSERVER(Observer, observer_list_, OnTabDetachedAt(contents, index));
70 }
71
72 void TabWebContentsTracker::TabReplacedAt(TabStripModel* tab_strip_model,
73 content::WebContents* old_contents,
74 content::WebContents* new_contents,
75 int index) {
76 FOR_EACH_OBSERVER(
77 Observer,
78 observer_list_,
79 OnTabReplacedAt(tab_strip_model, old_contents, new_contents, index));
80 }
81
82 // static
83 void TabWebContentsTracker::AddObserver(Observer* observer) {
84 GetInstance()->observer_list_.AddObserver(observer);
85 }
86
87 // static
88 void TabWebContentsTracker::RemoveObserver(Observer* observer) {
89 GetInstance()->observer_list_.RemoveObserver(observer);
90 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698