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