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" | |
8 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
9 #include "base/logging.h" | 8 #include "base/logging.h" |
10 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
11 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
12 #include "base/timer/timer.h" | 11 #include "base/timer/timer.h" |
13 #include "base/values.h" | 12 #include "base/values.h" |
14 #include "remoting/protocol/host_stub.h" | 13 #include "remoting/protocol/host_stub.h" |
15 #include "remoting/test/app_remoting_test_driver_environment.h" | 14 #include "remoting/test/app_remoting_test_driver_environment.h" |
16 #include "remoting/test/remote_application_details.h" | 15 #include "remoting/test/remote_application_details.h" |
17 #include "remoting/test/test_chromoting_client.h" | 16 #include "remoting/test/test_chromoting_client.h" |
(...skipping 24 matching lines...) Expand all Loading... |
42 | 41 |
43 base::RunLoop().RunUntilIdle(); | 42 base::RunLoop().RunUntilIdle(); |
44 } | 43 } |
45 | 44 |
46 void AppRemotingConnectionHelper::Initialize( | 45 void AppRemotingConnectionHelper::Initialize( |
47 scoped_ptr<TestChromotingClient> test_chromoting_client) { | 46 scoped_ptr<TestChromotingClient> test_chromoting_client) { |
48 client_ = test_chromoting_client.Pass(); | 47 client_ = test_chromoting_client.Pass(); |
49 client_->AddRemoteConnectionObserver(this); | 48 client_->AddRemoteConnectionObserver(this); |
50 } | 49 } |
51 | 50 |
52 void AppRemotingConnectionHelper::SetHostMessageReceivedCallback( | |
53 HostMessageReceivedCallback host_message_received_callback) { | |
54 host_message_received_callback_ = host_message_received_callback; | |
55 } | |
56 | |
57 bool AppRemotingConnectionHelper::StartConnection() { | 51 bool AppRemotingConnectionHelper::StartConnection() { |
58 DCHECK(thread_checker_.CalledOnValidThread()); | 52 DCHECK(thread_checker_.CalledOnValidThread()); |
59 DCHECK(client_); | 53 DCHECK(client_); |
60 | 54 |
61 RemoteHostInfo remote_host_info; | 55 RemoteHostInfo remote_host_info; |
62 remoting::test::AppRemotingSharedData->GetRemoteHostInfoForApplicationId( | 56 remoting::test::AppRemotingSharedData->GetRemoteHostInfoForApplicationId( |
63 application_details_.application_id, &remote_host_info); | 57 application_details_.application_id, &remote_host_info); |
64 | 58 |
65 if (!remote_host_info.IsReadyForConnection()) { | 59 if (!remote_host_info.IsReadyForConnection()) { |
66 return false; | 60 return false; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 } | 132 } |
139 } | 133 } |
140 | 134 |
141 void AppRemotingConnectionHelper::HostMessageReceived( | 135 void AppRemotingConnectionHelper::HostMessageReceived( |
142 const protocol::ExtensionMessage& message) { | 136 const protocol::ExtensionMessage& message) { |
143 DCHECK(thread_checker_.CalledOnValidThread()); | 137 DCHECK(thread_checker_.CalledOnValidThread()); |
144 | 138 |
145 VLOG(2) << "HostMessage received by HostMessageReceived()." | 139 VLOG(2) << "HostMessage received by HostMessageReceived()." |
146 << " type: " << message.type() << " data: " << message.data(); | 140 << " type: " << message.type() << " data: " << message.data(); |
147 | 141 |
148 // If a callback is not registered, then the message is passed to a default | 142 if (message.type() == "onWindowAdded") { |
149 // handler for the class based on the message type. | |
150 if (!host_message_received_callback_.is_null()) { | |
151 base::ResetAndReturn(&host_message_received_callback_).Run(message); | |
152 } else if (message.type() == "onWindowAdded") { | |
153 HandleOnWindowAddedMessage(message); | 143 HandleOnWindowAddedMessage(message); |
154 } else { | 144 } else { |
155 VLOG(2) << "HostMessage not handled by HostMessageReceived()."; | 145 VLOG(2) << "HostMessage not handled by HostMessageReceived()."; |
156 } | 146 } |
157 } | 147 } |
158 | 148 |
159 void AppRemotingConnectionHelper::SendClientConnectionDetailsToHost() { | 149 void AppRemotingConnectionHelper::SendClientConnectionDetailsToHost() { |
160 // First send an access token which will be used for Google Drive access. | 150 // First send an access token which will be used for Google Drive access. |
161 protocol::ExtensionMessage message; | 151 protocol::ExtensionMessage message; |
162 message.set_type("accessToken"); | 152 message.set_type("accessToken"); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 DCHECK(run_loop_); | 207 DCHECK(run_loop_); |
218 // Now that the main window is visible, give the app some time to settle | 208 // Now that the main window is visible, give the app some time to settle |
219 // before signaling that it is ready to run tests. | 209 // before signaling that it is ready to run tests. |
220 timer_->Start(FROM_HERE, base::TimeDelta::FromSeconds(2), | 210 timer_->Start(FROM_HERE, base::TimeDelta::FromSeconds(2), |
221 run_loop_->QuitClosure()); | 211 run_loop_->QuitClosure()); |
222 } | 212 } |
223 } | 213 } |
224 | 214 |
225 } // namespace test | 215 } // namespace test |
226 } // namespace remoting | 216 } // namespace remoting |
OLD | NEW |