OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CONTENT_PUBLIC_BROWSER_BROWSER_CHILD_PROCESS_HOST_ITERATOR_H_ |
| 6 #define CONTENT_PUBLIC_BROWSER_BROWSER_CHILD_PROCESS_HOST_ITERATOR_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <list> |
| 10 |
| 11 #include "content/common/content_export.h" |
| 12 #include "content/public/common/process_type.h" |
| 13 |
| 14 class BrowserChildProcessHost; |
| 15 |
| 16 namespace IPC { |
| 17 class Message; |
| 18 } |
| 19 |
| 20 namespace content { |
| 21 |
| 22 class BrowserChildProcessHostDelegate; |
| 23 struct ChildProcessData; |
| 24 |
| 25 // This class allows iteration through either all child processes, or ones of a |
| 26 // specific type, depending on which constructor is used. Note that this should |
| 27 // be done from the IO thread and that the iterator should not be kept around as |
| 28 // it may be invalidated on subsequent event processing in the event loop. |
| 29 class CONTENT_EXPORT BrowserChildProcessHostIterator { |
| 30 public: |
| 31 BrowserChildProcessHostIterator(); |
| 32 explicit BrowserChildProcessHostIterator(content::ProcessType type); |
| 33 |
| 34 // These methods work on the current iterator object. Only call them if |
| 35 // Done() returns false. |
| 36 bool operator++(); |
| 37 bool Done(); |
| 38 const ChildProcessData& GetData(); |
| 39 bool Send(IPC::Message* message); |
| 40 BrowserChildProcessHostDelegate* GetDelegate(); |
| 41 |
| 42 private: |
| 43 bool all_; |
| 44 content::ProcessType type_; |
| 45 std::list<BrowserChildProcessHost*>::iterator iterator_; |
| 46 }; |
| 47 |
| 48 // Helper class so that subclasses of BrowserChildProcessHostDelegate can be |
| 49 // iterated with no casting needing. Note that because of the components build, |
| 50 // this class can only be used by BCPHD implementations that live in content, |
| 51 // otherwise link errors will result. |
| 52 template <class T> |
| 53 class CONTENT_EXPORT BrowserChildProcessHostTypeIterator |
| 54 : public BrowserChildProcessHostIterator { |
| 55 public: |
| 56 explicit BrowserChildProcessHostTypeIterator(content::ProcessType type) |
| 57 : BrowserChildProcessHostIterator(type) {} |
| 58 T* operator->() { |
| 59 return static_cast<T*>(GetDelegate()); |
| 60 } |
| 61 T* operator*() { |
| 62 return static_cast<T*>(GetDelegate()); |
| 63 } |
| 64 }; |
| 65 |
| 66 }; // namespace content |
| 67 |
| 68 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_CHILD_PROCESS_HOST_ITERATOR_H_ |
OLD | NEW |