| 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/values.h" | 18 #include "base/values.h" |
| 19 #include "blimp/client/app/blimp_client_switches.h" | 19 #include "blimp/client/app/blimp_client_switches.h" |
| 20 #include "blimp/common/protocol_version.h" | 20 #include "blimp/common/version_info.h" |
| 21 #include "components/safe_json/safe_json_parser.h" | 21 #include "components/safe_json/safe_json_parser.h" |
| 22 #include "net/base/ip_address.h" | 22 #include "net/base/ip_address.h" |
| 23 #include "net/base/ip_endpoint.h" | 23 #include "net/base/ip_endpoint.h" |
| 24 #include "net/base/load_flags.h" | 24 #include "net/base/load_flags.h" |
| 25 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
| 26 #include "net/http/http_status_code.h" | 26 #include "net/http/http_status_code.h" |
| 27 #include "net/proxy/proxy_config_service.h" | 27 #include "net/proxy/proxy_config_service.h" |
| 28 #include "net/proxy/proxy_service.h" | 28 #include "net/proxy/proxy_service.h" |
| 29 #include "net/url_request/url_fetcher.h" | 29 #include "net/url_request/url_fetcher.h" |
| 30 #include "net/url_request/url_request_context.h" | 30 #include "net/url_request/url_request_context.h" |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 url_fetcher_ = | 237 url_fetcher_ = |
| 238 net::URLFetcher::Create(assigner_endpoint_, net::URLFetcher::POST, this); | 238 net::URLFetcher::Create(assigner_endpoint_, net::URLFetcher::POST, this); |
| 239 url_fetcher_->SetRequestContext(url_request_context_.get()); | 239 url_fetcher_->SetRequestContext(url_request_context_.get()); |
| 240 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | | 240 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | |
| 241 net::LOAD_DO_NOT_SEND_COOKIES); | 241 net::LOAD_DO_NOT_SEND_COOKIES); |
| 242 url_fetcher_->AddExtraRequestHeader("Authorization: Bearer " + | 242 url_fetcher_->AddExtraRequestHeader("Authorization: Bearer " + |
| 243 client_auth_token); | 243 client_auth_token); |
| 244 | 244 |
| 245 // Write the JSON for the request data. | 245 // Write the JSON for the request data. |
| 246 base::DictionaryValue dictionary; | 246 base::DictionaryValue dictionary; |
| 247 dictionary.SetString(kProtocolVersionKey, blimp::kEngineVersion); | 247 dictionary.SetString(kProtocolVersionKey, GetAssignmentRequestVersion()); |
| 248 std::string json; | 248 std::string json; |
| 249 base::JSONWriter::Write(dictionary, &json); | 249 base::JSONWriter::Write(dictionary, &json); |
| 250 url_fetcher_->SetUploadData("application/json", json); | 250 url_fetcher_->SetUploadData("application/json", json); |
| 251 url_fetcher_->Start(); | 251 url_fetcher_->Start(); |
| 252 } | 252 } |
| 253 | 253 |
| 254 void AssignmentSource::OnURLFetchComplete(const net::URLFetcher* source) { | 254 void AssignmentSource::OnURLFetchComplete(const net::URLFetcher* source) { |
| 255 DCHECK(!callback_.is_null()); | 255 DCHECK(!callback_.is_null()); |
| 256 DCHECK_EQ(url_fetcher_.get(), source); | 256 DCHECK_EQ(url_fetcher_.get(), source); |
| 257 | 257 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 } | 372 } |
| 373 | 373 |
| 374 void AssignmentSource::OnJsonParseError(const std::string& error) { | 374 void AssignmentSource::OnJsonParseError(const std::string& error) { |
| 375 DLOG(ERROR) << "Error while parsing assigner JSON: " << error; | 375 DLOG(ERROR) << "Error while parsing assigner JSON: " << error; |
| 376 base::ResetAndReturn(&callback_) | 376 base::ResetAndReturn(&callback_) |
| 377 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 377 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); |
| 378 } | 378 } |
| 379 | 379 |
| 380 } // namespace client | 380 } // namespace client |
| 381 } // namespace blimp | 381 } // namespace blimp |
| OLD | NEW |