Index: chrome/browser/ui/browser_list.cc |
diff --git a/chrome/browser/ui/browser_list.cc b/chrome/browser/ui/browser_list.cc |
index fd9eead15cecc61fe75868015814f32c5560ec35..f87f4bc3fa70698ae3a983cd8fbe04e21081904f 100644 |
--- a/chrome/browser/ui/browser_list.cc |
+++ b/chrome/browser/ui/browser_list.cc |
@@ -17,6 +17,7 @@ |
#include "chrome/browser/printing/background_printing_manager.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/profiles/profile_manager.h" |
+#include "chrome/browser/ui/browser.h" |
#include "chrome/browser/ui/browser_window.h" |
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
#include "chrome/common/chrome_notification_types.h" |
@@ -115,14 +116,6 @@ class BrowserActivityObserver : public content::NotificationObserver { |
BrowserActivityObserver* activity_observer = NULL; |
-// Type used to indicate to match anything. |
-const int kMatchAny = 0; |
- |
-// See BrowserMatches for details. |
-const int kMatchOriginalProfile = 1 << 0; |
-const int kMatchCanSupportWindowFeature = 1 << 1; |
-const int kMatchTabbed = 1 << 2; |
- |
static BrowserList::BrowserVector& browsers() { |
CR_DEFINE_STATIC_LOCAL(BrowserList::BrowserVector, browser_vector, ()); |
return browser_vector; |
@@ -139,70 +132,6 @@ static ObserverList<BrowserList::Observer>& observers() { |
return observer_vector; |
} |
-// Returns true if the specified |browser| matches the specified arguments. |
-// |match_types| is a bitmask dictating what parameters to match: |
-// . If it contains kMatchOriginalProfile then the original profile of the |
-// browser must match |profile->GetOriginalProfile()|. This is used to match |
-// incognito windows. |
-// . If it contains kMatchCanSupportWindowFeature |
-// |CanSupportWindowFeature(window_feature)| must return true. |
-// . If it contains kMatchTabbed, the browser must be a tabbed browser. |
-bool BrowserMatches(Browser* browser, |
- Profile* profile, |
- Browser::WindowFeature window_feature, |
- uint32 match_types) { |
- if (match_types & kMatchCanSupportWindowFeature && |
- !browser->CanSupportWindowFeature(window_feature)) { |
- return false; |
- } |
- |
- if (match_types & kMatchOriginalProfile) { |
- if (browser->profile()->GetOriginalProfile() != |
- profile->GetOriginalProfile()) |
- return false; |
- } else if (browser->profile() != profile) { |
- return false; |
- } |
- |
- if (match_types & kMatchTabbed) |
- return browser->is_type_tabbed(); |
- |
- return true; |
-} |
- |
-// Returns the first browser in the specified iterator that returns true from |
-// |BrowserMatches|, or null if no browsers match the arguments. See |
-// |BrowserMatches| for details on the arguments. |
-template <class T> |
-Browser* FindBrowserMatching(const T& begin, |
- const T& end, |
- Profile* profile, |
- Browser::WindowFeature window_feature, |
- uint32 match_types) { |
- for (T i = begin; i != end; ++i) { |
- if (BrowserMatches(*i, profile, window_feature, match_types)) |
- return *i; |
- } |
- return NULL; |
-} |
- |
-Browser* FindBrowserWithTabbedOrAnyType(Profile* profile, |
- bool match_tabbed, |
- bool match_original_profiles) { |
- uint32 match_types = kMatchAny; |
- if (match_tabbed) |
- match_types |= kMatchTabbed; |
- if (match_original_profiles) |
- match_types |= kMatchOriginalProfile; |
- Browser* browser = FindBrowserMatching( |
- BrowserList::begin_last_active(), BrowserList::end_last_active(), |
- profile, Browser::FEATURE_NONE, match_types); |
- // Fall back to a forward scan of all Browsers if no active one was found. |
- return browser ? browser : |
- FindBrowserMatching(BrowserList::begin(), BrowserList::end(), profile, |
- Browser::FEATURE_NONE, match_types); |
-} |
- |
printing::BackgroundPrintingManager* GetBackgroundPrintingManager() { |
return g_browser_process->background_printing_manager(); |
} |
@@ -461,10 +390,8 @@ void BrowserList::CloseAllBrowsersWithProfile(Profile* profile) { |
BrowserVector browsers_to_close; |
for (BrowserList::const_iterator i = BrowserList::begin(); |
i != BrowserList::end(); ++i) { |
- if (BrowserMatches(*i, profile, Browser::FEATURE_NONE, |
- kMatchOriginalProfile)) { |
+ if ((*i)->profile()->GetOriginalProfile() == profile->GetOriginalProfile()) |
browsers_to_close.push_back(*i); |
- } |
} |
for (BrowserVector::const_iterator i = browsers_to_close.begin(); |
@@ -601,15 +528,6 @@ void BrowserList::SessionEnding() { |
} |
// static |
-bool BrowserList::HasBrowserWithProfile(Profile* profile) { |
- return FindBrowserMatching(BrowserList::begin(), |
- BrowserList::end(), |
- profile, |
- Browser::FEATURE_NONE, |
- kMatchAny) != NULL; |
-} |
- |
-// static |
int BrowserList::keep_alive_count_ = 0; |
// static |
@@ -690,80 +608,6 @@ Browser* BrowserList::GetLastActive() { |
} |
// static |
-Browser* BrowserList::GetLastActiveWithProfile(Profile* profile) { |
- // We are only interested in last active browsers, so we don't fall back to |
- // all browsers like FindBrowserWith* do. |
- return FindBrowserMatching( |
- BrowserList::begin_last_active(), BrowserList::end_last_active(), profile, |
- Browser::FEATURE_NONE, kMatchAny); |
-} |
- |
-// static |
-Browser* BrowserList::FindTabbedBrowser(Profile* profile, |
- bool match_original_profiles) { |
- return FindBrowserWithTabbedOrAnyType(profile, |
- true, |
- match_original_profiles); |
-} |
- |
-// static |
-Browser* BrowserList::FindAnyBrowser(Profile* profile, |
- bool match_original_profiles) { |
- return FindBrowserWithTabbedOrAnyType(profile, |
- false, |
- match_original_profiles); |
-} |
- |
-// static |
-Browser* BrowserList::FindBrowserWithFeature(Profile* profile, |
- Browser::WindowFeature feature) { |
- Browser* browser = FindBrowserMatching( |
- BrowserList::begin_last_active(), BrowserList::end_last_active(), |
- profile, feature, kMatchCanSupportWindowFeature); |
- // Fall back to a forward scan of all Browsers if no active one was found. |
- return browser ? browser : |
- FindBrowserMatching(BrowserList::begin(), BrowserList::end(), profile, |
- feature, kMatchCanSupportWindowFeature); |
-} |
- |
-// static |
-Browser* BrowserList::FindBrowserWithProfile(Profile* profile) { |
- return FindAnyBrowser(profile, false); |
-} |
- |
-// static |
-Browser* BrowserList::FindBrowserWithID(SessionID::id_type desired_id) { |
- for (BrowserList::const_iterator i = BrowserList::begin(); |
- i != BrowserList::end(); ++i) { |
- if ((*i)->session_id().id() == desired_id) |
- return *i; |
- } |
- return NULL; |
-} |
- |
-// static |
-Browser* BrowserList::FindBrowserWithWindow(gfx::NativeWindow window) { |
- for (BrowserList::const_iterator it = BrowserList::begin(); |
- it != BrowserList::end(); |
- ++it) { |
- Browser* browser = *it; |
- if (browser->window() && browser->window()->GetNativeHandle() == window) |
- return browser; |
- } |
- return NULL; |
-} |
- |
-// static |
-Browser* BrowserList::FindBrowserWithWebContents(WebContents* web_contents) { |
- DCHECK(web_contents); |
- for (TabContentsIterator it; !it.done(); ++it) { |
- if (it->web_contents() == web_contents) |
- return it.browser(); |
- } |
- return NULL; |
-} |
- |
-// static |
BrowserList::const_reverse_iterator BrowserList::begin_last_active() { |
return last_active_browsers().rbegin(); |
} |
@@ -774,31 +618,6 @@ BrowserList::const_reverse_iterator BrowserList::end_last_active() { |
} |
// static |
-size_t BrowserList::GetBrowserCount(Profile* profile) { |
- size_t result = 0; |
- for (BrowserList::const_iterator i = BrowserList::begin(); |
- i != BrowserList::end(); ++i) { |
- if (BrowserMatches(*i, profile, Browser::FEATURE_NONE, kMatchAny)) { |
- ++result; |
- } |
- } |
- return result; |
-} |
- |
-// static |
-size_t BrowserList::GetBrowserCountForType(Profile* profile, |
- bool match_tabbed) { |
- size_t result = 0; |
- for (BrowserList::const_iterator i = BrowserList::begin(); |
- i != BrowserList::end(); ++i) { |
- if (BrowserMatches(*i, profile, Browser::FEATURE_NONE, |
- match_tabbed ? kMatchTabbed : kMatchAny)) |
- ++result; |
- } |
- return result; |
-} |
- |
-// static |
bool BrowserList::IsOffTheRecordSessionActive() { |
for (BrowserList::const_iterator i = BrowserList::begin(); |
i != BrowserList::end(); ++i) { |