Save errno for logging before potentially overwriting it.
[chromium-blink-merge.git] / content / public / browser / browser_child_process_host_iterator.cc
blob19eaec39333354bfbb65bbcc642e9c2fc283f570
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.
5 #include "content/public/browser/browser_child_process_host_iterator.h"
7 #include "base/logging.h"
8 #include "content/browser/browser_child_process_host_impl.h"
9 #include "content/public/browser/browser_thread.h"
11 namespace content {
13 BrowserChildProcessHostIterator::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();
20 BrowserChildProcessHostIterator::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 iterator_ = BrowserChildProcessHostImpl::GetIterator()->begin();
25 if (!Done() && (*iterator_)->GetData().process_type != process_type_)
26 ++(*this);
29 bool BrowserChildProcessHostIterator::operator++() {
30 CHECK(!Done());
31 do {
32 ++iterator_;
33 if (Done())
34 break;
36 if (!all_ && (*iterator_)->GetData().process_type != process_type_)
37 continue;
39 return true;
40 } while (true);
42 return false;
45 bool BrowserChildProcessHostIterator::Done() {
46 return iterator_ == BrowserChildProcessHostImpl::GetIterator()->end();
49 const ChildProcessData& BrowserChildProcessHostIterator::GetData() {
50 CHECK(!Done());
51 return (*iterator_)->GetData();
54 bool BrowserChildProcessHostIterator::Send(IPC::Message* message) {
55 CHECK(!Done());
56 return (*iterator_)->Send(message);
59 BrowserChildProcessHostDelegate*
60 BrowserChildProcessHostIterator::GetDelegate() {
61 return (*iterator_)->delegate();
64 } // namespace content