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 12 matching lines...) Expand all Loading... |
30 AppRemotingConnectionHelper::AppRemotingConnectionHelper( | 29 AppRemotingConnectionHelper::AppRemotingConnectionHelper( |
31 const RemoteApplicationDetails& application_details) | 30 const RemoteApplicationDetails& application_details) |
32 : application_details_(application_details), | 31 : application_details_(application_details), |
33 connection_is_ready_for_tests_(false), | 32 connection_is_ready_for_tests_(false), |
34 timer_(new base::Timer(true, false)) { | 33 timer_(new base::Timer(true, false)) { |
35 } | 34 } |
36 | 35 |
37 AppRemotingConnectionHelper::~AppRemotingConnectionHelper() { | 36 AppRemotingConnectionHelper::~AppRemotingConnectionHelper() { |
38 // |client_| destroys some of its members via DeleteSoon on the message loop's | 37 // |client_| destroys some of its members via DeleteSoon on the message loop's |
39 // TaskRunner so we need to run the loop until it has no more work to do. | 38 // TaskRunner so we need to run the loop until it has no more work to do. |
40 client_->RemoveRemoteConnectionObserver(this); | 39 if (!connection_is_ready_for_tests_) { |
| 40 client_->RemoveRemoteConnectionObserver(this); |
| 41 } |
41 client_.reset(); | 42 client_.reset(); |
42 | 43 |
43 base::RunLoop().RunUntilIdle(); | 44 base::RunLoop().RunUntilIdle(); |
44 } | 45 } |
45 | 46 |
46 void AppRemotingConnectionHelper::Initialize( | 47 void AppRemotingConnectionHelper::Initialize( |
47 scoped_ptr<TestChromotingClient> test_chromoting_client) { | 48 scoped_ptr<TestChromotingClient> test_chromoting_client) { |
48 client_ = test_chromoting_client.Pass(); | 49 client_ = test_chromoting_client.Pass(); |
49 client_->AddRemoteConnectionObserver(this); | 50 client_->AddRemoteConnectionObserver(this); |
50 } | 51 } |
51 | 52 |
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() { | 53 bool AppRemotingConnectionHelper::StartConnection() { |
58 DCHECK(thread_checker_.CalledOnValidThread()); | 54 DCHECK(thread_checker_.CalledOnValidThread()); |
59 DCHECK(client_); | 55 DCHECK(client_); |
60 | 56 |
61 RemoteHostInfo remote_host_info; | 57 RemoteHostInfo remote_host_info; |
62 remoting::test::AppRemotingSharedData->GetRemoteHostInfoForApplicationId( | 58 remoting::test::AppRemotingSharedData->GetRemoteHostInfoForApplicationId( |
63 application_details_.application_id, &remote_host_info); | 59 application_details_.application_id, &remote_host_info); |
64 | 60 |
65 if (!remote_host_info.IsReadyForConnection()) { | 61 if (!remote_host_info.IsReadyForConnection()) { |
66 return false; | 62 return false; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 } | 134 } |
139 } | 135 } |
140 | 136 |
141 void AppRemotingConnectionHelper::HostMessageReceived( | 137 void AppRemotingConnectionHelper::HostMessageReceived( |
142 const protocol::ExtensionMessage& message) { | 138 const protocol::ExtensionMessage& message) { |
143 DCHECK(thread_checker_.CalledOnValidThread()); | 139 DCHECK(thread_checker_.CalledOnValidThread()); |
144 | 140 |
145 VLOG(2) << "HostMessage received by HostMessageReceived()." | 141 VLOG(2) << "HostMessage received by HostMessageReceived()." |
146 << " type: " << message.type() << " data: " << message.data(); | 142 << " type: " << message.type() << " data: " << message.data(); |
147 | 143 |
148 // If a callback is not registered, then the message is passed to a default | 144 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); | 145 HandleOnWindowAddedMessage(message); |
154 } else { | 146 } else { |
155 VLOG(2) << "HostMessage not handled by HostMessageReceived()."; | 147 VLOG(2) << "HostMessage not handled by HostMessageReceived()."; |
156 } | 148 } |
157 } | 149 } |
158 | 150 |
159 void AppRemotingConnectionHelper::SendClientConnectionDetailsToHost() { | 151 void AppRemotingConnectionHelper::SendClientConnectionDetailsToHost() { |
160 // First send an access token which will be used for Google Drive access. | 152 // First send an access token which will be used for Google Drive access. |
161 protocol::ExtensionMessage message; | 153 protocol::ExtensionMessage message; |
162 message.set_type("accessToken"); | 154 message.set_type("accessToken"); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 std::string current_window_title; | 194 std::string current_window_title; |
203 message_data->GetString("title", ¤t_window_title); | 195 message_data->GetString("title", ¤t_window_title); |
204 if (current_window_title == kHostProcessWindowTitle) { | 196 if (current_window_title == kHostProcessWindowTitle) { |
205 LOG(ERROR) << "Host Process Window is visible, this likely means that the " | 197 LOG(ERROR) << "Host Process Window is visible, this likely means that the " |
206 << "underlying application is in a bad state, YMMV."; | 198 << "underlying application is in a bad state, YMMV."; |
207 } | 199 } |
208 | 200 |
209 std::string main_window_title = application_details_.main_window_title; | 201 std::string main_window_title = application_details_.main_window_title; |
210 if (current_window_title.find_first_of(main_window_title) == 0) { | 202 if (current_window_title.find_first_of(main_window_title) == 0) { |
211 connection_is_ready_for_tests_ = true; | 203 connection_is_ready_for_tests_ = true; |
| 204 client_->RemoveRemoteConnectionObserver(this); |
212 | 205 |
213 if (timer_->IsRunning()) { | 206 if (timer_->IsRunning()) { |
214 timer_->Stop(); | 207 timer_->Stop(); |
215 } | 208 } |
216 | 209 |
217 DCHECK(run_loop_); | 210 DCHECK(run_loop_); |
218 // Now that the main window is visible, give the app some time to settle | 211 // Now that the main window is visible, give the app some time to settle |
219 // before signaling that it is ready to run tests. | 212 // before signaling that it is ready to run tests. |
220 timer_->Start(FROM_HERE, base::TimeDelta::FromSeconds(2), | 213 timer_->Start(FROM_HERE, base::TimeDelta::FromSeconds(2), |
221 run_loop_->QuitClosure()); | 214 run_loop_->QuitClosure()); |
222 } | 215 } |
223 } | 216 } |
224 | 217 |
225 } // namespace test | 218 } // namespace test |
226 } // namespace remoting | 219 } // namespace remoting |
OLD | NEW |