Add ability to gather metrics to BubbleManager.
[chromium-blink-merge.git] / chrome / browser / ui / browser_iterator.h
blob38d8a193338a3a39f97c87185d5f08091f22ccb2
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.
5 #ifndef CHROME_BROWSER_UI_BROWSER_ITERATOR_H_
6 #define CHROME_BROWSER_UI_BROWSER_ITERATOR_H_
8 #include "chrome/browser/ui/browser_list.h"
9 #include "chrome/browser/ui/host_desktop.h"
11 class Browser;
13 namespace chrome {
15 // Iterates over all existing browsers (potentially across multiple desktops).
16 // Note: to iterate only over the browsers of a specific desktop, use the
17 // const_iterator of a given BrowserList instead.
19 // Example:
20 // for (BrowserIterator iterator; !iterator.done(); iterator.Next()) {
21 // Browser* cur = *iterator;
22 // -or-
23 // iterator->OperationOnBrowser();
24 // ...
25 // }
26 class BrowserIterator {
27 public:
28 BrowserIterator();
29 ~BrowserIterator();
31 // Returns true if this iterator is past the last Browser.
32 bool done() const {
33 // |current_iterator_| is never at the end of a list unless it is done (it
34 // immediately moves to the next browser list upon hitting the end of the
35 // current list unless there are no remaining empty browser lists).
36 return current_iterator_ == current_browser_list_->end();
39 // Returns the current Browser, valid as long as !done().
40 Browser* operator->() const {
41 return *current_iterator_;
43 Browser* operator*() const {
44 return *current_iterator_;
47 // Advances |current_iterator_| to the next browser.
48 void Next();
50 private:
51 // If |current_iterator_| is at |current_browser_list_->end()|, advance to the
52 // next non-empty browser list. After a call to this method: either
53 // |current_iterator_| is valid or done().
54 void NextBrowserListIfAtEnd();
56 // The BrowserList currently being iterated over. Instances of this class do
57 // not own this pointer.
58 BrowserList* current_browser_list_;
60 // The underlying iterator over browsers in |current_browser_list_|.
61 BrowserList::const_iterator current_iterator_;
63 // The next HostDesktopType to iterate over when |current_iterator_| reaches
64 // |current_browser_list_->end()|.
65 HostDesktopType next_desktop_type_;
67 DISALLOW_COPY_AND_ASSIGN(BrowserIterator);
70 } // namespace chrome
72 #endif // CHROME_BROWSER_UI_BROWSER_ITERATOR_H_