Chromium Code Reviews| Index: blimp/engine/browser/blimp_engine_session.cc |
| diff --git a/blimp/engine/browser/blimp_engine_session.cc b/blimp/engine/browser/blimp_engine_session.cc |
| index 0dd58702796390c6b00e6f36192d77bd3297b909..e92793dfcf67b244559103d65c464db422e25ec2 100644 |
| --- a/blimp/engine/browser/blimp_engine_session.cc |
| +++ b/blimp/engine/browser/blimp_engine_session.cc |
| @@ -16,6 +16,7 @@ |
| #include "blimp/net/blimp_connection.h" |
| #include "blimp/net/blimp_message_multiplexer.h" |
| #include "blimp/net/browser_connection_handler.h" |
| +#include "blimp/net/common.h" |
| #include "blimp/net/engine_authentication_handler.h" |
| #include "blimp/net/engine_connection_manager.h" |
| #include "blimp/net/null_blimp_message_processor.h" |
| @@ -49,7 +50,6 @@ const int kDummyTabId = 0; |
| const float kDefaultScaleFactor = 1.f; |
| const int kDefaultDisplayWidth = 800; |
| const int kDefaultDisplayHeight = 600; |
| -const uint16 kDefaultPortNumber = 25467; |
| base::LazyInstance<blimp::NullBlimpMessageProcessor> g_blimp_message_processor = |
| LAZY_INSTANCE_INITIALIZER; |
| @@ -70,53 +70,6 @@ class FocusRulesImpl : public wm::BaseFocusRules { |
| } // namespace |
| -// This class's functions and destruction are all invoked on the IO thread by |
| -// the BlimpEngineSession. |
| -class BlimpNetworkComponents { |
|
haibinlu
2015/12/29 00:51:45
per offline discussion, keep BlimpNetworkComponent
Kevin M
2015/12/30 23:08:49
Done.
|
| - public: |
| - explicit BlimpNetworkComponents(net::NetLog* net_log); |
| - ~BlimpNetworkComponents(); |
| - |
| - void Initialize(); |
| - |
| - private: |
| - net::NetLog* net_log_; |
| - scoped_ptr<BrowserConnectionHandler> connection_handler_; |
| - scoped_ptr<EngineAuthenticationHandler> authentication_handler_; |
| - scoped_ptr<EngineConnectionManager> connection_manager_; |
| - |
| - DISALLOW_COPY_AND_ASSIGN(BlimpNetworkComponents); |
| -}; |
| - |
| -BlimpNetworkComponents::BlimpNetworkComponents(net::NetLog* net_log) |
| - : net_log_(net_log) {} |
| - |
| -BlimpNetworkComponents::~BlimpNetworkComponents() { |
| - DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| -} |
| - |
| -void BlimpNetworkComponents::Initialize() { |
| - DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| - DCHECK(!connection_handler_); |
| - |
| - // Creates and connects net components. |
| - // A BlimpConnection flows from |
| - // connection_manager_ --> authentication_handler_ --> connection_handler_ |
| - connection_handler_.reset(new BrowserConnectionHandler); |
| - authentication_handler_.reset( |
| - new EngineAuthenticationHandler(connection_handler_.get())); |
| - connection_manager_.reset( |
| - new EngineConnectionManager(authentication_handler_.get())); |
| - |
| - // Adds BlimpTransports to connection_manager_. |
| - net::IPAddressNumber local_ip_any; |
| - bool success = net::ParseIPLiteralToNumber("0.0.0.0", &local_ip_any); |
| - DCHECK(success); |
| - net::IPEndPoint address(local_ip_any, kDefaultPortNumber); |
| - connection_manager_->AddTransport( |
| - make_scoped_ptr(new TCPEngineTransport(address, net_log_))); |
| -} |
| - |
| BlimpEngineSession::BlimpEngineSession( |
| scoped_ptr<BlimpBrowserContext> browser_context, |
| net::NetLog* net_log) |
| @@ -125,7 +78,7 @@ BlimpEngineSession::BlimpEngineSession( |
| // TODO(dtrainor, haibinlu): Properly pull these from the BlimpMessageMux. |
| render_widget_processor_(g_blimp_message_processor.Pointer(), |
| g_blimp_message_processor.Pointer()), |
| - net_components_(new BlimpNetworkComponents(net_log)) { |
| + net_log_(net_log) { |
| screen_->UpdateDisplayScaleAndSize(kDefaultScaleFactor, |
| gfx::Size(kDefaultDisplayWidth, |
| kDefaultDisplayHeight)); |
| @@ -137,7 +90,11 @@ BlimpEngineSession::~BlimpEngineSession() { |
| // Safely delete network components on the IO thread. |
| content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, |
| - net_components_.release()); |
| + connection_handler_.release()); |
| + content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, |
| + authentication_handler_.release()); |
| + content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, |
| + connection_manager_.release()); |
| } |
| void BlimpEngineSession::Initialize() { |
| @@ -172,8 +129,8 @@ void BlimpEngineSession::Initialize() { |
| content::BrowserThread::PostTask( |
| content::BrowserThread::IO, FROM_HERE, |
| - base::Bind(&BlimpNetworkComponents::Initialize, |
| - base::Unretained(net_components_.get()))); |
| + base::Bind(&BlimpEngineSession::InitializeNetwork, |
| + base::Unretained(this))); |
| } |
| void BlimpEngineSession::CreateWebContents(const int target_tab_id) { |
| @@ -261,6 +218,7 @@ void BlimpEngineSession::OnCompositorMessageReceived( |
| void BlimpEngineSession::ProcessMessage( |
| scoped_ptr<BlimpMessage> message, |
| const net::CompletionCallback& callback) { |
| + DVLOG(2) << "BlimpEngineSession: ProcessMessage"; |
| DCHECK(message->type() == BlimpMessage::TAB_CONTROL || |
| message->type() == BlimpMessage::NAVIGATION); |
| @@ -304,6 +262,29 @@ void BlimpEngineSession::ProcessMessage( |
| } |
| } |
| +void BlimpEngineSession::InitializeNetwork() { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| + DCHECK(!connection_handler_); |
| + |
| + // Create a handler chain for BlimpConnections. |
| + // Newly connected BlimpConnections are passed from |
| + // connection_manager_ --> authentication_handler_ --> connection_handler_. |
| + connection_handler_.reset(new BrowserConnectionHandler); |
| + authentication_handler_.reset( |
| + new EngineAuthenticationHandler(connection_handler_.get())); |
| + connection_manager_.reset( |
| + new EngineConnectionManager(authentication_handler_.get())); |
| + |
| + // Adds BlimpTransports to connection_manager_. |
| + // TODO(kmarshall): Take transport configuration from parameters. |
| + net::IPAddressNumber local_ip_any; |
| + bool success = net::ParseIPLiteralToNumber("0.0.0.0", &local_ip_any); |
| + CHECK(success); |
| + net::IPEndPoint address(local_ip_any, kDefaultTcpPort); |
| + connection_manager_->AddTransport( |
| + make_scoped_ptr(new TCPEngineTransport(address, net_log_))); |
| +} |
| + |
| void BlimpEngineSession::AddNewContents(content::WebContents* source, |
| content::WebContents* new_contents, |
| WindowOpenDisposition disposition, |