OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "tools/android/forwarder2/forwarders_manager.h" | 5 #include "tools/android/forwarder2/forwarders_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <sys/select.h> | 8 #include <sys/select.h> |
9 #include <unistd.h> | 9 #include <unistd.h> |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 13 matching lines...) Expand all Loading... |
24 ForwardersManager::ForwardersManager() : thread_("ForwardersManagerThread") { | 24 ForwardersManager::ForwardersManager() : thread_("ForwardersManagerThread") { |
25 thread_.Start(); | 25 thread_.Start(); |
26 WaitForEventsOnInternalThreadSoon(); | 26 WaitForEventsOnInternalThreadSoon(); |
27 } | 27 } |
28 | 28 |
29 | 29 |
30 ForwardersManager::~ForwardersManager() { | 30 ForwardersManager::~ForwardersManager() { |
31 deletion_notifier_.Notify(); | 31 deletion_notifier_.Notify(); |
32 } | 32 } |
33 | 33 |
34 void ForwardersManager::CreateAndStartNewForwarder(scoped_ptr<Socket> socket1, | 34 void ForwardersManager::CreateAndStartNewForwarder( |
35 scoped_ptr<Socket> socket2) { | 35 std::unique_ptr<Socket> socket1, |
| 36 std::unique_ptr<Socket> socket2) { |
36 // Note that the internal Forwarder vector is populated on the internal thread | 37 // Note that the internal Forwarder vector is populated on the internal thread |
37 // which is the only thread from which it's accessed. | 38 // which is the only thread from which it's accessed. |
38 thread_.task_runner()->PostTask( | 39 thread_.task_runner()->PostTask( |
39 FROM_HERE, | 40 FROM_HERE, |
40 base::Bind(&ForwardersManager::CreateNewForwarderOnInternalThread, | 41 base::Bind(&ForwardersManager::CreateNewForwarderOnInternalThread, |
41 base::Unretained(this), base::Passed(&socket1), | 42 base::Unretained(this), base::Passed(&socket1), |
42 base::Passed(&socket2))); | 43 base::Passed(&socket2))); |
43 | 44 |
44 // Guarantees that the CreateNewForwarderOnInternalThread callback posted to | 45 // Guarantees that the CreateNewForwarderOnInternalThread callback posted to |
45 // the internal thread gets executed immediately. | 46 // the internal thread gets executed immediately. |
46 wakeup_notifier_.Notify(); | 47 wakeup_notifier_.Notify(); |
47 } | 48 } |
48 | 49 |
49 void ForwardersManager::CreateNewForwarderOnInternalThread( | 50 void ForwardersManager::CreateNewForwarderOnInternalThread( |
50 scoped_ptr<Socket> socket1, | 51 std::unique_ptr<Socket> socket1, |
51 scoped_ptr<Socket> socket2) { | 52 std::unique_ptr<Socket> socket2) { |
52 DCHECK(thread_.task_runner()->RunsTasksOnCurrentThread()); | 53 DCHECK(thread_.task_runner()->RunsTasksOnCurrentThread()); |
53 forwarders_.push_back(new Forwarder(std::move(socket1), std::move(socket2))); | 54 forwarders_.push_back(new Forwarder(std::move(socket1), std::move(socket2))); |
54 } | 55 } |
55 | 56 |
56 void ForwardersManager::WaitForEventsOnInternalThreadSoon() { | 57 void ForwardersManager::WaitForEventsOnInternalThreadSoon() { |
57 thread_.task_runner()->PostTask( | 58 thread_.task_runner()->PostTask( |
58 FROM_HERE, | 59 FROM_HERE, |
59 base::Bind(&ForwardersManager::WaitForEventsOnInternalThread, | 60 base::Bind(&ForwardersManager::WaitForEventsOnInternalThread, |
60 base::Unretained(this))); | 61 base::Unretained(this))); |
61 } | 62 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 ++i; | 124 ++i; |
124 continue; | 125 continue; |
125 } | 126 } |
126 | 127 |
127 std::swap(forwarders_[i], forwarders_.back()); | 128 std::swap(forwarders_[i], forwarders_.back()); |
128 forwarders_.pop_back(); | 129 forwarders_.pop_back(); |
129 } | 130 } |
130 } | 131 } |
131 | 132 |
132 } // namespace forwarder2 | 133 } // namespace forwarder2 |
OLD | NEW |