Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/session/assignment_source.h" | 5 #include "blimp/client/session/assignment_source.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
| 12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/numerics/safe_conversions.h" | 15 #include "base/numerics/safe_conversions.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/task_runner_util.h" | 17 #include "base/task_runner_util.h" |
| 18 #include "base/threading/thread_restrictions.h" | |
| 18 #include "base/values.h" | 19 #include "base/values.h" |
| 19 #include "blimp/client/app/blimp_client_switches.h" | 20 #include "blimp/client/app/blimp_client_switches.h" |
| 21 #include "blimp/common/get_client_token.h" | |
| 20 #include "blimp/common/protocol_version.h" | 22 #include "blimp/common/protocol_version.h" |
| 21 #include "components/safe_json/safe_json_parser.h" | 23 #include "components/safe_json/safe_json_parser.h" |
| 22 #include "net/base/ip_address.h" | 24 #include "net/base/ip_address.h" |
| 23 #include "net/base/ip_endpoint.h" | 25 #include "net/base/ip_endpoint.h" |
| 24 #include "net/base/load_flags.h" | 26 #include "net/base/load_flags.h" |
| 25 #include "net/base/net_errors.h" | 27 #include "net/base/net_errors.h" |
| 26 #include "net/http/http_status_code.h" | 28 #include "net/http/http_status_code.h" |
| 27 #include "net/proxy/proxy_config_service.h" | 29 #include "net/proxy/proxy_config_service.h" |
| 28 #include "net/proxy/proxy_service.h" | 30 #include "net/proxy/proxy_service.h" |
| 29 #include "net/url_request/url_fetcher.h" | 31 #include "net/url_request/url_fetcher.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 | 94 |
| 93 bool IsValidIpPortNumber(unsigned port) { | 95 bool IsValidIpPortNumber(unsigned port) { |
| 94 return port > 0 && port <= 65535; | 96 return port > 0 && port <= 65535; |
| 95 } | 97 } |
| 96 | 98 |
| 97 // Populates an Assignment using command-line parameters, if provided. | 99 // Populates an Assignment using command-line parameters, if provided. |
| 98 // Returns a null Assignment if no parameters were set. | 100 // Returns a null Assignment if no parameters were set. |
| 99 // Must be called on a thread suitable for file IO. | 101 // Must be called on a thread suitable for file IO. |
| 100 Assignment GetAssignmentFromCommandLine() { | 102 Assignment GetAssignmentFromCommandLine() { |
| 101 Assignment assignment; | 103 Assignment assignment; |
| 102 assignment.client_token = kDummyClientToken; | 104 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 105 assignment.client_token = GetClientToken(*cmd_line); | |
|
Kevin M
2016/05/10 18:06:34
Add newline before this line, to visually separate
Kevin M
2016/05/10 18:06:34
What's the behavior if the token isn't specified?
Kevin M
2016/05/10 18:06:34
You can just pass the result of ForCurrentProcess(
CJ
2016/05/10 20:58:06
Done.
CJ
2016/05/10 20:58:06
Adding an assert here such that client_token does
CJ
2016/05/10 20:58:06
Keeping it, since in a later comment, you suggest
| |
| 103 | 106 |
| 104 unsigned port_parsed = 0; | 107 unsigned port_parsed = 0; |
| 105 if (!base::StringToUint( | 108 if (!base::StringToUint( |
| 106 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 109 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
|
Kevin M
2016/05/10 18:06:34
You can replace all calls to base::CommandLine::Fo
CJ
2016/05/10 20:58:06
Done.
| |
| 107 switches::kEnginePort), | 110 switches::kEnginePort), |
| 108 &port_parsed) || | 111 &port_parsed) || |
| 109 !IsValidIpPortNumber(port_parsed)) { | 112 !IsValidIpPortNumber(port_parsed)) { |
| 110 DLOG(FATAL) << "--engine-port must be a value between 1 and 65535."; | 113 DLOG(FATAL) << "--engine-port must be a value between 1 and 65535."; |
| 111 return Assignment(); | 114 return Assignment(); |
| 112 } | 115 } |
| 113 | 116 |
| 114 net::IPAddress ip_address; | 117 net::IPAddress ip_address; |
| 115 std::string ip_str = | 118 std::string ip_str = |
| 116 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 119 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 } | 375 } |
| 373 | 376 |
| 374 void AssignmentSource::OnJsonParseError(const std::string& error) { | 377 void AssignmentSource::OnJsonParseError(const std::string& error) { |
| 375 DLOG(ERROR) << "Error while parsing assigner JSON: " << error; | 378 DLOG(ERROR) << "Error while parsing assigner JSON: " << error; |
| 376 base::ResetAndReturn(&callback_) | 379 base::ResetAndReturn(&callback_) |
| 377 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 380 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); |
| 378 } | 381 } |
| 379 | 382 |
| 380 } // namespace client | 383 } // namespace client |
| 381 } // namespace blimp | 384 } // namespace blimp |
| OLD | NEW |