OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/public/browser/browser_child_process_host_iterator.h" | 5 #include "content/public/browser/browser_child_process_host_iterator.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/browser/browser_child_process_host_impl.h" | 8 #include "content/browser/browser_child_process_host_impl.h" |
9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
10 | 10 |
11 namespace content { | 11 namespace content { |
12 | 12 |
13 BrowserChildProcessHostIterator::BrowserChildProcessHostIterator() | 13 BrowserChildProcessHostIterator::BrowserChildProcessHostIterator() |
14 : all_(true), type_(content::PROCESS_TYPE_UNKNOWN) { | 14 : all_(true), process_type_(PROCESS_TYPE_UNKNOWN) { |
15 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)) << | 15 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)) << |
16 "BrowserChildProcessHostIterator must be used on the IO thread."; | 16 "BrowserChildProcessHostIterator must be used on the IO thread."; |
17 iterator_ = BrowserChildProcessHostImpl::GetIterator()->begin(); | 17 iterator_ = BrowserChildProcessHostImpl::GetIterator()->begin(); |
18 } | 18 } |
19 | 19 |
20 BrowserChildProcessHostIterator::BrowserChildProcessHostIterator( | 20 BrowserChildProcessHostIterator::BrowserChildProcessHostIterator(int type) |
21 content::ProcessType type) | 21 : all_(false), process_type_(type) { |
22 : all_(false), type_(type) { | |
23 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)) << | 22 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)) << |
24 "BrowserChildProcessHostIterator must be used on the IO thread."; | 23 "BrowserChildProcessHostIterator must be used on the IO thread."; |
25 iterator_ = BrowserChildProcessHostImpl::GetIterator()->begin(); | 24 iterator_ = BrowserChildProcessHostImpl::GetIterator()->begin(); |
26 if (!Done() && (*iterator_)->GetData().type != type_) | 25 if (!Done() && (*iterator_)->GetData().process_type != process_type_) |
27 ++(*this); | 26 ++(*this); |
28 } | 27 } |
29 | 28 |
30 bool BrowserChildProcessHostIterator::operator++() { | 29 bool BrowserChildProcessHostIterator::operator++() { |
31 CHECK(!Done()); | 30 CHECK(!Done()); |
32 do { | 31 do { |
33 ++iterator_; | 32 ++iterator_; |
34 if (Done()) | 33 if (Done()) |
35 break; | 34 break; |
36 | 35 |
37 if (!all_ && (*iterator_)->GetData().type != type_) | 36 if (!all_ && (*iterator_)->GetData().process_type != process_type_) |
38 continue; | 37 continue; |
39 | 38 |
40 return true; | 39 return true; |
41 } while (true); | 40 } while (true); |
42 | 41 |
43 return false; | 42 return false; |
44 } | 43 } |
45 | 44 |
46 bool BrowserChildProcessHostIterator::Done() { | 45 bool BrowserChildProcessHostIterator::Done() { |
47 return iterator_ == BrowserChildProcessHostImpl::GetIterator()->end(); | 46 return iterator_ == BrowserChildProcessHostImpl::GetIterator()->end(); |
48 } | 47 } |
49 | 48 |
50 const ChildProcessData& BrowserChildProcessHostIterator::GetData() { | 49 const ChildProcessData& BrowserChildProcessHostIterator::GetData() { |
51 CHECK(!Done()); | 50 CHECK(!Done()); |
52 return (*iterator_)->GetData(); | 51 return (*iterator_)->GetData(); |
53 } | 52 } |
54 | 53 |
55 bool BrowserChildProcessHostIterator::Send(IPC::Message* message) { | 54 bool BrowserChildProcessHostIterator::Send(IPC::Message* message) { |
56 CHECK(!Done()); | 55 CHECK(!Done()); |
57 return (*iterator_)->Send(message); | 56 return (*iterator_)->Send(message); |
58 } | 57 } |
59 | 58 |
60 BrowserChildProcessHostDelegate* | 59 BrowserChildProcessHostDelegate* |
61 BrowserChildProcessHostIterator::GetDelegate() { | 60 BrowserChildProcessHostIterator::GetDelegate() { |
62 return (*iterator_)->delegate(); | 61 return (*iterator_)->delegate(); |
63 } | 62 } |
64 | 63 |
65 } // namespace content | 64 } // namespace content |
OLD | NEW |