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

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

Issue 2439403003: Refactor BlimpConnection to TCPConnection (Closed)
Patch Set: Added missing Engine Transport Created 4 years, 1 month 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 #include <utility> 8 #include <utility>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 65
66 namespace blimp { 66 namespace blimp {
67 namespace engine { 67 namespace engine {
68 namespace { 68 namespace {
69 69
70 const float kDefaultScaleFactor = 1.f; 70 const float kDefaultScaleFactor = 1.f;
71 const int kDefaultDisplayWidth = 800; 71 const int kDefaultDisplayWidth = 800;
72 const int kDefaultDisplayHeight = 600; 72 const int kDefaultDisplayHeight = 600;
73 const uint16_t kDefaultPort = 25467; 73 const uint16_t kDefaultPort = 25467;
74 74
75 const char kTcpTransport[] = "tcp";
76 const char kGrpcTransport[] = "grpc";
77
75 // Focus rules that support activating an child window. 78 // Focus rules that support activating an child window.
76 class FocusRulesImpl : public wm::BaseFocusRules { 79 class FocusRulesImpl : public wm::BaseFocusRules {
77 public: 80 public:
78 FocusRulesImpl() {} 81 FocusRulesImpl() {}
79 ~FocusRulesImpl() override {} 82 ~FocusRulesImpl() override {}
80 83
81 bool SupportsChildActivation(aura::Window* window) const override { 84 bool SupportsChildActivation(aura::Window* window) const override {
82 return true; 85 return true;
83 } 86 }
84 87
85 private: 88 private:
86 DISALLOW_COPY_AND_ASSIGN(FocusRulesImpl); 89 DISALLOW_COPY_AND_ASSIGN(FocusRulesImpl);
87 }; 90 };
88 91
89 // Proxies calls to TaskRunner::PostTask while stripping the return value, 92 // Proxies calls to TaskRunner::PostTask while stripping the return value,
90 // which provides a suitable function prototype for binding a base::Closure. 93 // which provides a suitable function prototype for binding a base::Closure.
91 void PostTask(const scoped_refptr<base::TaskRunner>& task_runner, 94 void PostTask(const scoped_refptr<base::TaskRunner>& task_runner,
92 const base::Closure& closure) { 95 const base::Closure& closure) {
93 task_runner->PostTask(FROM_HERE, closure); 96 task_runner->PostTask(FROM_HERE, closure);
94 } 97 }
95 98
96 // Returns a closure that quits the current (bind-time) MessageLoop. 99 // Returns a closure that quits the current (bind-time) MessageLoop.
97 base::Closure QuitCurrentMessageLoopClosure() { 100 base::Closure QuitCurrentMessageLoopClosure() {
98 return base::Bind(&PostTask, base::ThreadTaskRunnerHandle::Get(), 101 return base::Bind(&PostTask, base::ThreadTaskRunnerHandle::Get(),
99 base::MessageLoop::QuitWhenIdleClosure()); 102 base::MessageLoop::QuitWhenIdleClosure());
100 } 103 }
101 104
105 EngineConnectionManager::EngineTransportType GetTransportType() {
106 const std::string transport_parsed =
107 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
108 kEngineTransport);
109 if (transport_parsed == kTcpTransport || transport_parsed.empty()) {
110 return EngineConnectionManager::EngineTransportType::TCP;
111 } else if (transport_parsed == kGrpcTransport) {
112 return EngineConnectionManager::EngineTransportType::GRPC;
113 }
114 LOG(FATAL) << "--engine-transport must either be empty or one of "
115 << kGrpcTransport << ", " << kTcpTransport;
116 return EngineConnectionManager::EngineTransportType::TCP;
117 }
118
102 net::IPAddress GetListeningAddress() { 119 net::IPAddress GetListeningAddress() {
103 if (base::CommandLine::ForCurrentProcess()->HasSwitch(kAllowNonLocalhost)) { 120 if (base::CommandLine::ForCurrentProcess()->HasSwitch(kAllowNonLocalhost)) {
104 return net::IPAddress::IPv4AllZeros(); 121 return net::IPAddress::IPv4AllZeros();
105 } 122 }
106 return net::IPAddress::IPv4Localhost(); 123 return net::IPAddress::IPv4Localhost();
107 } 124 }
108 125
109 uint16_t GetListeningPort() { 126 uint16_t GetListeningPort() {
110 unsigned port_parsed = 0; 127 unsigned port_parsed = 0;
111 if (!base::StringToUint( 128 if (!base::StringToUint(
(...skipping 20 matching lines...) Expand all
132 explicit EngineNetworkComponents(net::NetLog* net_log); 149 explicit EngineNetworkComponents(net::NetLog* net_log);
133 ~EngineNetworkComponents() override; 150 ~EngineNetworkComponents() override;
134 151
135 // Sets up network components and starts listening for incoming connection. 152 // Sets up network components and starts listening for incoming connection.
136 // This should be called after all features have been registered so that 153 // This should be called after all features have been registered so that
137 // received messages can be properly handled. 154 // received messages can be properly handled.
138 void Initialize(scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, 155 void Initialize(scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
139 base::WeakPtr<BlobChannelSender> blob_channel_sender, 156 base::WeakPtr<BlobChannelSender> blob_channel_sender,
140 const std::string& client_token); 157 const std::string& client_token);
141 158
159 // TODO(perumaal): Remove this once gRPC support is ready.
160 // See crbug.com/659279.
142 uint16_t GetPortForTesting() { return port_; } 161 uint16_t GetPortForTesting() { return port_; }
143 162
144 BrowserConnectionHandler* connection_handler() { 163 BrowserConnectionHandler* connection_handler() {
145 return &connection_handler_; 164 return &connection_handler_;
146 } 165 }
147 166
148 BlobChannelService* blob_channel_service() { 167 BlobChannelService* blob_channel_service() {
149 return blob_channel_service_.get(); 168 return blob_channel_service_.get();
150 } 169 }
151 170
(...skipping 30 matching lines...) Expand all
182 base::WeakPtr<BlobChannelSender> blob_channel_sender, 201 base::WeakPtr<BlobChannelSender> blob_channel_sender,
183 const std::string& client_token) { 202 const std::string& client_token) {
184 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 203 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
185 DCHECK(!connection_manager_); 204 DCHECK(!connection_manager_);
186 // Plumb authenticated connections from the authentication handler 205 // Plumb authenticated connections from the authentication handler
187 // to |this| (which will then pass it to |connection_handler_|. 206 // to |this| (which will then pass it to |connection_handler_|.
188 authentication_handler_ = 207 authentication_handler_ =
189 base::MakeUnique<EngineAuthenticationHandler>(this, client_token); 208 base::MakeUnique<EngineAuthenticationHandler>(this, client_token);
190 209
191 // Plumb unauthenticated connections to |authentication_handler_|. 210 // Plumb unauthenticated connections to |authentication_handler_|.
192 connection_manager_ = 211 connection_manager_ = base::MakeUnique<EngineConnectionManager>(
193 base::MakeUnique<EngineConnectionManager>(authentication_handler_.get()); 212 authentication_handler_.get(), net_log_);
194 213
195 blob_channel_service_ = 214 blob_channel_service_ =
196 base::MakeUnique<BlobChannelService>(blob_channel_sender, ui_task_runner); 215 base::MakeUnique<BlobChannelService>(blob_channel_sender, ui_task_runner);
197 216
198 // Adds BlimpTransports to connection_manager_. 217 // Adds BlimpTransports to connection_manager_.
199 net::IPEndPoint address(GetListeningAddress(), GetListeningPort()); 218 net::IPEndPoint address(GetListeningAddress(), GetListeningPort());
200 TCPEngineTransport* transport = new TCPEngineTransport(address, net_log_); 219 connection_manager_->ConnectTransport(&address, GetTransportType());
201 connection_manager_->AddTransport(base::WrapUnique(transport));
202
203 transport->GetLocalAddress(&address);
204 port_ = address.port(); 220 port_ = address.port();
205 DVLOG(1) << "Engine port #: " << port_;
206 } 221 }
207 222
208 void EngineNetworkComponents::HandleConnection( 223 void EngineNetworkComponents::HandleConnection(
209 std::unique_ptr<BlimpConnection> connection) { 224 std::unique_ptr<BlimpConnection> connection) {
210 // Observe |connection| for disconnection events. 225 // Observe |connection| for disconnection events.
211 connection->AddConnectionErrorObserver(this); 226 connection->AddConnectionErrorObserver(this);
212 connection_handler_.HandleConnection(std::move(connection)); 227 connection_handler_.HandleConnection(std::move(connection));
213 } 228 }
214 229
215 void EngineNetworkComponents::OnConnectionError(int error) { 230 void EngineNetworkComponents::OnConnectionError(int error) {
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 parent->AddChild(content); 581 parent->AddChild(content);
567 content->Show(); 582 content->Show();
568 583
569 tab_ = base::MakeUnique<Tab>(std::move(new_contents), target_tab_id, 584 tab_ = base::MakeUnique<Tab>(std::move(new_contents), target_tab_id,
570 &render_widget_feature_, 585 &render_widget_feature_,
571 navigation_message_sender_.get()); 586 navigation_message_sender_.get());
572 } 587 }
573 588
574 } // namespace engine 589 } // namespace engine
575 } // namespace blimp 590 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698