| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "chromeos/dbus/dbus_thread_manager.h" | 8 #include "chromeos/dbus/dbus_thread_manager.h" |
| 9 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" | 9 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" |
| 10 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" | 10 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 BluetoothSocketThread::CleanupForTesting(); | 93 BluetoothSocketThread::CleanupForTesting(); |
| 94 DBusThreadManager::Shutdown(); | 94 DBusThreadManager::Shutdown(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void AdapterCallback(scoped_refptr<BluetoothAdapter> adapter) { | 97 void AdapterCallback(scoped_refptr<BluetoothAdapter> adapter) { |
| 98 adapter_ = adapter; | 98 adapter_ = adapter; |
| 99 } | 99 } |
| 100 | 100 |
| 101 void SuccessCallback() { | 101 void SuccessCallback() { |
| 102 ++success_callback_count_; | 102 ++success_callback_count_; |
| 103 message_loop_.Quit(); | 103 message_loop_.QuitWhenIdle(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void ErrorCallback(const std::string& message) { | 106 void ErrorCallback(const std::string& message) { |
| 107 ++error_callback_count_; | 107 ++error_callback_count_; |
| 108 last_message_ = message; | 108 last_message_ = message; |
| 109 | 109 |
| 110 if (message_loop_.is_running()) | 110 if (message_loop_.is_running()) |
| 111 message_loop_.Quit(); | 111 message_loop_.QuitWhenIdle(); |
| 112 } | 112 } |
| 113 | 113 |
| 114 void ConnectToServiceSuccessCallback(scoped_refptr<BluetoothSocket> socket) { | 114 void ConnectToServiceSuccessCallback(scoped_refptr<BluetoothSocket> socket) { |
| 115 ++success_callback_count_; | 115 ++success_callback_count_; |
| 116 last_socket_ = socket; | 116 last_socket_ = socket; |
| 117 | 117 |
| 118 message_loop_.Quit(); | 118 message_loop_.QuitWhenIdle(); |
| 119 } | 119 } |
| 120 | 120 |
| 121 void SendSuccessCallback(int bytes_sent) { | 121 void SendSuccessCallback(int bytes_sent) { |
| 122 ++success_callback_count_; | 122 ++success_callback_count_; |
| 123 last_bytes_sent_ = bytes_sent; | 123 last_bytes_sent_ = bytes_sent; |
| 124 | 124 |
| 125 message_loop_.Quit(); | 125 message_loop_.QuitWhenIdle(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void ReceiveSuccessCallback(int bytes_received, | 128 void ReceiveSuccessCallback(int bytes_received, |
| 129 scoped_refptr<net::IOBuffer> io_buffer) { | 129 scoped_refptr<net::IOBuffer> io_buffer) { |
| 130 ++success_callback_count_; | 130 ++success_callback_count_; |
| 131 last_bytes_received_ = bytes_received; | 131 last_bytes_received_ = bytes_received; |
| 132 last_io_buffer_ = io_buffer; | 132 last_io_buffer_ = io_buffer; |
| 133 | 133 |
| 134 message_loop_.Quit(); | 134 message_loop_.QuitWhenIdle(); |
| 135 } | 135 } |
| 136 | 136 |
| 137 void ReceiveErrorCallback(BluetoothSocket::ErrorReason reason, | 137 void ReceiveErrorCallback(BluetoothSocket::ErrorReason reason, |
| 138 const std::string& error_message) { | 138 const std::string& error_message) { |
| 139 ++error_callback_count_; | 139 ++error_callback_count_; |
| 140 last_reason_ = reason; | 140 last_reason_ = reason; |
| 141 last_message_ = error_message; | 141 last_message_ = error_message; |
| 142 | 142 |
| 143 message_loop_.Quit(); | 143 message_loop_.QuitWhenIdle(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 void CreateServiceSuccessCallback(scoped_refptr<BluetoothSocket> socket) { | 146 void CreateServiceSuccessCallback(scoped_refptr<BluetoothSocket> socket) { |
| 147 ++success_callback_count_; | 147 ++success_callback_count_; |
| 148 last_socket_ = socket; | 148 last_socket_ = socket; |
| 149 | 149 |
| 150 if (message_loop_.is_running()) | 150 if (message_loop_.is_running()) |
| 151 message_loop_.Quit(); | 151 message_loop_.QuitWhenIdle(); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void AcceptSuccessCallback(const BluetoothDevice* device, | 154 void AcceptSuccessCallback(const BluetoothDevice* device, |
| 155 scoped_refptr<BluetoothSocket> socket) { | 155 scoped_refptr<BluetoothSocket> socket) { |
| 156 ++success_callback_count_; | 156 ++success_callback_count_; |
| 157 last_device_ = device; | 157 last_device_ = device; |
| 158 last_socket_ = socket; | 158 last_socket_ = socket; |
| 159 | 159 |
| 160 message_loop_.Quit(); | 160 message_loop_.QuitWhenIdle(); |
| 161 } | 161 } |
| 162 | 162 |
| 163 void ImmediateSuccessCallback() { | 163 void ImmediateSuccessCallback() { |
| 164 ++success_callback_count_; | 164 ++success_callback_count_; |
| 165 } | 165 } |
| 166 | 166 |
| 167 protected: | 167 protected: |
| 168 base::MessageLoop message_loop_; | 168 base::MessageLoop message_loop_; |
| 169 | 169 |
| 170 scoped_refptr<BluetoothAdapter> adapter_; | 170 scoped_refptr<BluetoothAdapter> adapter_; |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 | 618 |
| 619 server_socket = nullptr; | 619 server_socket = nullptr; |
| 620 | 620 |
| 621 message_loop_.RunUntilIdle(); | 621 message_loop_.RunUntilIdle(); |
| 622 | 622 |
| 623 EXPECT_EQ(2U, success_callback_count_); | 623 EXPECT_EQ(2U, success_callback_count_); |
| 624 EXPECT_EQ(2U, error_callback_count_); | 624 EXPECT_EQ(2U, error_callback_count_); |
| 625 } | 625 } |
| 626 | 626 |
| 627 } // namespace chromeos | 627 } // namespace chromeos |
| OLD | NEW |