browser_child_process_host_iterator.cc revision f2477e01787aa58f445919b809d89e252beef54f
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#include "content/public/browser/browser_child_process_host_iterator.h" 6 7#include "base/logging.h" 8#include "content/browser/browser_child_process_host_impl.h" 9#include "content/public/browser/browser_thread.h" 10 11namespace content { 12 13BrowserChildProcessHostIterator::BrowserChildProcessHostIterator() 14 : all_(true), process_type_(PROCESS_TYPE_UNKNOWN) { 15 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)) << 16 "BrowserChildProcessHostIterator must be used on the IO thread."; 17 iterator_ = BrowserChildProcessHostImpl::GetIterator()->begin(); 18} 19 20BrowserChildProcessHostIterator::BrowserChildProcessHostIterator(int type) 21 : all_(false), process_type_(type) { 22 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)) << 23 "BrowserChildProcessHostIterator must be used on the IO thread."; 24 DCHECK_NE(PROCESS_TYPE_RENDERER, type) << 25 "BrowserChildProcessHostIterator doesn't work for renderer processes; " 26 "try RenderProcessHost::AllHostsIterator() instead."; 27 iterator_ = BrowserChildProcessHostImpl::GetIterator()->begin(); 28 if (!Done() && (*iterator_)->GetData().process_type != process_type_) 29 ++(*this); 30} 31 32bool BrowserChildProcessHostIterator::operator++() { 33 CHECK(!Done()); 34 do { 35 ++iterator_; 36 if (Done()) 37 break; 38 39 if (!all_ && (*iterator_)->GetData().process_type != process_type_) 40 continue; 41 42 return true; 43 } while (true); 44 45 return false; 46} 47 48bool BrowserChildProcessHostIterator::Done() { 49 return iterator_ == BrowserChildProcessHostImpl::GetIterator()->end(); 50} 51 52const ChildProcessData& BrowserChildProcessHostIterator::GetData() { 53 CHECK(!Done()); 54 return (*iterator_)->GetData(); 55} 56 57bool BrowserChildProcessHostIterator::Send(IPC::Message* message) { 58 CHECK(!Done()); 59 return (*iterator_)->Send(message); 60} 61 62BrowserChildProcessHostDelegate* 63 BrowserChildProcessHostIterator::GetDelegate() { 64 return (*iterator_)->delegate(); 65} 66 67} // namespace content 68