Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / ui / tab_contents / tab_contents_iterator.h
blob818658f604fc1056b6622e4ca0bbd4b95ece50b0
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_ITERATOR_H_
6 #define CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_ITERATOR_H_
8 #include <set>
10 #include "base/basictypes.h"
11 #include "chrome/browser/ui/browser_iterator.h"
13 namespace content {
14 class WebContents;
17 // Iterates through all web view hosts in all browser windows. Because the
18 // renderers act asynchronously, getting a host through this interface does
19 // not guarantee that the renderer is ready to go. Doing anything to affect
20 // browser windows or tabs while iterating may cause incorrect behavior.
22 // Example:
23 // for (TabContentsIterator iterator; !iterator.done(); iterator.Next()) {
24 // WebContents* cur = *iterator;
25 // -or-
26 // iterator->OperationOnWebContents();
27 // ...
28 // }
29 class TabContentsIterator {
30 public:
31 TabContentsIterator();
33 // Returns true if we are past the last Browser.
34 bool done() const { return cur_ == NULL; }
36 // Returns the Browser instance associated with the current
37 // WebContents. Valid as long as !done().
38 Browser* browser() const {
39 if (!browser_iterator_.done())
40 return *browser_iterator_;
41 return NULL;
44 // Returns the current WebContents, valid as long as !done().
45 content::WebContents* operator->() const {
46 return cur_;
48 content::WebContents* operator*() const {
49 return cur_;
52 // Loads the next host into |cur_|. This is designed so that for the initial
53 // call from the constructor, when browser_iterator_ points to the first
54 // Browser and web_view_index_ is -1, it will fill the first host.
55 void Next();
57 private:
58 // Tab index into the current Browser of the current web view.
59 int web_view_index_;
61 // Current WebContents, or NULL if we're at the end of the list. This
62 // can be extracted given the browser iterator and index, but it's nice to
63 // cache this since the caller may access the current host many times.
64 content::WebContents* cur_;
66 // An iterator over all the browsers.
67 chrome::BrowserIterator browser_iterator_;
69 DISALLOW_COPY_AND_ASSIGN(TabContentsIterator);
72 #endif // CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_ITERATOR_H_