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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 | 66 |
67 } // namespace | 67 } // namespace |
68 | 68 |
69 // This class's functions and destruction are all invoked on the IO thread by | 69 // This class's functions and destruction are all invoked on the IO thread by |
70 // the BlimpClientSession. | 70 // the BlimpClientSession. |
71 class ClientNetworkComponents : public ConnectionHandler, | 71 class ClientNetworkComponents : public ConnectionHandler, |
72 public ConnectionErrorObserver { | 72 public ConnectionErrorObserver { |
73 public: | 73 public: |
74 // Can be created on any thread. | 74 // Can be created on any thread. |
75 explicit ClientNetworkComponents( | 75 explicit ClientNetworkComponents( |
76 std::unique_ptr<NetworkEventObserver> observer); | 76 std::unique_ptr<NetworkEventObserver> observer, |
77 BlimpConnectionDetails* blimp_connection_details); | |
Kevin M
2016/05/10 23:54:24
This is racy. |blimp_connection_details| can be de
shaktisahu
2016/05/16 05:41:38
Okay. I have redesigned now. |blimp_connection_det
| |
77 ~ClientNetworkComponents() override; | 78 ~ClientNetworkComponents() override; |
78 | 79 |
79 // Sets up network components. | 80 // Sets up network components. |
80 void Initialize(); | 81 void Initialize(); |
81 | 82 |
82 // Starts the connection to the engine using the given |assignment|. | 83 // Starts the connection to the engine using the given |assignment|. |
83 // It is required to first call Initialize. | 84 // It is required to first call Initialize. |
84 void ConnectWithAssignment(const Assignment& assignment); | 85 void ConnectWithAssignment(const Assignment& assignment); |
85 | 86 |
86 BrowserConnectionHandler* GetBrowserConnectionHandler(); | 87 BrowserConnectionHandler* GetBrowserConnectionHandler(); |
87 | 88 |
88 private: | 89 private: |
89 // ConnectionHandler implementation. | 90 // ConnectionHandler implementation. |
90 void HandleConnection(std::unique_ptr<BlimpConnection> connection) override; | 91 void HandleConnection(std::unique_ptr<BlimpConnection> connection) override; |
91 | 92 |
92 // ConnectionErrorObserver implementation. | 93 // ConnectionErrorObserver implementation. |
93 void OnConnectionError(int error) override; | 94 void OnConnectionError(int error) override; |
94 | 95 |
95 std::unique_ptr<BrowserConnectionHandler> connection_handler_; | 96 std::unique_ptr<BrowserConnectionHandler> connection_handler_; |
96 std::unique_ptr<ClientConnectionManager> connection_manager_; | 97 std::unique_ptr<ClientConnectionManager> connection_manager_; |
97 std::unique_ptr<NetworkEventObserver> network_observer_; | 98 std::unique_ptr<NetworkEventObserver> network_observer_; |
98 | 99 |
100 BlimpConnectionDetails* connection_details_; | |
101 | |
99 DISALLOW_COPY_AND_ASSIGN(ClientNetworkComponents); | 102 DISALLOW_COPY_AND_ASSIGN(ClientNetworkComponents); |
100 }; | 103 }; |
101 | 104 |
102 ClientNetworkComponents::ClientNetworkComponents( | 105 ClientNetworkComponents::ClientNetworkComponents( |
103 std::unique_ptr<NetworkEventObserver> network_observer) | 106 std::unique_ptr<NetworkEventObserver> network_observer, |
107 BlimpConnectionDetails* details) | |
104 : connection_handler_(new BrowserConnectionHandler), | 108 : connection_handler_(new BrowserConnectionHandler), |
105 network_observer_(std::move(network_observer)) {} | 109 network_observer_(std::move(network_observer)), |
110 connection_details_(details) {} | |
106 | 111 |
107 ClientNetworkComponents::~ClientNetworkComponents() {} | 112 ClientNetworkComponents::~ClientNetworkComponents() {} |
108 | 113 |
109 void ClientNetworkComponents::Initialize() { | 114 void ClientNetworkComponents::Initialize() { |
110 DCHECK(!connection_manager_); | 115 DCHECK(!connection_manager_); |
111 connection_manager_ = base::WrapUnique(new ClientConnectionManager(this)); | 116 connection_manager_ = base::WrapUnique(new ClientConnectionManager(this)); |
112 } | 117 } |
113 | 118 |
114 void ClientNetworkComponents::ConnectWithAssignment( | 119 void ClientNetworkComponents::ConnectWithAssignment( |
115 const Assignment& assignment) { | 120 const Assignment& assignment) { |
(...skipping 27 matching lines...) Expand all Loading... | |
143 BrowserConnectionHandler* | 148 BrowserConnectionHandler* |
144 ClientNetworkComponents::GetBrowserConnectionHandler() { | 149 ClientNetworkComponents::GetBrowserConnectionHandler() { |
145 return connection_handler_.get(); | 150 return connection_handler_.get(); |
146 } | 151 } |
147 | 152 |
148 void ClientNetworkComponents::HandleConnection( | 153 void ClientNetworkComponents::HandleConnection( |
149 std::unique_ptr<BlimpConnection> connection) { | 154 std::unique_ptr<BlimpConnection> connection) { |
150 VLOG(1) << "Connection established."; | 155 VLOG(1) << "Connection established."; |
151 connection->AddConnectionErrorObserver(this); | 156 connection->AddConnectionErrorObserver(this); |
152 network_observer_->OnConnected(); | 157 network_observer_->OnConnected(); |
158 connection->SetBlimpConnectionDetails(connection_details_); | |
153 connection_handler_->HandleConnection(std::move(connection)); | 159 connection_handler_->HandleConnection(std::move(connection)); |
154 } | 160 } |
155 | 161 |
156 void ClientNetworkComponents::OnConnectionError(int result) { | 162 void ClientNetworkComponents::OnConnectionError(int result) { |
157 VLOG(1) << "Connection error: " << net::ErrorToString(result); | 163 VLOG(1) << "Connection error: " << net::ErrorToString(result); |
158 network_observer_->OnDisconnected(result); | 164 network_observer_->OnDisconnected(result); |
159 } | 165 } |
160 | 166 |
161 BlimpClientSession::BlimpClientSession(const GURL& assigner_endpoint) | 167 BlimpClientSession::BlimpClientSession(const GURL& assigner_endpoint) |
162 : io_thread_("BlimpIOThread"), | 168 : io_thread_("BlimpIOThread"), |
169 blimp_connection_details_(new BlimpConnectionDetails(this)), | |
163 tab_control_feature_(new TabControlFeature), | 170 tab_control_feature_(new TabControlFeature), |
164 navigation_feature_(new NavigationFeature), | 171 navigation_feature_( |
172 new NavigationFeature(blimp_connection_details_.get())), | |
165 ime_feature_(new ImeFeature), | 173 ime_feature_(new ImeFeature), |
166 render_widget_feature_(new RenderWidgetFeature), | 174 render_widget_feature_(new RenderWidgetFeature), |
167 settings_feature_(new SettingsFeature), | 175 settings_feature_(new SettingsFeature), |
168 weak_factory_(this) { | 176 weak_factory_(this) { |
169 net_components_.reset(new ClientNetworkComponents( | 177 net_components_.reset(new ClientNetworkComponents( |
170 base::WrapUnique(new CrossThreadNetworkEventObserver( | 178 base::WrapUnique(new CrossThreadNetworkEventObserver( |
171 weak_factory_.GetWeakPtr(), | 179 weak_factory_.GetWeakPtr(), base::SequencedTaskRunnerHandle::Get())), |
172 base::SequencedTaskRunnerHandle::Get())))); | 180 blimp_connection_details_.get())); |
181 | |
173 base::Thread::Options options; | 182 base::Thread::Options options; |
174 options.message_loop_type = base::MessageLoop::TYPE_IO; | 183 options.message_loop_type = base::MessageLoop::TYPE_IO; |
175 io_thread_.StartWithOptions(options); | 184 io_thread_.StartWithOptions(options); |
176 | 185 |
177 assignment_source_.reset(new AssignmentSource( | 186 assignment_source_.reset(new AssignmentSource( |
178 assigner_endpoint, io_thread_.task_runner(), io_thread_.task_runner())); | 187 assigner_endpoint, io_thread_.task_runner(), io_thread_.task_runner())); |
179 | 188 |
180 RegisterFeatures(); | 189 RegisterFeatures(); |
181 | 190 |
182 // Initialize must only be posted after the RegisterFeature calls have | 191 // Initialize must only be posted after the RegisterFeature calls have |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
244 // Client will not send send any RenderWidget messages, so don't save the | 253 // Client will not send send any RenderWidget messages, so don't save the |
245 // outgoing BlimpMessageProcessor in the RenderWidgetFeature. | 254 // outgoing BlimpMessageProcessor in the RenderWidgetFeature. |
246 thread_pipe_manager_->RegisterFeature(BlimpMessage::RENDER_WIDGET, | 255 thread_pipe_manager_->RegisterFeature(BlimpMessage::RENDER_WIDGET, |
247 render_widget_feature_.get()); | 256 render_widget_feature_.get()); |
248 | 257 |
249 ime_feature_->set_outgoing_message_processor( | 258 ime_feature_->set_outgoing_message_processor( |
250 thread_pipe_manager_->RegisterFeature(BlimpMessage::IME, | 259 thread_pipe_manager_->RegisterFeature(BlimpMessage::IME, |
251 ime_feature_.get())); | 260 ime_feature_.get())); |
252 } | 261 } |
253 | 262 |
263 void BlimpClientSession::OnPacketReceived(int bytes) {} | |
Kevin M
2016/05/10 23:54:24
nit: the name says OnPacketReceived, but the param
shaktisahu
2016/05/16 05:41:38
Method dropped. Now I have only one method called
| |
264 | |
265 void BlimpClientSession::OnPacketSent(int bytes) {} | |
266 | |
254 void BlimpClientSession::OnConnected() {} | 267 void BlimpClientSession::OnConnected() {} |
255 | 268 |
256 void BlimpClientSession::OnDisconnected(int result) {} | 269 void BlimpClientSession::OnDisconnected(int result) {} |
257 | 270 |
258 TabControlFeature* BlimpClientSession::GetTabControlFeature() const { | 271 TabControlFeature* BlimpClientSession::GetTabControlFeature() const { |
259 return tab_control_feature_.get(); | 272 return tab_control_feature_.get(); |
260 } | 273 } |
261 | 274 |
262 NavigationFeature* BlimpClientSession::GetNavigationFeature() const { | 275 NavigationFeature* BlimpClientSession::GetNavigationFeature() const { |
263 return navigation_feature_.get(); | 276 return navigation_feature_.get(); |
264 } | 277 } |
265 | 278 |
266 ImeFeature* BlimpClientSession::GetImeFeature() const { | 279 ImeFeature* BlimpClientSession::GetImeFeature() const { |
267 return ime_feature_.get(); | 280 return ime_feature_.get(); |
268 } | 281 } |
269 | 282 |
270 RenderWidgetFeature* BlimpClientSession::GetRenderWidgetFeature() const { | 283 RenderWidgetFeature* BlimpClientSession::GetRenderWidgetFeature() const { |
271 return render_widget_feature_.get(); | 284 return render_widget_feature_.get(); |
272 } | 285 } |
273 | 286 |
274 SettingsFeature* BlimpClientSession::GetSettingsFeature() const { | 287 SettingsFeature* BlimpClientSession::GetSettingsFeature() const { |
275 return settings_feature_.get(); | 288 return settings_feature_.get(); |
276 } | 289 } |
277 | 290 |
278 } // namespace client | 291 } // namespace client |
279 } // namespace blimp | 292 } // namespace blimp |
OLD | NEW |