summaryrefslogtreecommitdiffstats
path: root/blimp/client/session/assignment_source.cc
diff options
context:
space:
mode:
authornyquist <nyquist@chromium.org>2016-02-01 20:49:33 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-02 04:54:47 +0000
commit7dbd1d2d73f422d197337abf08ed0dc7c99d3e0d (patch)
tree0306c235d2f3eb78838187442bd9cb6087faaa22 /blimp/client/session/assignment_source.cc
parentafc918de00a2f2895b4d8eaf3a043e654ba5e8fb (diff)
downloadchromium_src-7dbd1d2d73f422d197337abf08ed0dc7c99d3e0d.zip
chromium_src-7dbd1d2d73f422d197337abf08ed0dc7c99d3e0d.tar.gz
chromium_src-7dbd1d2d73f422d197337abf08ed0dc7c99d3e0d.tar.bz2
Add initial framework for AssignmentSource.
This CL moves reading the command line params for engine connection to a default AssignmentSource instead of being a part of BlimpClientSession. This is required going forward to be able to implement something that communicates with the real assigner. In addition this CL also makes the connection step asynchronous instead of happening during the construction of the BlimpClientSession. This is important so that going forward, the request to get an assignment does not block startup. BUG=582668 Review URL: https://codereview.chromium.org/1648383004 Cr-Commit-Position: refs/heads/master@{#372892}
Diffstat (limited to 'blimp/client/session/assignment_source.cc')
-rw-r--r--blimp/client/session/assignment_source.cc76
1 files changed, 76 insertions, 0 deletions
diff --git a/blimp/client/session/assignment_source.cc b/blimp/client/session/assignment_source.cc
new file mode 100644
index 0000000..271569c
--- /dev/null
+++ b/blimp/client/session/assignment_source.cc
@@ -0,0 +1,76 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "blimp/client/session/assignment_source.h"
+
+#include "base/bind.h"
+#include "base/command_line.h"
+#include "base/location.h"
+#include "base/numerics/safe_conversions.h"
+#include "base/strings/string_number_conversions.h"
+#include "blimp/client/app/blimp_client_switches.h"
+#include "net/base/ip_address.h"
+#include "net/base/ip_endpoint.h"
+
+namespace blimp {
+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;
+
+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
+
+namespace client {
+
+AssignmentSource::AssignmentSource(
+ const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner)
+ : main_task_runner_(main_task_runner) {}
+
+AssignmentSource::~AssignmentSource() {}
+
+void AssignmentSource::GetAssignment(const AssignmentCallback& callback) {
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
+ Assignment assignment;
+ assignment.ip_endpoint =
+ net::IPEndPoint(GetBlimpletIPAddress(), GetBlimpletTCPPort());
+ assignment.client_token = kDummyClientToken;
+ main_task_runner_->PostTask(FROM_HERE, base::Bind(callback, assignment));
+}
+
+} // namespace client
+} // namespace blimp