diff options
author | gab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-14 04:18:49 +0000 |
---|---|---|
committer | gab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-14 04:18:49 +0000 |
commit | edd3cd1925df11fae7349e034af243eab4689e86 (patch) | |
tree | 3b3ae639b912a499e3190be0767ae96bae32d830 | |
parent | 7c60f50438f48400252f330c313a99897b5b7ca9 (diff) | |
download | chromium_src-edd3cd1925df11fae7349e034af243eab4689e86.zip chromium_src-edd3cd1925df11fae7349e034af243eab4689e86.tar.gz chromium_src-edd3cd1925df11fae7349e034af243eab4689e86.tar.bz2 |
Make BrowserList::(Add|Remove)Observer add the observer to every desktop's browser list.
Also make it impossible to call AddObserver on an individual list from outside BrowserList.
This is to make sure the paradigm becomes that the consumer code is in charge of checking for HostDesktopType (should he care) upon receiving an event; allowing AddObserver to be called on an individual list would put burden on the reader to understand whether the events are coming from multiple browser lists or a single one (which seems unecessary for now).
BUG=129187
Review URL: https://chromiumcodereview.appspot.com/12258019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182384 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/automation/testing_automation_provider.cc | 9 | ||||
-rw-r--r-- | chrome/browser/ui/browser_list.cc | 13 | ||||
-rw-r--r-- | chrome/browser/ui/browser_list.h | 7 | ||||
-rw-r--r-- | chrome/browser/ui/browser_list_impl.h | 13 |
4 files changed, 27 insertions, 15 deletions
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index adb1e94..0918e7f 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -92,6 +92,7 @@ #include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_iterator.h" +#include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_list_impl.h" #include "chrome/browser/ui/browser_tabstrip.h" #include "chrome/browser/ui/browser_window.h" @@ -253,9 +254,7 @@ TestingAutomationProvider::TestingAutomationProvider(Profile* profile) , power_manager_observer_(NULL) #endif { - // The automation layer doesn't support non-native desktops. - chrome::BrowserListImpl::GetInstance( - chrome::HOST_DESKTOP_TYPE_NATIVE)->AddObserver(this); + BrowserList::AddObserver(this); registrar_.Add(this, chrome::NOTIFICATION_SESSION_END, content::NotificationService::AllSources()); #if defined(OS_CHROMEOS) @@ -267,9 +266,7 @@ TestingAutomationProvider::~TestingAutomationProvider() { #if defined(OS_CHROMEOS) RemoveChromeosObservers(); #endif - // The automation layer doesn't support non-native desktops. - chrome::BrowserListImpl::GetInstance( - chrome::HOST_DESKTOP_TYPE_NATIVE)->RemoveObserver(this); + BrowserList::RemoveObserver(this); } IPC::Channel::Mode TestingAutomationProvider::GetChannelMode( diff --git a/chrome/browser/ui/browser_list.cc b/chrome/browser/ui/browser_list.cc index ef5f75f..8ac380a 100644 --- a/chrome/browser/ui/browser_list.cc +++ b/chrome/browser/ui/browser_list.cc @@ -10,6 +10,7 @@ #include "chrome/browser/ui/browser_list_impl.h" #include "chrome/browser/ui/browser_list_observer.h" #include "chrome/browser/ui/browser_window.h" +#include "chrome/browser/ui/host_desktop.h" using content::WebContents; @@ -35,12 +36,20 @@ void BrowserList::RemoveBrowser(Browser* browser) { // static void BrowserList::AddObserver(chrome::BrowserListObserver* observer) { - GetNativeList()->AddObserver(observer); + for (chrome::HostDesktopType t = chrome::HOST_DESKTOP_TYPE_FIRST; + t < chrome::HOST_DESKTOP_TYPE_COUNT; + t = static_cast<chrome::HostDesktopType>(t + 1)) { + chrome::BrowserListImpl::GetInstance(t)->AddObserver(observer); + } } // static void BrowserList::RemoveObserver(chrome::BrowserListObserver* observer) { - GetNativeList()->RemoveObserver(observer); + for (chrome::HostDesktopType t = chrome::HOST_DESKTOP_TYPE_FIRST; + t < chrome::HOST_DESKTOP_TYPE_COUNT; + t = static_cast<chrome::HostDesktopType>(t + 1)) { + chrome::BrowserListImpl::GetInstance(t)->RemoveObserver(observer); + } } void BrowserList::CloseAllBrowsersWithProfile(Profile* profile) { diff --git a/chrome/browser/ui/browser_list.h b/chrome/browser/ui/browser_list.h index f3103cf..eb48b2f 100644 --- a/chrome/browser/ui/browser_list.h +++ b/chrome/browser/ui/browser_list.h @@ -22,12 +22,13 @@ class BrowserList { typedef std::vector<Browser*> BrowserVector; typedef BrowserVector::const_reverse_iterator const_reverse_iterator; - // Adds and removes browsers from the global list. The browser object should - // be valid BEFORE these calls (for the benefit of observers), so notify and - // THEN delete the object. + // Adds and removes browsers from the list they are associated with. The + // browser object should be valid BEFORE these calls (for the benefit of + // observers), so notify and THEN delete the object. static void AddBrowser(Browser* browser); static void RemoveBrowser(Browser* browser); + // Adds and removes |observer| from the observer list of each desktop. static void AddObserver(chrome::BrowserListObserver* observer); static void RemoveObserver(chrome::BrowserListObserver* observer); diff --git a/chrome/browser/ui/browser_list_impl.h b/chrome/browser/ui/browser_list_impl.h index 2801a6e..3ff167c 100644 --- a/chrome/browser/ui/browser_list_impl.h +++ b/chrome/browser/ui/browser_list_impl.h @@ -6,10 +6,10 @@ #define CHROME_BROWSER_UI_BROWSER_LIST_IMPL_H_ #include "base/observer_list.h" +#include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/host_desktop.h" class Browser; -class BrowserList; class Profile; namespace chrome { @@ -33,9 +33,6 @@ class BrowserListImpl { void AddBrowser(Browser* browser); void RemoveBrowser(Browser* browser); - void AddObserver(BrowserListObserver* observer); - void RemoveObserver(BrowserListObserver* observer); - // Called by Browser objects when their window is activated (focused). This // allows us to determine what the last active Browser was. void SetLastActive(Browser* browser); @@ -73,6 +70,14 @@ class BrowserListImpl { BrowserListImpl(); ~BrowserListImpl(); + // Only callable by BrowserList::(Add|Remove)Observer. + // TODO(gab): Merge BrowserListImpl into BrowserList removing the need for + // friend. + friend void BrowserList::AddObserver(chrome::BrowserListObserver*); + friend void BrowserList::RemoveObserver(chrome::BrowserListObserver*); + void AddObserver(BrowserListObserver* observer); + void RemoveObserver(BrowserListObserver* observer); + // Helper method to remove a browser instance from a list of browsers void RemoveBrowserFrom(Browser* browser, BrowserVector* browser_list); |