Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(694)

Side by Side Diff: blimp/engine/session/blimp_engine_session.cc

Issue 1929723002: [Blimp] Adds blimp engine browser test framework and LoadUrl test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address Kevin's comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/engine/session/blimp_engine_session.h" 5 #include "blimp/engine/session/blimp_engine_session.h"
6 6
7 #include <string> 7 #include <string>
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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } 95 }
96 96
97 uint16_t GetListeningPort() { 97 uint16_t GetListeningPort() {
98 unsigned port_parsed = 0; 98 unsigned port_parsed = 0;
99 if (!base::StringToUint( 99 if (!base::StringToUint(
100 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 100 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
101 kEnginePort), 101 kEnginePort),
102 &port_parsed)) { 102 &port_parsed)) {
103 return kDefaultPort; 103 return kDefaultPort;
104 } 104 }
105 if (port_parsed == 0 || 105 if (port_parsed > 65535) {
106 port_parsed > 65535) { 106 LOG(FATAL) << "--engine-port must be a value between 0 and 65535.";
107 LOG(FATAL) << "--engine-port must be a value between 1 and 65535.";
108 return kDefaultPort; 107 return kDefaultPort;
109 } 108 }
110 return port_parsed; 109 return port_parsed;
111 } 110 }
112 111
113 } // namespace 112 } // namespace
114 113
115 // EngineNetworkComponents is created by the BlimpEngineSession on the UI 114 // EngineNetworkComponents is created by the BlimpEngineSession on the UI
116 // thread, and then used and destroyed on the IO thread. 115 // thread, and then used and destroyed on the IO thread.
117 class EngineNetworkComponents : public ConnectionHandler, 116 class EngineNetworkComponents : public ConnectionHandler,
118 public ConnectionErrorObserver { 117 public ConnectionErrorObserver {
119 public: 118 public:
120 // |net_log|: The log to use for network-related events. 119 // |net_log|: The log to use for network-related events.
121 // |quit_closure|: A closure which will terminate the engine when 120 // |quit_closure|: A closure which will terminate the engine when
122 // invoked. 121 // invoked.
123 EngineNetworkComponents(net::NetLog* net_log, 122 EngineNetworkComponents(net::NetLog* net_log,
124 const base::Closure& quit_closure); 123 const base::Closure& quit_closure);
125 ~EngineNetworkComponents() override; 124 ~EngineNetworkComponents() override;
126 125
127 // Sets up network components and starts listening for incoming connection. 126 // Sets up network components and starts listening for incoming connection.
128 // This should be called after all features have been registered so that 127 // This should be called after all features have been registered so that
129 // received messages can be properly handled. 128 // received messages can be properly handled.
130 void Initialize(const std::string& client_token); 129 void Initialize(const std::string& client_token);
131 130
131 uint16_t GetPortForTesting() { return port_; }
132
132 BrowserConnectionHandler* GetBrowserConnectionHandler(); 133 BrowserConnectionHandler* GetBrowserConnectionHandler();
133 134
134 private: 135 private:
135 // ConnectionHandler implementation. 136 // ConnectionHandler implementation.
136 void HandleConnection(std::unique_ptr<BlimpConnection> connection) override; 137 void HandleConnection(std::unique_ptr<BlimpConnection> connection) override;
137 138
138 // ConnectionErrorObserver implementation. 139 // ConnectionErrorObserver implementation.
139 // Signals the engine session that an authenticated connection was 140 // Signals the engine session that an authenticated connection was
140 // terminated. 141 // terminated.
141 void OnConnectionError(int error) override; 142 void OnConnectionError(int error) override;
142 143
143 net::NetLog* net_log_; 144 net::NetLog* net_log_;
144 base::Closure quit_closure_; 145 base::Closure quit_closure_;
146 uint16_t port_ = 0;
145 147
146 std::unique_ptr<BrowserConnectionHandler> connection_handler_; 148 std::unique_ptr<BrowserConnectionHandler> connection_handler_;
147 std::unique_ptr<EngineAuthenticationHandler> authentication_handler_; 149 std::unique_ptr<EngineAuthenticationHandler> authentication_handler_;
148 std::unique_ptr<EngineConnectionManager> connection_manager_; 150 std::unique_ptr<EngineConnectionManager> connection_manager_;
149 151
150 DISALLOW_COPY_AND_ASSIGN(EngineNetworkComponents); 152 DISALLOW_COPY_AND_ASSIGN(EngineNetworkComponents);
151 }; 153 };
152 154
153 EngineNetworkComponents::EngineNetworkComponents( 155 EngineNetworkComponents::EngineNetworkComponents(
154 net::NetLog* net_log, 156 net::NetLog* net_log,
(...skipping 14 matching lines...) Expand all
169 // to |this| (which will then pass it to |connection_handler_|. 171 // to |this| (which will then pass it to |connection_handler_|.
170 authentication_handler_ = 172 authentication_handler_ =
171 base::WrapUnique(new EngineAuthenticationHandler(this, client_token)); 173 base::WrapUnique(new EngineAuthenticationHandler(this, client_token));
172 174
173 // Plumb unauthenticated connections to |authentication_handler_|. 175 // Plumb unauthenticated connections to |authentication_handler_|.
174 connection_manager_ = base::WrapUnique( 176 connection_manager_ = base::WrapUnique(
175 new EngineConnectionManager(authentication_handler_.get())); 177 new EngineConnectionManager(authentication_handler_.get()));
176 178
177 // Adds BlimpTransports to connection_manager_. 179 // Adds BlimpTransports to connection_manager_.
178 net::IPEndPoint address(GetIPv4AnyAddress(), GetListeningPort()); 180 net::IPEndPoint address(GetIPv4AnyAddress(), GetListeningPort());
179 connection_manager_->AddTransport( 181 TCPEngineTransport* transport = new TCPEngineTransport(address, net_log_);
180 base::WrapUnique(new TCPEngineTransport(address, net_log_))); 182 connection_manager_->AddTransport(base::WrapUnique(transport));
183
184 transport->GetLocalAddress(&address);
185 port_ = address.port();
181 } 186 }
182 187
183 void EngineNetworkComponents::HandleConnection( 188 void EngineNetworkComponents::HandleConnection(
184 std::unique_ptr<BlimpConnection> connection) { 189 std::unique_ptr<BlimpConnection> connection) {
185 // Observe |connection| for disconnection events. 190 // Observe |connection| for disconnection events.
186 connection->AddConnectionErrorObserver(this); 191 connection->AddConnectionErrorObserver(this);
187 connection_handler_->HandleConnection(std::move(connection)); 192 connection_handler_->HandleConnection(std::move(connection));
188 } 193 }
189 194
190 void EngineNetworkComponents::OnConnectionError(int error) { 195 void EngineNetworkComponents::OnConnectionError(int error) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 267
263 // Initialize must only be posted after the RegisterFeature calls have 268 // Initialize must only be posted after the RegisterFeature calls have
264 // completed. 269 // completed.
265 content::BrowserThread::PostTask( 270 content::BrowserThread::PostTask(
266 content::BrowserThread::IO, FROM_HERE, 271 content::BrowserThread::IO, FROM_HERE,
267 base::Bind(&EngineNetworkComponents::Initialize, 272 base::Bind(&EngineNetworkComponents::Initialize,
268 base::Unretained(net_components_.get()), 273 base::Unretained(net_components_.get()),
269 engine_config_->client_token())); 274 engine_config_->client_token()));
270 } 275 }
271 276
277 void BlimpEngineSession::GetEnginePortForTesting(
278 const GetPortCallback& callback) {
279 content::BrowserThread::PostTaskAndReplyWithResult(
280 content::BrowserThread::IO, FROM_HERE,
281 base::Bind(&EngineNetworkComponents::GetPortForTesting,
282 base::Unretained(net_components_.get())),
283 callback);
284 }
285
272 void BlimpEngineSession::RegisterFeatures() { 286 void BlimpEngineSession::RegisterFeatures() {
273 thread_pipe_manager_.reset(new ThreadPipeManager( 287 thread_pipe_manager_.reset(new ThreadPipeManager(
274 content::BrowserThread::GetMessageLoopProxyForThread( 288 content::BrowserThread::GetMessageLoopProxyForThread(
275 content::BrowserThread::IO), 289 content::BrowserThread::IO),
276 content::BrowserThread::GetMessageLoopProxyForThread( 290 content::BrowserThread::GetMessageLoopProxyForThread(
277 content::BrowserThread::UI), 291 content::BrowserThread::UI),
278 net_components_->GetBrowserConnectionHandler())); 292 net_components_->GetBrowserConnectionHandler()));
279 293
280 // Register features' message senders and receivers. 294 // Register features' message senders and receivers.
281 tab_control_message_sender_ = 295 tab_control_message_sender_ =
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 648
635 aura::Window* parent = window_tree_host_->window(); 649 aura::Window* parent = window_tree_host_->window();
636 aura::Window* content = web_contents_->GetNativeView(); 650 aura::Window* content = web_contents_->GetNativeView();
637 if (!parent->Contains(content)) 651 if (!parent->Contains(content))
638 parent->AddChild(content); 652 parent->AddChild(content);
639 content->Show(); 653 content->Show();
640 } 654 }
641 655
642 } // namespace engine 656 } // namespace engine
643 } // namespace blimp 657 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698