| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/browser_list.h" | 5 #include "chrome/browser/ui/browser_list.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 Profile* profile, | 148 Profile* profile, |
| 149 Browser::WindowFeature window_feature, | 149 Browser::WindowFeature window_feature, |
| 150 uint32 match_types) { | 150 uint32 match_types) { |
| 151 for (T i = begin; i != end; ++i) { | 151 for (T i = begin; i != end; ++i) { |
| 152 if (BrowserMatches(*i, profile, window_feature, match_types)) | 152 if (BrowserMatches(*i, profile, window_feature, match_types)) |
| 153 return *i; | 153 return *i; |
| 154 } | 154 } |
| 155 return NULL; | 155 return NULL; |
| 156 } | 156 } |
| 157 | 157 |
| 158 // Returns a vector of all browsers in the specified iterator that return true |
| 159 // from |BrowserMatches|, or an empty vector if no browsers match the |
| 160 // arguments. See |BrowserMatches| for details about the arguments. |
| 161 template <class T> |
| 162 std::vector<Browser*> FindAllBrowsersMatching( |
| 163 const T& begin, |
| 164 const T& end, |
| 165 Profile* profile, |
| 166 Browser::WindowFeature window_feature, |
| 167 uint32 match_types) { |
| 168 std::vector<Browser*> browsers; |
| 169 for (T i = begin; i != end; ++i) { |
| 170 if (BrowserMatches(*i, profile, window_feature, match_types)) |
| 171 browsers.push_back(*i); |
| 172 } |
| 173 return browsers; |
| 174 } |
| 175 |
| 158 Browser* FindBrowserWithTabbedOrAnyType(Profile* profile, | 176 Browser* FindBrowserWithTabbedOrAnyType(Profile* profile, |
| 159 bool match_tabbed, | 177 bool match_tabbed, |
| 160 bool match_incognito) { | 178 bool match_incognito) { |
| 161 uint32 match_types = kMatchAny; | 179 uint32 match_types = kMatchAny; |
| 162 if (match_tabbed) | 180 if (match_tabbed) |
| 163 match_types |= kMatchTabbed; | 181 match_types |= kMatchTabbed; |
| 164 if (match_incognito) | 182 if (match_incognito) |
| 165 match_types |= kMatchOriginalProfile; | 183 match_types |= kMatchOriginalProfile; |
| 166 Browser* browser = FindBrowserMatching( | 184 Browser* browser = FindBrowserMatching( |
| 167 BrowserList::begin_last_active(), BrowserList::end_last_active(), | 185 BrowserList::begin_last_active(), BrowserList::end_last_active(), |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 Browser* BrowserList::FindBrowserWithID(SessionID::id_type desired_id) { | 591 Browser* BrowserList::FindBrowserWithID(SessionID::id_type desired_id) { |
| 574 for (BrowserList::const_iterator i = BrowserList::begin(); | 592 for (BrowserList::const_iterator i = BrowserList::begin(); |
| 575 i != BrowserList::end(); ++i) { | 593 i != BrowserList::end(); ++i) { |
| 576 if ((*i)->session_id().id() == desired_id) | 594 if ((*i)->session_id().id() == desired_id) |
| 577 return *i; | 595 return *i; |
| 578 } | 596 } |
| 579 return NULL; | 597 return NULL; |
| 580 } | 598 } |
| 581 | 599 |
| 582 // static | 600 // static |
| 601 std::vector<Browser*> BrowserList::GetBrowsersWithProfile(Profile* profile) { |
| 602 std::vector<Browser*> browsers = FindAllBrowsersMatching( |
| 603 BrowserList::begin(), BrowserList::end(), profile, |
| 604 Browser::FEATURE_NONE, kMatchAny); |
| 605 return browsers; |
| 606 } |
| 607 |
| 608 // static |
| 583 size_t BrowserList::GetBrowserCountForType(Profile* profile, | 609 size_t BrowserList::GetBrowserCountForType(Profile* profile, |
| 584 bool match_tabbed) { | 610 bool match_tabbed) { |
| 585 size_t result = 0; | 611 size_t result = 0; |
| 586 for (BrowserList::const_iterator i = BrowserList::begin(); | 612 for (BrowserList::const_iterator i = BrowserList::begin(); |
| 587 i != BrowserList::end(); ++i) { | 613 i != BrowserList::end(); ++i) { |
| 588 if (BrowserMatches(*i, profile, Browser::FEATURE_NONE, | 614 if (BrowserMatches(*i, profile, Browser::FEATURE_NONE, |
| 589 match_tabbed ? kMatchTabbed : kMatchAny)) | 615 match_tabbed ? kMatchTabbed : kMatchAny)) |
| 590 ++result; | 616 ++result; |
| 591 } | 617 } |
| 592 return result; | 618 return result; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 // If no more TabContents from Browsers, check the BackgroundPrintingManager. | 682 // If no more TabContents from Browsers, check the BackgroundPrintingManager. |
| 657 while (bg_printing_iterator_ != GetBackgroundPrintingManager()->end()) { | 683 while (bg_printing_iterator_ != GetBackgroundPrintingManager()->end()) { |
| 658 cur_ = *bg_printing_iterator_; | 684 cur_ = *bg_printing_iterator_; |
| 659 CHECK(cur_); | 685 CHECK(cur_); |
| 660 ++bg_printing_iterator_; | 686 ++bg_printing_iterator_; |
| 661 return; | 687 return; |
| 662 } | 688 } |
| 663 // Reached the end - no more TabContents. | 689 // Reached the end - no more TabContents. |
| 664 cur_ = NULL; | 690 cur_ = NULL; |
| 665 } | 691 } |
| OLD | NEW |