| 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 #ifndef CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_ITERATOR_H_ | 5 #ifndef CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_ITERATOR_H_ |
| 6 #define CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_ITERATOR_H_ | 6 #define CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_ITERATOR_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "chrome/browser/ui/browser_list.h" | 12 #include "chrome/browser/ui/browser_list.h" |
| 13 | 13 |
| 14 class TabContents; | 14 class TabContents; |
| 15 typedef TabContents TabContentsWrapper; | |
| 16 | 15 |
| 17 // Iterates through all web view hosts in all browser windows. Because the | 16 // Iterates through all web view hosts in all browser windows. Because the |
| 18 // renderers act asynchronously, getting a host through this interface does | 17 // renderers act asynchronously, getting a host through this interface does |
| 19 // not guarantee that the renderer is ready to go. Doing anything to affect | 18 // not guarantee that the renderer is ready to go. Doing anything to affect |
| 20 // browser windows or tabs while iterating may cause incorrect behavior. | 19 // browser windows or tabs while iterating may cause incorrect behavior. |
| 21 // | 20 // |
| 22 // Example: | 21 // Example: |
| 23 // for (TabContentsIterator iterator; !iterator.done(); ++iterator) { | 22 // for (TabContentsIterator iterator; !iterator.done(); ++iterator) { |
| 24 // TabContentsWrapper* cur = *iterator; | 23 // TabContents* cur = *iterator; |
| 25 // -or- | 24 // -or- |
| 26 // iterator->operationOnTabContents(); | 25 // iterator->operationOnTabContents(); |
| 27 // ... | 26 // ... |
| 28 // } | 27 // } |
| 29 class TabContentsIterator { | 28 class TabContentsIterator { |
| 30 public: | 29 public: |
| 31 TabContentsIterator(); | 30 TabContentsIterator(); |
| 32 | 31 |
| 33 // Returns true if we are past the last Browser. | 32 // Returns true if we are past the last Browser. |
| 34 bool done() const { return cur_ == NULL; } | 33 bool done() const { return cur_ == NULL; } |
| 35 | 34 |
| 36 // Returns the Browser instance associated with the current | 35 // Returns the Browser instance associated with the current |
| 37 // TabContentsWrapper. Valid as long as !done() | 36 // TabContents. Valid as long as !done() |
| 38 Browser* browser() const { | 37 Browser* browser() const { |
| 39 if (browser_iterator_ != BrowserList::end()) | 38 if (browser_iterator_ != BrowserList::end()) |
| 40 return *browser_iterator_; | 39 return *browser_iterator_; |
| 41 return NULL; | 40 return NULL; |
| 42 } | 41 } |
| 43 | 42 |
| 44 // Returns the current TabContentsWrapper, valid as long as !Done() | 43 // Returns the current TabContents, valid as long as !Done() |
| 45 TabContentsWrapper* operator->() const { | 44 TabContents* operator->() const { |
| 46 return cur_; | 45 return cur_; |
| 47 } | 46 } |
| 48 TabContentsWrapper* operator*() const { | 47 TabContents* operator*() const { |
| 49 return cur_; | 48 return cur_; |
| 50 } | 49 } |
| 51 | 50 |
| 52 // Incrementing operators, valid as long as !Done() | 51 // Incrementing operators, valid as long as !Done() |
| 53 TabContentsWrapper* operator++() { // ++preincrement | 52 TabContents* operator++() { // ++preincrement |
| 54 Advance(); | 53 Advance(); |
| 55 return cur_; | 54 return cur_; |
| 56 } | 55 } |
| 57 TabContentsWrapper* operator++(int) { // postincrement++ | 56 TabContents* operator++(int) { // postincrement++ |
| 58 TabContentsWrapper* tmp = cur_; | 57 TabContents* tmp = cur_; |
| 59 Advance(); | 58 Advance(); |
| 60 return tmp; | 59 return tmp; |
| 61 } | 60 } |
| 62 | 61 |
| 63 private: | 62 private: |
| 64 // Loads the next host into Cur. This is designed so that for the initial | 63 // Loads the next host into Cur. This is designed so that for the initial |
| 65 // call when browser_iterator_ points to the first browser and | 64 // call when browser_iterator_ points to the first browser and |
| 66 // web_view_index_ is -1, it will fill the first host. | 65 // web_view_index_ is -1, it will fill the first host. |
| 67 void Advance(); | 66 void Advance(); |
| 68 | 67 |
| 69 // Iterator over all the Browser objects. | 68 // Iterator over all the Browser objects. |
| 70 BrowserList::const_iterator browser_iterator_; | 69 BrowserList::const_iterator browser_iterator_; |
| 71 | 70 |
| 72 // tab index into the current Browser of the current web view | 71 // tab index into the current Browser of the current web view |
| 73 int web_view_index_; | 72 int web_view_index_; |
| 74 | 73 |
| 75 // iterator over the TabContentsWrappers doing background printing. | 74 // iterator over the TabContentss doing background printing. |
| 76 std::set<TabContentsWrapper*>::const_iterator bg_printing_iterator_; | 75 std::set<TabContents*>::const_iterator bg_printing_iterator_; |
| 77 | 76 |
| 78 // Current TabContentsWrapper, or NULL if we're at the end of the list. This | 77 // Current TabContents, or NULL if we're at the end of the list. This |
| 79 // can be extracted given the browser iterator and index, but it's nice to | 78 // can be extracted given the browser iterator and index, but it's nice to |
| 80 // cache this since the caller may access the current host many times. | 79 // cache this since the caller may access the current host many times. |
| 81 TabContentsWrapper* cur_; | 80 TabContents* cur_; |
| 82 | 81 |
| 83 DISALLOW_COPY_AND_ASSIGN(TabContentsIterator); | 82 DISALLOW_COPY_AND_ASSIGN(TabContentsIterator); |
| 84 }; | 83 }; |
| 85 | 84 |
| 86 #endif // CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_ITERATOR_H_ | 85 #endif // CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_ITERATOR_H_ |
| OLD | NEW |