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 explicit ClientNetworkComponents( | 75 explicit ClientNetworkComponents( |
Kevin M
2016/05/24 22:56:40
Not "explicit"
| |
76 std::unique_ptr<NetworkEventObserver> observer); | 76 std::unique_ptr<NetworkEventObserver> observer, |
77 BlimpConnectionStatistics* blimp_connection_statistics); | |
Kevin M
2016/05/24 22:56:40
Should take a unique_ptr<> if we are passing owner
| |
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_; |
99 std::unique_ptr<BlimpConnectionStatistics> connection_statistics_; | |
98 | 100 |
99 DISALLOW_COPY_AND_ASSIGN(ClientNetworkComponents); | 101 DISALLOW_COPY_AND_ASSIGN(ClientNetworkComponents); |
100 }; | 102 }; |
101 | 103 |
102 ClientNetworkComponents::ClientNetworkComponents( | 104 ClientNetworkComponents::ClientNetworkComponents( |
103 std::unique_ptr<NetworkEventObserver> network_observer) | 105 std::unique_ptr<NetworkEventObserver> network_observer, |
106 BlimpConnectionStatistics* statistics) | |
104 : connection_handler_(new BrowserConnectionHandler), | 107 : connection_handler_(new BrowserConnectionHandler), |
105 network_observer_(std::move(network_observer)) {} | 108 network_observer_(std::move(network_observer)), |
109 connection_statistics_(statistics) {} | |
Kevin M
2016/05/24 22:56:40
DCHECK(statistics)
| |
106 | 110 |
107 ClientNetworkComponents::~ClientNetworkComponents() {} | 111 ClientNetworkComponents::~ClientNetworkComponents() {} |
108 | 112 |
109 void ClientNetworkComponents::Initialize() { | 113 void ClientNetworkComponents::Initialize() { |
110 DCHECK(!connection_manager_); | 114 DCHECK(!connection_manager_); |
111 connection_manager_ = base::WrapUnique(new ClientConnectionManager(this)); | 115 connection_manager_ = base::WrapUnique(new ClientConnectionManager(this)); |
112 } | 116 } |
113 | 117 |
114 void ClientNetworkComponents::ConnectWithAssignment( | 118 void ClientNetworkComponents::ConnectWithAssignment( |
115 const Assignment& assignment) { | 119 const Assignment& assignment) { |
116 DCHECK(connection_manager_); | 120 DCHECK(connection_manager_); |
117 | 121 |
118 connection_manager_->set_client_token(assignment.client_token); | 122 connection_manager_->set_client_token(assignment.client_token); |
119 const char* transport_type = "UNKNOWN"; | 123 const char* transport_type = "UNKNOWN"; |
120 switch (assignment.transport_protocol) { | 124 switch (assignment.transport_protocol) { |
121 case Assignment::SSL: | 125 case Assignment::SSL: |
122 DCHECK(assignment.cert); | 126 DCHECK(assignment.cert); |
123 connection_manager_->AddTransport(base::WrapUnique(new SSLClientTransport( | 127 connection_manager_->AddTransport(base::WrapUnique(new SSLClientTransport( |
124 assignment.engine_endpoint, std::move(assignment.cert), nullptr))); | 128 assignment.engine_endpoint, std::move(assignment.cert), |
129 connection_statistics_.get(), nullptr))); | |
125 transport_type = "SSL"; | 130 transport_type = "SSL"; |
126 break; | 131 break; |
127 case Assignment::TCP: | 132 case Assignment::TCP: |
128 connection_manager_->AddTransport(base::WrapUnique( | 133 connection_manager_->AddTransport(base::WrapUnique(new TCPClientTransport( |
129 new TCPClientTransport(assignment.engine_endpoint, nullptr))); | 134 assignment.engine_endpoint, connection_statistics_.get(), nullptr))); |
130 transport_type = "TCP"; | 135 transport_type = "TCP"; |
131 break; | 136 break; |
132 case Assignment::UNKNOWN: | 137 case Assignment::UNKNOWN: |
133 LOG(FATAL) << "Unknown transport type."; | 138 LOG(FATAL) << "Unknown transport type."; |
134 break; | 139 break; |
135 } | 140 } |
136 | 141 |
137 VLOG(1) << "Connecting to " << assignment.engine_endpoint.ToString() << " (" | 142 VLOG(1) << "Connecting to " << assignment.engine_endpoint.ToString() << " (" |
138 << transport_type << ")"; | 143 << transport_type << ")"; |
139 | 144 |
(...skipping 19 matching lines...) Expand all Loading... | |
159 } | 164 } |
160 | 165 |
161 BlimpClientSession::BlimpClientSession(const GURL& assigner_endpoint) | 166 BlimpClientSession::BlimpClientSession(const GURL& assigner_endpoint) |
162 : io_thread_("BlimpIOThread"), | 167 : io_thread_("BlimpIOThread"), |
163 tab_control_feature_(new TabControlFeature), | 168 tab_control_feature_(new TabControlFeature), |
164 navigation_feature_(new NavigationFeature), | 169 navigation_feature_(new NavigationFeature), |
165 ime_feature_(new ImeFeature), | 170 ime_feature_(new ImeFeature), |
166 render_widget_feature_(new RenderWidgetFeature), | 171 render_widget_feature_(new RenderWidgetFeature), |
167 settings_feature_(new SettingsFeature), | 172 settings_feature_(new SettingsFeature), |
168 weak_factory_(this) { | 173 weak_factory_(this) { |
169 net_components_.reset(new ClientNetworkComponents( | |
170 base::WrapUnique(new CrossThreadNetworkEventObserver( | |
171 weak_factory_.GetWeakPtr(), | |
172 base::SequencedTaskRunnerHandle::Get())))); | |
173 base::Thread::Options options; | 174 base::Thread::Options options; |
174 options.message_loop_type = base::MessageLoop::TYPE_IO; | 175 options.message_loop_type = base::MessageLoop::TYPE_IO; |
175 io_thread_.StartWithOptions(options); | 176 io_thread_.StartWithOptions(options); |
177 blimp_connection_statistics_ = new BlimpConnectionStatistics(); | |
178 net_components_.reset(new ClientNetworkComponents( | |
179 base::WrapUnique(new CrossThreadNetworkEventObserver( | |
180 weak_factory_.GetWeakPtr(), base::SequencedTaskRunnerHandle::Get())), | |
181 blimp_connection_statistics_)); | |
176 | 182 |
177 assignment_source_.reset(new AssignmentSource( | 183 assignment_source_.reset(new AssignmentSource( |
178 assigner_endpoint, io_thread_.task_runner(), io_thread_.task_runner())); | 184 assigner_endpoint, io_thread_.task_runner(), io_thread_.task_runner())); |
179 | 185 |
180 RegisterFeatures(); | 186 RegisterFeatures(); |
181 | 187 |
182 // Initialize must only be posted after the RegisterFeature calls have | 188 // Initialize must only be posted after the RegisterFeature calls have |
183 // completed. | 189 // completed. |
184 io_thread_.task_runner()->PostTask( | 190 io_thread_.task_runner()->PostTask( |
185 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, | 191 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
268 } | 274 } |
269 | 275 |
270 RenderWidgetFeature* BlimpClientSession::GetRenderWidgetFeature() const { | 276 RenderWidgetFeature* BlimpClientSession::GetRenderWidgetFeature() const { |
271 return render_widget_feature_.get(); | 277 return render_widget_feature_.get(); |
272 } | 278 } |
273 | 279 |
274 SettingsFeature* BlimpClientSession::GetSettingsFeature() const { | 280 SettingsFeature* BlimpClientSession::GetSettingsFeature() const { |
275 return settings_feature_.get(); | 281 return settings_feature_.get(); |
276 } | 282 } |
277 | 283 |
284 BlimpConnectionStatistics* BlimpClientSession::GetBlimpConnectionStatistics() | |
285 const { | |
286 return blimp_connection_statistics_; | |
287 } | |
288 | |
278 } // namespace client | 289 } // namespace client |
279 } // namespace blimp | 290 } // namespace blimp |
OLD | NEW |