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 "blimp/client/session/blimp_client_session.h" | 5 #include "blimp/client/session/blimp_client_session.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/numerics/safe_conversions.h" | 11 #include "base/numerics/safe_conversions.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/thread_task_runner_handle.h" |
13 #include "base/threading/sequenced_task_runner_handle.h" | 14 #include "base/threading/sequenced_task_runner_handle.h" |
14 #include "blimp/client/app/blimp_client_switches.h" | 15 #include "blimp/client/app/blimp_client_switches.h" |
15 #include "blimp/client/feature/navigation_feature.h" | 16 #include "blimp/client/feature/navigation_feature.h" |
16 #include "blimp/client/feature/render_widget_feature.h" | 17 #include "blimp/client/feature/render_widget_feature.h" |
17 #include "blimp/client/feature/tab_control_feature.h" | 18 #include "blimp/client/feature/tab_control_feature.h" |
18 #include "blimp/net/blimp_message_processor.h" | 19 #include "blimp/net/blimp_message_processor.h" |
19 #include "blimp/net/blimp_message_thread_pipe.h" | 20 #include "blimp/net/blimp_message_thread_pipe.h" |
20 #include "blimp/net/browser_connection_handler.h" | 21 #include "blimp/net/browser_connection_handler.h" |
21 #include "blimp/net/client_connection_manager.h" | 22 #include "blimp/net/client_connection_manager.h" |
22 #include "blimp/net/common.h" | 23 #include "blimp/net/common.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 // actual sender of the |outgoing_pipe|. | 100 // actual sender of the |outgoing_pipe|. |
100 scoped_ptr<BlimpMessageProcessor> outgoing_message_processor = | 101 scoped_ptr<BlimpMessageProcessor> outgoing_message_processor = |
101 browser_connection_handler_->RegisterFeature(type, incoming_proxy.get()); | 102 browser_connection_handler_->RegisterFeature(type, incoming_proxy.get()); |
102 outgoing_pipe->set_target_processor(outgoing_message_processor.get()); | 103 outgoing_pipe->set_target_processor(outgoing_message_processor.get()); |
103 | 104 |
104 incoming_proxies_.push_back(std::move(incoming_proxy)); | 105 incoming_proxies_.push_back(std::move(incoming_proxy)); |
105 outgoing_pipes_.push_back(std::move(outgoing_pipe)); | 106 outgoing_pipes_.push_back(std::move(outgoing_pipe)); |
106 outgoing_message_processors_.push_back(std::move(outgoing_message_processor)); | 107 outgoing_message_processors_.push_back(std::move(outgoing_message_processor)); |
107 } | 108 } |
108 | 109 |
109 BlimpClientSession::BlimpClientSession( | 110 BlimpClientSession::BlimpClientSession() |
110 scoped_ptr<AssignmentSource> assignment_source) | 111 : io_thread_("BlimpIOThread"), |
111 : assignment_source_(std::move(assignment_source)), | |
112 io_thread_("BlimpIOThread"), | |
113 tab_control_feature_(new TabControlFeature), | 112 tab_control_feature_(new TabControlFeature), |
114 navigation_feature_(new NavigationFeature), | 113 navigation_feature_(new NavigationFeature), |
115 render_widget_feature_(new RenderWidgetFeature), | 114 render_widget_feature_(new RenderWidgetFeature), |
116 net_components_(new ClientNetworkComponents), | 115 net_components_(new ClientNetworkComponents), |
117 weak_factory_(this) { | 116 weak_factory_(this) { |
118 base::Thread::Options options; | 117 base::Thread::Options options; |
119 options.message_loop_type = base::MessageLoop::TYPE_IO; | 118 options.message_loop_type = base::MessageLoop::TYPE_IO; |
120 io_thread_.StartWithOptions(options); | 119 io_thread_.StartWithOptions(options); |
121 | 120 |
| 121 assignment_source_.reset(new AssignmentSource( |
| 122 base::ThreadTaskRunnerHandle::Get(), io_thread_.task_runner())); |
| 123 |
122 // Register features' message senders and receivers. | 124 // Register features' message senders and receivers. |
123 tab_control_feature_->set_outgoing_message_processor( | 125 tab_control_feature_->set_outgoing_message_processor( |
124 RegisterFeature(BlimpMessage::TAB_CONTROL, tab_control_feature_.get())); | 126 RegisterFeature(BlimpMessage::TAB_CONTROL, tab_control_feature_.get())); |
125 navigation_feature_->set_outgoing_message_processor( | 127 navigation_feature_->set_outgoing_message_processor( |
126 RegisterFeature(BlimpMessage::NAVIGATION, navigation_feature_.get())); | 128 RegisterFeature(BlimpMessage::NAVIGATION, navigation_feature_.get())); |
127 render_widget_feature_->set_outgoing_input_message_processor( | 129 render_widget_feature_->set_outgoing_input_message_processor( |
128 RegisterFeature(BlimpMessage::INPUT, render_widget_feature_.get())); | 130 RegisterFeature(BlimpMessage::INPUT, render_widget_feature_.get())); |
129 render_widget_feature_->set_outgoing_compositor_message_processor( | 131 render_widget_feature_->set_outgoing_compositor_message_processor( |
130 RegisterFeature(BlimpMessage::COMPOSITOR, render_widget_feature_.get())); | 132 RegisterFeature(BlimpMessage::COMPOSITOR, render_widget_feature_.get())); |
131 | 133 |
132 // We don't expect to send any RenderWidget messages, so don't save the | 134 // We don't expect to send any RenderWidget messages, so don't save the |
133 // outgoing BlimpMessageProcessor in the RenderWidgetFeature. | 135 // outgoing BlimpMessageProcessor in the RenderWidgetFeature. |
134 RegisterFeature(BlimpMessage::RENDER_WIDGET, render_widget_feature_.get()); | 136 RegisterFeature(BlimpMessage::RENDER_WIDGET, render_widget_feature_.get()); |
135 | 137 |
136 // Initialize must only be posted after the RegisterFeature calls have | 138 // Initialize must only be posted after the RegisterFeature calls have |
137 // completed. | 139 // completed. |
138 io_thread_.task_runner()->PostTask( | 140 io_thread_.task_runner()->PostTask( |
139 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, | 141 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, |
140 base::Unretained(net_components_.get()))); | 142 base::Unretained(net_components_.get()))); |
141 } | 143 } |
142 | 144 |
143 BlimpClientSession::~BlimpClientSession() { | 145 BlimpClientSession::~BlimpClientSession() { |
144 io_thread_.task_runner()->DeleteSoon(FROM_HERE, net_components_.release()); | 146 io_thread_.task_runner()->DeleteSoon(FROM_HERE, net_components_.release()); |
145 } | 147 } |
146 | 148 |
147 void BlimpClientSession::Connect() { | 149 void BlimpClientSession::Connect(const std::string& client_auth_token) { |
148 assignment_source_->GetAssignment(base::Bind( | 150 assignment_source_->GetAssignment( |
149 &BlimpClientSession::ConnectWithAssignment, weak_factory_.GetWeakPtr())); | 151 client_auth_token, base::Bind(&BlimpClientSession::ConnectWithAssignment, |
| 152 weak_factory_.GetWeakPtr())); |
150 } | 153 } |
151 | 154 |
152 void BlimpClientSession::ConnectWithAssignment(const Assignment& assignment) { | 155 void BlimpClientSession::ConnectWithAssignment(AssignmentSource::Result result, |
| 156 const Assignment& assignment) { |
| 157 OnAssignmentConnectionAttempted(result); |
| 158 |
| 159 if (result != AssignmentSource::Result::RESULT_OK) { |
| 160 VLOG(1) << "Assignment request failed: " << result; |
| 161 return; |
| 162 } |
| 163 |
153 io_thread_.task_runner()->PostTask( | 164 io_thread_.task_runner()->PostTask( |
154 FROM_HERE, | 165 FROM_HERE, |
155 base::Bind(&ClientNetworkComponents::ConnectWithAssignment, | 166 base::Bind(&ClientNetworkComponents::ConnectWithAssignment, |
156 base::Unretained(net_components_.get()), assignment)); | 167 base::Unretained(net_components_.get()), assignment)); |
157 } | 168 } |
158 | 169 |
| 170 void BlimpClientSession::OnAssignmentConnectionAttempted( |
| 171 AssignmentSource::Result result) {} |
| 172 |
159 scoped_ptr<BlimpMessageProcessor> BlimpClientSession::RegisterFeature( | 173 scoped_ptr<BlimpMessageProcessor> BlimpClientSession::RegisterFeature( |
160 BlimpMessage::Type type, | 174 BlimpMessage::Type type, |
161 BlimpMessageProcessor* incoming_processor) { | 175 BlimpMessageProcessor* incoming_processor) { |
162 // Creates an outgoing pipe and a proxy for forwarding messages | 176 // Creates an outgoing pipe and a proxy for forwarding messages |
163 // from features on the UI thread to network components on the IO thread. | 177 // from features on the UI thread to network components on the IO thread. |
164 scoped_ptr<BlimpMessageThreadPipe> outgoing_pipe( | 178 scoped_ptr<BlimpMessageThreadPipe> outgoing_pipe( |
165 new BlimpMessageThreadPipe(io_thread_.task_runner())); | 179 new BlimpMessageThreadPipe(io_thread_.task_runner())); |
166 scoped_ptr<BlimpMessageProcessor> outgoing_message_proxy = | 180 scoped_ptr<BlimpMessageProcessor> outgoing_message_proxy = |
167 outgoing_pipe->CreateProxy(); | 181 outgoing_pipe->CreateProxy(); |
168 | 182 |
(...skipping 23 matching lines...) Expand all Loading... |
192 NavigationFeature* BlimpClientSession::GetNavigationFeature() const { | 206 NavigationFeature* BlimpClientSession::GetNavigationFeature() const { |
193 return navigation_feature_.get(); | 207 return navigation_feature_.get(); |
194 } | 208 } |
195 | 209 |
196 RenderWidgetFeature* BlimpClientSession::GetRenderWidgetFeature() const { | 210 RenderWidgetFeature* BlimpClientSession::GetRenderWidgetFeature() const { |
197 return render_widget_feature_.get(); | 211 return render_widget_feature_.get(); |
198 } | 212 } |
199 | 213 |
200 } // namespace client | 214 } // namespace client |
201 } // namespace blimp | 215 } // namespace blimp |
OLD | NEW |