OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_UI_BROWSER_ITERATOR_H_ | |
6 #define CHROME_BROWSER_UI_BROWSER_ITERATOR_H_ | |
7 | |
8 #include "base/macros.h" | |
9 #include "chrome/browser/ui/browser_list.h" | |
10 #include "chrome/browser/ui/host_desktop.h" | |
11 | |
12 class Browser; | |
13 | |
14 namespace chrome { | |
15 | |
16 // TODO(scottmg): Remove this file entirely. http://crbug.com/558054. | |
17 | |
18 // Iterates over all existing browsers (potentially across multiple desktops). | |
19 // Note: to iterate only over the browsers of a specific desktop, use the | |
20 // const_iterator of a given BrowserList instead. | |
21 // | |
22 // Example: | |
23 // for (BrowserIterator iterator; !iterator.done(); iterator.Next()) { | |
24 // Browser* cur = *iterator; | |
25 // -or- | |
26 // iterator->OperationOnBrowser(); | |
27 // ... | |
28 // } | |
29 class BrowserIterator { | |
30 public: | |
31 BrowserIterator(); | |
32 ~BrowserIterator(); | |
33 | |
34 // Returns true if this iterator is past the last Browser. | |
35 bool done() const { | |
36 // |iterator_| is never at the end of a list unless it is done (it | |
37 // immediately moves to the next browser list upon hitting the end of the | |
38 // current list unless there are no remaining empty browser lists). | |
39 return iterator_ == browser_list_->end(); | |
40 } | |
41 | |
42 // Returns the current Browser, valid as long as !done(). | |
43 Browser* operator->() const { return *iterator_; } | |
44 Browser* operator*() const { return *iterator_; } | |
45 | |
46 // Advances |iterator_| to the next browser. | |
47 void Next(); | |
48 | |
49 private: | |
50 // The BrowserList being iterated over. | |
51 BrowserList* browser_list_; | |
52 | |
53 // The underlying iterator over browsers in |browser_list_|. | |
54 BrowserList::const_iterator iterator_; | |
55 | |
56 DISALLOW_COPY_AND_ASSIGN(BrowserIterator); | |
57 }; | |
58 | |
59 } // namespace chrome | |
60 | |
61 #endif // CHROME_BROWSER_UI_BROWSER_ITERATOR_H_ | |
OLD | NEW |