summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/browser_iterator.cc
diff options
context:
space:
mode:
authorgab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-30 20:57:17 +0000
committergab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-30 20:57:17 +0000
commit1038ecb77198ad02d6e6f8c4fbe46584a31f32fd (patch)
treee1fb814b66987590d8dfdc19701d10b3e7aaec41 /chrome/browser/ui/browser_iterator.cc
parent172a3a8063c95204c3279e5a36dc0ecb4c1b50be (diff)
downloadchromium_src-1038ecb77198ad02d6e6f8c4fbe46584a31f32fd.zip
chromium_src-1038ecb77198ad02d6e6f8c4fbe46584a31f32fd.tar.gz
chromium_src-1038ecb77198ad02d6e6f8c4fbe46584a31f32fd.tar.bz2
Introduce BrowserIterator.
An iterator meant to iterate over all the browsers in BrowserListImpls across multiple desktops (i.e. multiple HostDesktopTypes). As a first step, used it in TabContentsIterator (pretty much bringing back the implementation to the one that was there prior to https://codereview.chromium.org/11316340/ -- except that the iterator is now aware of multiple desktops). Another CL will follow in which all BrowserList::const_iterator, etc. methods will be replaced by BrowserIterator. The interface of BrowserIterator is derived from the interface of TabContentsIterator for consistency (which is being slightly tweaked in parallel in https://codereview.chromium.org/12049038/). BUG=129187 Review URL: https://chromiumcodereview.appspot.com/12038053 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@179695 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/browser_iterator.cc')
-rw-r--r--chrome/browser/ui/browser_iterator.cc33
1 files changed, 33 insertions, 0 deletions
diff --git a/chrome/browser/ui/browser_iterator.cc b/chrome/browser/ui/browser_iterator.cc
new file mode 100644
index 0000000..73571d5
--- /dev/null
+++ b/chrome/browser/ui/browser_iterator.cc
@@ -0,0 +1,33 @@
+// 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/browser_iterator.h"
+
+namespace chrome {
+
+BrowserIterator::BrowserIterator()
+ : current_browser_list_(
+ BrowserListImpl::GetInstance(HOST_DESKTOP_TYPE_FIRST)),
+ current_iterator_(current_browser_list_->begin()),
+ next_desktop_type_(
+ static_cast<HostDesktopType>(HOST_DESKTOP_TYPE_FIRST + 1)) {
+ NextBrowserListIfAtEnd();
+}
+
+void BrowserIterator::Next() {
+ ++current_iterator_;
+ NextBrowserListIfAtEnd();
+}
+
+void BrowserIterator::NextBrowserListIfAtEnd() {
+ // Make sure either |current_iterator_| is valid or done().
+ while (current_iterator_ == current_browser_list_->end() &&
+ next_desktop_type_ < HOST_DESKTOP_TYPE_COUNT) {
+ current_browser_list_ = BrowserListImpl::GetInstance(next_desktop_type_);
+ current_iterator_ = current_browser_list_->begin();
+ next_desktop_type_ = static_cast<HostDesktopType>(next_desktop_type_ + 1);
+ }
+}
+
+} // namespace chrome