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

Side by Side Diff: blimp/client/core/session/assignment_source.cc

Issue 2281783002: Changes client_token to be client_auth_token. (Closed)
Patch Set: Linting. Created 4 years, 3 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
« no previous file with comments | « no previous file | blimp/client/core/session/assignment_source_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/client/core/session/assignment_source.h" 5 #include "blimp/client/core/session/assignment_source.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/callback_helpers.h" 11 #include "base/callback_helpers.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/json/json_reader.h" 14 #include "base/json/json_reader.h"
15 #include "base/json/json_writer.h" 15 #include "base/json/json_writer.h"
16 #include "base/location.h" 16 #include "base/location.h"
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
18 #include "base/numerics/safe_conversions.h" 18 #include "base/numerics/safe_conversions.h"
19 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
20 #include "base/task_runner_util.h" 20 #include "base/task_runner_util.h"
21 #include "base/threading/thread_restrictions.h" 21 #include "base/threading/thread_restrictions.h"
22 #include "base/values.h" 22 #include "base/values.h"
23 #include "blimp/client/core/blimp_client_switches.h" 23 #include "blimp/client/core/blimp_client_switches.h"
24 #include "blimp/common/get_client_token.h" 24 #include "blimp/common/get_client_auth_token.h"
25 #include "blimp/common/protocol_version.h" 25 #include "blimp/common/protocol_version.h"
26 #include "components/safe_json/safe_json_parser.h" 26 #include "components/safe_json/safe_json_parser.h"
27 #include "net/base/ip_address.h" 27 #include "net/base/ip_address.h"
28 #include "net/base/ip_endpoint.h" 28 #include "net/base/ip_endpoint.h"
29 #include "net/base/load_flags.h" 29 #include "net/base/load_flags.h"
30 #include "net/base/net_errors.h" 30 #include "net/base/net_errors.h"
31 #include "net/http/http_status_code.h" 31 #include "net/http/http_status_code.h"
32 #include "net/proxy/proxy_config_service.h" 32 #include "net/proxy/proxy_config_service.h"
33 #include "net/proxy/proxy_service.h" 33 #include "net/proxy/proxy_service.h"
34 #include "net/url_request/url_fetcher.h" 34 #include "net/url_request/url_fetcher.h"
35 #include "net/url_request/url_request_context.h" 35 #include "net/url_request/url_request_context.h"
36 #include "net/url_request/url_request_context_builder.h" 36 #include "net/url_request/url_request_context_builder.h"
37 #include "net/url_request/url_request_context_getter.h" 37 #include "net/url_request/url_request_context_getter.h"
38 38
39 namespace blimp { 39 namespace blimp {
40 namespace client { 40 namespace client {
41 41
42 namespace { 42 namespace {
43 43
44 // Assignment request JSON keys. 44 // Assignment request JSON keys.
45 const char kProtocolVersionKey[] = "protocol_version"; 45 const char kProtocolVersionKey[] = "protocol_version";
46 46
47 // Assignment response JSON keys. 47 // Assignment response JSON keys.
48 const char kClientTokenKey[] = "clientToken"; 48 const char kClientAuthTokenKey[] = "clientToken";
49 const char kHostKey[] = "host"; 49 const char kHostKey[] = "host";
50 const char kPortKey[] = "port"; 50 const char kPortKey[] = "port";
51 const char kCertificateKey[] = "certificate"; 51 const char kCertificateKey[] = "certificate";
52 52
53 // Possible arguments for the "--engine-transport" command line parameter. 53 // Possible arguments for the "--engine-transport" command line parameter.
54 const char kSSLTransportValue[] = "ssl"; 54 const char kSSLTransportValue[] = "ssl";
55 const char kTCPTransportValue[] = "tcp"; 55 const char kTCPTransportValue[] = "tcp";
56 56
57 class SimpleURLRequestContextGetter : public net::URLRequestContextGetter { 57 class SimpleURLRequestContextGetter : public net::URLRequestContextGetter {
58 public: 58 public:
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 return port > 0 && port <= 65535; 104 return port > 0 && port <= 65535;
105 } 105 }
106 106
107 // Populates an Assignment using command-line parameters, if provided. 107 // Populates an Assignment using command-line parameters, if provided.
108 // Returns a null Assignment if no parameters were set. 108 // Returns a null Assignment if no parameters were set.
109 // Must be called on a thread suitable for file IO. 109 // Must be called on a thread suitable for file IO.
110 Assignment GetAssignmentFromCommandLine() { 110 Assignment GetAssignmentFromCommandLine() {
111 Assignment assignment; 111 Assignment assignment;
112 112
113 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); 113 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
114 assignment.client_token = GetClientToken(*cmd_line); 114 assignment.client_auth_token = GetClientAuthToken(*cmd_line);
115 CHECK(!assignment.client_token.empty()) << "No client token provided."; 115 CHECK(!assignment.client_auth_token.empty())
116 << "No client auth token provided.";
116 117
117 unsigned port_parsed = 0; 118 unsigned port_parsed = 0;
118 if (!base::StringToUint( 119 if (!base::StringToUint(
119 cmd_line->GetSwitchValueASCII(switches::kEnginePort), 120 cmd_line->GetSwitchValueASCII(switches::kEnginePort),
120 &port_parsed) || !IsValidIpPortNumber(port_parsed)) { 121 &port_parsed) || !IsValidIpPortNumber(port_parsed)) {
121 DLOG(FATAL) << "--engine-port must be a value between 1 and 65535."; 122 DLOG(FATAL) << "--engine-port must be a value between 1 and 65535.";
122 return Assignment(); 123 return Assignment();
123 } 124 }
124 125
125 net::IPAddress ip_address; 126 net::IPAddress ip_address;
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 void AssignmentSource::OnJsonParsed(std::unique_ptr<base::Value> json) { 313 void AssignmentSource::OnJsonParsed(std::unique_ptr<base::Value> json) {
313 const base::DictionaryValue* dict; 314 const base::DictionaryValue* dict;
314 if (!json->GetAsDictionary(&dict)) { 315 if (!json->GetAsDictionary(&dict)) {
315 LOG(WARNING) << "Unable to parse JSON data as a dictionary."; 316 LOG(WARNING) << "Unable to parse JSON data as a dictionary.";
316 base::ResetAndReturn(&callback_) 317 base::ResetAndReturn(&callback_)
317 .Run(ASSIGNMENT_REQUEST_RESULT_BAD_RESPONSE, Assignment()); 318 .Run(ASSIGNMENT_REQUEST_RESULT_BAD_RESPONSE, Assignment());
318 return; 319 return;
319 } 320 }
320 321
321 // Validate that all the expected fields are present. 322 // Validate that all the expected fields are present.
322 std::string client_token; 323 std::string client_auth_token;
323 std::string host; 324 std::string host;
324 int port; 325 int port;
325 std::string cert_str; 326 std::string cert_str;
326 if (!(dict->GetString(kClientTokenKey, &client_token) && 327 if (!(dict->GetString(kClientAuthTokenKey, &client_auth_token) &&
327 dict->GetString(kHostKey, &host) && dict->GetInteger(kPortKey, &port) && 328 dict->GetString(kHostKey, &host) && dict->GetInteger(kPortKey, &port) &&
328 dict->GetString(kCertificateKey, &cert_str))) { 329 dict->GetString(kCertificateKey, &cert_str))) {
329 LOG(WARNING) << "Not all fields present in assignment JSON data."; 330 LOG(WARNING) << "Not all fields present in assignment JSON data.";
330 base::ResetAndReturn(&callback_) 331 base::ResetAndReturn(&callback_)
331 .Run(ASSIGNMENT_REQUEST_RESULT_BAD_RESPONSE, Assignment()); 332 .Run(ASSIGNMENT_REQUEST_RESULT_BAD_RESPONSE, Assignment());
332 return; 333 return;
333 } 334 }
334 335
335 net::IPAddress ip_address; 336 net::IPAddress ip_address;
336 if (!ip_address.AssignFromIPLiteral(host)) { 337 if (!ip_address.AssignFromIPLiteral(host)) {
(...skipping 18 matching lines...) Expand all
355 base::ResetAndReturn(&callback_) 356 base::ResetAndReturn(&callback_)
356 .Run(ASSIGNMENT_REQUEST_RESULT_INVALID_CERT, Assignment()); 357 .Run(ASSIGNMENT_REQUEST_RESULT_INVALID_CERT, Assignment());
357 return; 358 return;
358 } 359 }
359 360
360 // The assigner assumes SSL-only and all engines it assigns only communicate 361 // The assigner assumes SSL-only and all engines it assigns only communicate
361 // over SSL. 362 // over SSL.
362 Assignment assignment; 363 Assignment assignment;
363 assignment.transport_protocol = Assignment::TransportProtocol::SSL; 364 assignment.transport_protocol = Assignment::TransportProtocol::SSL;
364 assignment.engine_endpoint = net::IPEndPoint(ip_address, port); 365 assignment.engine_endpoint = net::IPEndPoint(ip_address, port);
365 assignment.client_token = client_token; 366 assignment.client_auth_token = client_auth_token;
366 assignment.cert = std::move(cert_list[0]); 367 assignment.cert = std::move(cert_list[0]);
367 368
368 base::ResetAndReturn(&callback_) 369 base::ResetAndReturn(&callback_)
369 .Run(ASSIGNMENT_REQUEST_RESULT_OK, assignment); 370 .Run(ASSIGNMENT_REQUEST_RESULT_OK, assignment);
370 } 371 }
371 372
372 void AssignmentSource::OnJsonParseError(const std::string& error) { 373 void AssignmentSource::OnJsonParseError(const std::string& error) {
373 DLOG(ERROR) << "Error while parsing assigner JSON: " << error; 374 DLOG(ERROR) << "Error while parsing assigner JSON: " << error;
374 base::ResetAndReturn(&callback_) 375 base::ResetAndReturn(&callback_)
375 .Run(ASSIGNMENT_REQUEST_RESULT_BAD_RESPONSE, Assignment()); 376 .Run(ASSIGNMENT_REQUEST_RESULT_BAD_RESPONSE, Assignment());
376 } 377 }
377 378
378 } // namespace client 379 } // namespace client
379 } // namespace blimp 380 } // namespace blimp
OLDNEW
« no previous file with comments | « no previous file | blimp/client/core/session/assignment_source_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698