summaryrefslogtreecommitdiffstats
path: root/blimp/client/session/blimp_client_session.cc
diff options
context:
space:
mode:
Diffstat (limited to 'blimp/client/session/blimp_client_session.cc')
-rw-r--r--blimp/client/session/blimp_client_session.cc95
1 files changed, 34 insertions, 61 deletions
diff --git a/blimp/client/session/blimp_client_session.cc b/blimp/client/session/blimp_client_session.cc
index 3c310f5..e681a0a 100644
--- a/blimp/client/session/blimp_client_session.cc
+++ b/blimp/client/session/blimp_client_session.cc
@@ -28,52 +28,6 @@
namespace blimp {
namespace client {
-namespace {
-
-// TODO(kmarshall): Take values from configuration data.
-const char kDummyClientToken[] = "MyVoiceIsMyPassport";
-const std::string kDefaultBlimpletIPAddress = "127.0.0.1";
-const uint16_t kDefaultBlimpletTCPPort = 25467;
-
-// A BlimpletAssignment contains the configuration data needed for a client
-// to connect to the engine.
-struct BlimpletAssignment {
- net::IPEndPoint ip_endpoint;
-};
-
-net::IPAddress GetBlimpletIPAddress() {
- std::string host;
- if (base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kBlimpletHost)) {
- host = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
- switches::kBlimpletHost);
- } else {
- host = kDefaultBlimpletIPAddress;
- }
- net::IPAddress ip_address;
- if (!net::IPAddress::FromIPLiteral(host, &ip_address))
- CHECK(false) << "Invalid BlimpletAssignment host " << host;
- return ip_address;
-}
-
-uint16_t GetBlimpletTCPPort() {
- if (base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kBlimpletTCPPort)) {
- std::string port_str =
- base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
- switches::kBlimpletTCPPort);
- uint port_64t;
- if (!base::StringToUint(port_str, &port_64t) ||
- !base::IsValueInRangeForNumericType<uint16_t>(port_64t)) {
- CHECK(false) << "Invalid BlimpletAssignment port " << port_str;
- }
- return base::checked_cast<uint16_t>(port_64t);
- } else {
- return kDefaultBlimpletTCPPort;
- }
-}
-
-} // namespace
// This class's functions and destruction are all invoked on the IO thread by
// the BlimpClientSession.
@@ -85,8 +39,12 @@ class ClientNetworkComponents {
~ClientNetworkComponents() {}
- // Sets up network components and starts to connect to the engine.
- void Initialize(const net::AddressList& address_list);
+ // Sets up network components.
+ void Initialize();
+
+ // Starts the connection to the engine using the given |assignment|.
+ // It is required to first call Initialize.
+ void ConnectWithAssignment(const Assignment& assignment);
// Invoked by BlimpEngineSession to finish feature registration on IO thread:
// using |incoming_proxy| as the incoming message processor, and connecting
@@ -111,14 +69,19 @@ class ClientNetworkComponents {
DISALLOW_COPY_AND_ASSIGN(ClientNetworkComponents);
};
-void ClientNetworkComponents::Initialize(const net::AddressList& address_list) {
+void ClientNetworkComponents::Initialize() {
DCHECK(!connection_manager_);
connection_manager_ = make_scoped_ptr(
new ClientConnectionManager(browser_connection_handler_.get()));
- connection_manager_->set_client_token(kDummyClientToken);
+}
+
+void ClientNetworkComponents::ConnectWithAssignment(
+ const Assignment& assignment) {
+ DCHECK(connection_manager_);
+ connection_manager_->set_client_token(assignment.client_token);
- connection_manager_->AddTransport(
- make_scoped_ptr(new TCPClientTransport(address_list, nullptr)));
+ connection_manager_->AddTransport(make_scoped_ptr(new TCPClientTransport(
+ net::AddressList(assignment.ip_endpoint), nullptr)));
connection_manager_->Connect();
}
@@ -143,12 +106,15 @@ void ClientNetworkComponents::RegisterFeature(
outgoing_message_processors_.push_back(std::move(outgoing_message_processor));
}
-BlimpClientSession::BlimpClientSession()
- : io_thread_("BlimpIOThread"),
+BlimpClientSession::BlimpClientSession(
+ scoped_ptr<AssignmentSource> assignment_source)
+ : assignment_source_(std::move(assignment_source)),
+ io_thread_("BlimpIOThread"),
tab_control_feature_(new TabControlFeature),
navigation_feature_(new NavigationFeature),
render_widget_feature_(new RenderWidgetFeature),
- net_components_(new ClientNetworkComponents) {
+ net_components_(new ClientNetworkComponents),
+ weak_factory_(this) {
base::Thread::Options options;
options.message_loop_type = base::MessageLoop::TYPE_IO;
io_thread_.StartWithOptions(options);
@@ -171,14 +137,25 @@ BlimpClientSession::BlimpClientSession()
// completed.
io_thread_.task_runner()->PostTask(
FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize,
- base::Unretained(net_components_.get()),
- net::AddressList(GetBlimpletIPEndpoint())));
+ base::Unretained(net_components_.get())));
}
BlimpClientSession::~BlimpClientSession() {
io_thread_.task_runner()->DeleteSoon(FROM_HERE, net_components_.release());
}
+void BlimpClientSession::Connect() {
+ assignment_source_->GetAssignment(base::Bind(
+ &BlimpClientSession::ConnectWithAssignment, weak_factory_.GetWeakPtr()));
+}
+
+void BlimpClientSession::ConnectWithAssignment(const Assignment& assignment) {
+ io_thread_.task_runner()->PostTask(
+ FROM_HERE,
+ base::Bind(&ClientNetworkComponents::ConnectWithAssignment,
+ base::Unretained(net_components_.get()), assignment));
+}
+
scoped_ptr<BlimpMessageProcessor> BlimpClientSession::RegisterFeature(
BlimpMessage::Type type,
BlimpMessageProcessor* incoming_processor) {
@@ -220,9 +197,5 @@ RenderWidgetFeature* BlimpClientSession::GetRenderWidgetFeature() const {
return render_widget_feature_.get();
}
-net::IPEndPoint BlimpClientSession::GetBlimpletIPEndpoint() {
- return net::IPEndPoint(GetBlimpletIPAddress(), GetBlimpletTCPPort());
-}
-
} // namespace client
} // namespace blimp