| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/tab_contents/tab_contents_iterator.h" | 5 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 11 | 11 |
| 12 TabContentsIterator::TabContentsIterator() | 12 TabContentsIterator::TabContentsIterator() |
| 13 : web_view_index_(-1), | 13 : web_view_index_(-1), |
| 14 cur_(NULL) { | 14 cur_(NULL), |
| 15 browser_iterator_(BrowserList::GetInstance()->begin()) { |
| 15 // Load the first WebContents into |cur_|. | 16 // Load the first WebContents into |cur_|. |
| 16 Next(); | 17 Next(); |
| 17 } | 18 } |
| 18 | 19 |
| 19 void TabContentsIterator::Next() { | 20 void TabContentsIterator::Next() { |
| 20 // The current WebContents should be valid unless we are at the beginning. | 21 // The current WebContents should be valid unless we are at the beginning. |
| 21 DCHECK(cur_ || web_view_index_ == -1) << "Trying to advance past the end"; | 22 DCHECK(cur_ || web_view_index_ == -1) << "Trying to advance past the end"; |
| 22 | 23 |
| 23 // Update |cur_| to the next WebContents in the list. | 24 // Update |cur_| to the next WebContents in the list. |
| 24 while (!browser_iterator_.done()) { | 25 while (browser_iterator_ != BrowserList::GetInstance()->end()) { |
| 25 if (++web_view_index_ >= browser_iterator_->tab_strip_model()->count()) { | 26 if (++web_view_index_ >= (*browser_iterator_)->tab_strip_model()->count()) { |
| 26 // Advance to the next Browser in the list. | 27 // Advance to the next Browser in the list. |
| 27 browser_iterator_.Next(); | 28 ++browser_iterator_; |
| 28 web_view_index_ = -1; | 29 web_view_index_ = -1; |
| 29 continue; | 30 continue; |
| 30 } | 31 } |
| 31 | 32 |
| 32 content::WebContents* next_tab = browser_iterator_->tab_strip_model() | 33 content::WebContents* next_tab = (*browser_iterator_)->tab_strip_model() |
| 33 ->GetWebContentsAt(web_view_index_); | 34 ->GetWebContentsAt(web_view_index_); |
| 34 if (next_tab) { | 35 if (next_tab) { |
| 35 cur_ = next_tab; | 36 cur_ = next_tab; |
| 36 return; | 37 return; |
| 37 } | 38 } |
| 38 } | 39 } |
| 39 // Reached the end. | 40 // Reached the end. |
| 40 cur_ = NULL; | 41 cur_ = NULL; |
| 41 } | 42 } |
| OLD | NEW |