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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 }; | 65 }; |
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 ClientNetworkComponents( | 75 explicit ClientNetworkComponents( |
76 std::unique_ptr<NetworkEventObserver> observer, | 76 std::unique_ptr<NetworkEventObserver> observer); |
77 std::unique_ptr<BlimpConnectionStatistics> blimp_connection_statistics); | |
78 ~ClientNetworkComponents() override; | 77 ~ClientNetworkComponents() override; |
79 | 78 |
80 // Sets up network components. | 79 // Sets up network components. |
81 void Initialize(); | 80 void Initialize(); |
82 | 81 |
83 // Starts the connection to the engine using the given |assignment|. | 82 // Starts the connection to the engine using the given |assignment|. |
84 // It is required to first call Initialize. | 83 // It is required to first call Initialize. |
85 void ConnectWithAssignment(const Assignment& assignment); | 84 void ConnectWithAssignment(const Assignment& assignment); |
86 | 85 |
87 BrowserConnectionHandler* GetBrowserConnectionHandler(); | 86 BrowserConnectionHandler* GetBrowserConnectionHandler(); |
88 | 87 |
89 private: | 88 private: |
90 // ConnectionHandler implementation. | 89 // ConnectionHandler implementation. |
91 void HandleConnection(std::unique_ptr<BlimpConnection> connection) override; | 90 void HandleConnection(std::unique_ptr<BlimpConnection> connection) override; |
92 | 91 |
93 // ConnectionErrorObserver implementation. | 92 // ConnectionErrorObserver implementation. |
94 void OnConnectionError(int error) override; | 93 void OnConnectionError(int error) override; |
95 | 94 |
96 std::unique_ptr<BrowserConnectionHandler> connection_handler_; | 95 std::unique_ptr<BrowserConnectionHandler> connection_handler_; |
97 std::unique_ptr<ClientConnectionManager> connection_manager_; | 96 std::unique_ptr<ClientConnectionManager> connection_manager_; |
98 std::unique_ptr<NetworkEventObserver> network_observer_; | 97 std::unique_ptr<NetworkEventObserver> network_observer_; |
99 std::unique_ptr<BlimpConnectionStatistics> connection_statistics_; | |
100 | 98 |
101 DISALLOW_COPY_AND_ASSIGN(ClientNetworkComponents); | 99 DISALLOW_COPY_AND_ASSIGN(ClientNetworkComponents); |
102 }; | 100 }; |
103 | 101 |
104 ClientNetworkComponents::ClientNetworkComponents( | 102 ClientNetworkComponents::ClientNetworkComponents( |
105 std::unique_ptr<NetworkEventObserver> network_observer, | 103 std::unique_ptr<NetworkEventObserver> network_observer) |
106 std::unique_ptr<BlimpConnectionStatistics> statistics) | |
107 : connection_handler_(new BrowserConnectionHandler), | 104 : connection_handler_(new BrowserConnectionHandler), |
108 network_observer_(std::move(network_observer)), | 105 network_observer_(std::move(network_observer)) {} |
109 connection_statistics_(std::move(statistics)) { | |
110 DCHECK(connection_statistics_); | |
111 } | |
112 | 106 |
113 ClientNetworkComponents::~ClientNetworkComponents() {} | 107 ClientNetworkComponents::~ClientNetworkComponents() {} |
114 | 108 |
115 void ClientNetworkComponents::Initialize() { | 109 void ClientNetworkComponents::Initialize() { |
116 DCHECK(!connection_manager_); | 110 DCHECK(!connection_manager_); |
117 connection_manager_ = base::WrapUnique(new ClientConnectionManager(this)); | 111 connection_manager_ = base::WrapUnique(new ClientConnectionManager(this)); |
118 } | 112 } |
119 | 113 |
120 void ClientNetworkComponents::ConnectWithAssignment( | 114 void ClientNetworkComponents::ConnectWithAssignment( |
121 const Assignment& assignment) { | 115 const Assignment& assignment) { |
122 DCHECK(connection_manager_); | 116 DCHECK(connection_manager_); |
123 | 117 |
124 connection_manager_->set_client_token(assignment.client_token); | 118 connection_manager_->set_client_token(assignment.client_token); |
125 const char* transport_type = "UNKNOWN"; | 119 const char* transport_type = "UNKNOWN"; |
126 switch (assignment.transport_protocol) { | 120 switch (assignment.transport_protocol) { |
127 case Assignment::SSL: | 121 case Assignment::SSL: |
128 DCHECK(assignment.cert); | 122 DCHECK(assignment.cert); |
129 connection_manager_->AddTransport(base::WrapUnique(new SSLClientTransport( | 123 connection_manager_->AddTransport(base::WrapUnique(new SSLClientTransport( |
130 assignment.engine_endpoint, std::move(assignment.cert), | 124 assignment.engine_endpoint, std::move(assignment.cert), nullptr))); |
131 connection_statistics_.get(), nullptr))); | |
132 transport_type = "SSL"; | 125 transport_type = "SSL"; |
133 break; | 126 break; |
134 case Assignment::TCP: | 127 case Assignment::TCP: |
135 connection_manager_->AddTransport(base::WrapUnique(new TCPClientTransport( | 128 connection_manager_->AddTransport(base::WrapUnique( |
136 assignment.engine_endpoint, connection_statistics_.get(), nullptr))); | 129 new TCPClientTransport(assignment.engine_endpoint, nullptr))); |
137 transport_type = "TCP"; | 130 transport_type = "TCP"; |
138 break; | 131 break; |
139 case Assignment::UNKNOWN: | 132 case Assignment::UNKNOWN: |
140 LOG(FATAL) << "Unknown transport type."; | 133 LOG(FATAL) << "Unknown transport type."; |
141 break; | 134 break; |
142 } | 135 } |
143 | 136 |
144 VLOG(1) << "Connecting to " << assignment.engine_endpoint.ToString() << " (" | 137 VLOG(1) << "Connecting to " << assignment.engine_endpoint.ToString() << " (" |
145 << transport_type << ")"; | 138 << transport_type << ")"; |
146 | 139 |
(...skipping 19 matching lines...) Expand all Loading... |
166 } | 159 } |
167 | 160 |
168 BlimpClientSession::BlimpClientSession(const GURL& assigner_endpoint) | 161 BlimpClientSession::BlimpClientSession(const GURL& assigner_endpoint) |
169 : io_thread_("BlimpIOThread"), | 162 : io_thread_("BlimpIOThread"), |
170 tab_control_feature_(new TabControlFeature), | 163 tab_control_feature_(new TabControlFeature), |
171 navigation_feature_(new NavigationFeature), | 164 navigation_feature_(new NavigationFeature), |
172 ime_feature_(new ImeFeature), | 165 ime_feature_(new ImeFeature), |
173 render_widget_feature_(new RenderWidgetFeature), | 166 render_widget_feature_(new RenderWidgetFeature), |
174 settings_feature_(new SettingsFeature), | 167 settings_feature_(new SettingsFeature), |
175 weak_factory_(this) { | 168 weak_factory_(this) { |
| 169 net_components_.reset(new ClientNetworkComponents( |
| 170 base::WrapUnique(new CrossThreadNetworkEventObserver( |
| 171 weak_factory_.GetWeakPtr(), |
| 172 base::SequencedTaskRunnerHandle::Get())))); |
176 base::Thread::Options options; | 173 base::Thread::Options options; |
177 options.message_loop_type = base::MessageLoop::TYPE_IO; | 174 options.message_loop_type = base::MessageLoop::TYPE_IO; |
178 io_thread_.StartWithOptions(options); | 175 io_thread_.StartWithOptions(options); |
179 blimp_connection_statistics_ = new BlimpConnectionStatistics(); | |
180 net_components_.reset(new ClientNetworkComponents( | |
181 base::WrapUnique(new CrossThreadNetworkEventObserver( | |
182 weak_factory_.GetWeakPtr(), base::SequencedTaskRunnerHandle::Get())), | |
183 base::WrapUnique(blimp_connection_statistics_))); | |
184 | 176 |
185 assignment_source_.reset(new AssignmentSource( | 177 assignment_source_.reset(new AssignmentSource( |
186 assigner_endpoint, io_thread_.task_runner(), io_thread_.task_runner())); | 178 assigner_endpoint, io_thread_.task_runner(), io_thread_.task_runner())); |
187 | 179 |
188 RegisterFeatures(); | 180 RegisterFeatures(); |
189 | 181 |
190 // Initialize must only be posted after the RegisterFeature calls have | 182 // Initialize must only be posted after the RegisterFeature calls have |
191 // completed. | 183 // completed. |
192 io_thread_.task_runner()->PostTask( | 184 io_thread_.task_runner()->PostTask( |
193 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, | 185 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 } | 271 } |
280 | 272 |
281 RenderWidgetFeature* BlimpClientSession::GetRenderWidgetFeature() const { | 273 RenderWidgetFeature* BlimpClientSession::GetRenderWidgetFeature() const { |
282 return render_widget_feature_.get(); | 274 return render_widget_feature_.get(); |
283 } | 275 } |
284 | 276 |
285 SettingsFeature* BlimpClientSession::GetSettingsFeature() const { | 277 SettingsFeature* BlimpClientSession::GetSettingsFeature() const { |
286 return settings_feature_.get(); | 278 return settings_feature_.get(); |
287 } | 279 } |
288 | 280 |
289 BlimpConnectionStatistics* BlimpClientSession::GetBlimpConnectionStatistics() | |
290 const { | |
291 return blimp_connection_statistics_; | |
292 } | |
293 | |
294 } // namespace client | 281 } // namespace client |
295 } // namespace blimp | 282 } // namespace blimp |
OLD | NEW |