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