| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "remoting/test/app_remoting_connection_helper.h" | 5 #include "remoting/test/app_remoting_connection_helper.h" |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" |
| 7 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 8 #include "base/logging.h" | 9 #include "base/logging.h" |
| 9 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 10 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
| 11 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
| 12 #include "base/values.h" | 13 #include "base/values.h" |
| 13 #include "remoting/protocol/host_stub.h" | 14 #include "remoting/protocol/host_stub.h" |
| 14 #include "remoting/test/app_remoting_test_driver_environment.h" | 15 #include "remoting/test/app_remoting_test_driver_environment.h" |
| 15 #include "remoting/test/remote_application_details.h" | 16 #include "remoting/test/remote_application_details.h" |
| 16 #include "remoting/test/test_chromoting_client.h" | 17 #include "remoting/test/test_chromoting_client.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 46 scoped_ptr<TestChromotingClient> test_chromoting_client) { | 47 scoped_ptr<TestChromotingClient> test_chromoting_client) { |
| 47 client_ = test_chromoting_client.Pass(); | 48 client_ = test_chromoting_client.Pass(); |
| 48 client_->AddRemoteConnectionObserver(this); | 49 client_->AddRemoteConnectionObserver(this); |
| 49 } | 50 } |
| 50 | 51 |
| 51 void AppRemotingConnectionHelper::SetHostMessageReceivedCallback( | 52 void AppRemotingConnectionHelper::SetHostMessageReceivedCallback( |
| 52 HostMessageReceivedCallback host_message_received_callback) { | 53 HostMessageReceivedCallback host_message_received_callback) { |
| 53 host_message_received_callback_ = host_message_received_callback; | 54 host_message_received_callback_ = host_message_received_callback; |
| 54 } | 55 } |
| 55 | 56 |
| 56 void AppRemotingConnectionHelper::ResetHostMessageReceivedCallback() { | |
| 57 host_message_received_callback_.Reset(); | |
| 58 } | |
| 59 | |
| 60 bool AppRemotingConnectionHelper::StartConnection() { | 57 bool AppRemotingConnectionHelper::StartConnection() { |
| 61 DCHECK(thread_checker_.CalledOnValidThread()); | 58 DCHECK(thread_checker_.CalledOnValidThread()); |
| 62 DCHECK(client_); | 59 DCHECK(client_); |
| 63 | 60 |
| 64 RemoteHostInfo remote_host_info; | 61 RemoteHostInfo remote_host_info; |
| 65 remoting::test::AppRemotingSharedData->GetRemoteHostInfoForApplicationId( | 62 remoting::test::AppRemotingSharedData->GetRemoteHostInfoForApplicationId( |
| 66 application_details_.application_id, &remote_host_info); | 63 application_details_.application_id, &remote_host_info); |
| 67 | 64 |
| 68 if (!remote_host_info.IsReadyForConnection()) { | 65 if (!remote_host_info.IsReadyForConnection()) { |
| 69 return false; | 66 return false; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 } | 138 } |
| 142 } | 139 } |
| 143 | 140 |
| 144 void AppRemotingConnectionHelper::HostMessageReceived( | 141 void AppRemotingConnectionHelper::HostMessageReceived( |
| 145 const protocol::ExtensionMessage& message) { | 142 const protocol::ExtensionMessage& message) { |
| 146 DCHECK(thread_checker_.CalledOnValidThread()); | 143 DCHECK(thread_checker_.CalledOnValidThread()); |
| 147 | 144 |
| 148 // If a callback is not registered, then the message is passed to a default | 145 // If a callback is not registered, then the message is passed to a default |
| 149 // handler for the class based on the message type. | 146 // handler for the class based on the message type. |
| 150 if (!host_message_received_callback_.is_null()) { | 147 if (!host_message_received_callback_.is_null()) { |
| 151 host_message_received_callback_.Run(message); | 148 base::ResetAndReturn(&host_message_received_callback_).Run(message); |
| 152 } else if (message.type() == "onWindowAdded") { | 149 } else if (message.type() == "onWindowAdded") { |
| 153 HandleOnWindowAddedMessage(message); | 150 HandleOnWindowAddedMessage(message); |
| 154 } else { | 151 } else { |
| 155 VLOG(2) << "HostMessage not handled by HostMessageReceived()."; | 152 VLOG(2) << "HostMessage not handled by HostMessageReceived()."; |
| 156 VLOG(2) << "type: " << message.type(); | 153 VLOG(2) << "type: " << message.type(); |
| 157 VLOG(2) << "data: " << message.data(); | 154 VLOG(2) << "data: " << message.data(); |
| 158 } | 155 } |
| 159 } | 156 } |
| 160 | 157 |
| 161 void AppRemotingConnectionHelper::SendClientConnectionDetailsToHost() { | 158 void AppRemotingConnectionHelper::SendClientConnectionDetailsToHost() { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 DCHECK(run_loop_); | 216 DCHECK(run_loop_); |
| 220 // Now that the main window is visible, give the app some time to settle | 217 // Now that the main window is visible, give the app some time to settle |
| 221 // before signaling that it is ready to run tests. | 218 // before signaling that it is ready to run tests. |
| 222 timer_->Start(FROM_HERE, base::TimeDelta::FromSeconds(2), | 219 timer_->Start(FROM_HERE, base::TimeDelta::FromSeconds(2), |
| 223 run_loop_->QuitClosure()); | 220 run_loop_->QuitClosure()); |
| 224 } | 221 } |
| 225 } | 222 } |
| 226 | 223 |
| 227 } // namespace test | 224 } // namespace test |
| 228 } // namespace remoting | 225 } // namespace remoting |
| OLD | NEW |