Commit 0660ba5c authored by Junbo Ke's avatar Junbo Ke Committed by Commit Bot

[Chromecast] Remove an unnecessary field from SubstitutableParameter.

|is_for_auth| is unnecessary since we only need to know which headers
are signature.

Bug: b/162380916
Merge-With: eureka-internal/444720
Test: On device
Change-Id: Icd46e0b88d55de83cbfc1d43fb7584c25999d421
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2382714Reviewed-by: default avatarSean Topping <seantopping@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Junbo Ke <juke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805902}
parent 63227bd5
...@@ -31,10 +31,6 @@ struct SubstitutableParameter { ...@@ -31,10 +31,6 @@ struct SubstitutableParameter {
// `ClientAuthDelegate` // `ClientAuthDelegate`
bool is_signature; bool is_signature;
// Whether the header is used for authentication. If |is_signature| is true,
// |is_for_auth| must also be true.
bool is_for_auth;
// Value of the header. // Value of the header.
string value; string value;
}; };
......
...@@ -98,7 +98,6 @@ std::string ReplacementMapToString( ...@@ -98,7 +98,6 @@ std::string ReplacementMapToString(
IdentificationSettingsManager::SubstitutableParameter IdentificationSettingsManager::SubstitutableParameter
IdentificationSettingsManager::ConvertSubstitutableParameterFromMojom( IdentificationSettingsManager::ConvertSubstitutableParameterFromMojom(
mojom::SubstitutableParameterPtr mojo_param) { mojom::SubstitutableParameterPtr mojo_param) {
DCHECK(!mojo_param->is_signature || mojo_param->is_for_auth);
IdentificationSettingsManager::SubstitutableParameter param; IdentificationSettingsManager::SubstitutableParameter param;
param.name = mojo_param->name; param.name = mojo_param->name;
if (mojo_param->replacement_token.has_value()) { if (mojo_param->replacement_token.has_value()) {
...@@ -109,7 +108,6 @@ IdentificationSettingsManager::ConvertSubstitutableParameterFromMojom( ...@@ -109,7 +108,6 @@ IdentificationSettingsManager::ConvertSubstitutableParameterFromMojom(
} }
param.is_signature = mojo_param->is_signature; param.is_signature = mojo_param->is_signature;
param.value = mojo_param->value; param.value = mojo_param->value;
param.is_for_auth = mojo_param->is_for_auth;
return param; return param;
} }
...@@ -415,7 +413,6 @@ void IdentificationSettingsManager::AnalyzeAndReplaceQueryString( ...@@ -415,7 +413,6 @@ void IdentificationSettingsManager::AnalyzeAndReplaceQueryString(
base::StringPiece input = orig_url.query_piece(); base::StringPiece input = orig_url.query_piece();
std::string output = orig_url.query() + "&"; // Helps with an edge case. std::string output = orig_url.query() + "&"; // Helps with an edge case.
bool need_replacement = false; bool need_replacement = false;
uint32_t i = 0;
for (auto& p : *params) { for (auto& p : *params) {
if (!p.replacement_token.empty() && if (!p.replacement_token.empty() &&
input.find(p.replacement_token) != std::string::npos) { input.find(p.replacement_token) != std::string::npos) {
...@@ -423,8 +420,7 @@ void IdentificationSettingsManager::AnalyzeAndReplaceQueryString( ...@@ -423,8 +420,7 @@ void IdentificationSettingsManager::AnalyzeAndReplaceQueryString(
p.need_query = true; p.need_query = true;
need_replacement = true; need_replacement = true;
std::string replacement_value = net::EscapeQueryParamValue( std::string replacement_value = net::EscapeQueryParamValue(p.value, true);
p.is_for_auth ? GetAuthHeader(i) : p.value, true);
base::ReplaceSubstringsAfterOffset(&output, 0, p.replacement_token, base::ReplaceSubstringsAfterOffset(&output, 0, p.replacement_token,
replacement_value); replacement_value);
} else if (!p.suppression_token.empty() && } else if (!p.suppression_token.empty() &&
...@@ -440,7 +436,6 @@ void IdentificationSettingsManager::AnalyzeAndReplaceQueryString( ...@@ -440,7 +436,6 @@ void IdentificationSettingsManager::AnalyzeAndReplaceQueryString(
base::ReplaceSubstringsAfterOffset(&output, 0, "&&", "&"); base::ReplaceSubstringsAfterOffset(&output, 0, "&&", "&");
} while (output.find("&&") != std::string::npos); } while (output.find("&&") != std::string::npos);
} }
++i;
} }
if (need_replacement) { if (need_replacement) {
size_t last_pos = output.size() - 1; size_t last_pos = output.size() - 1;
...@@ -463,23 +458,13 @@ void IdentificationSettingsManager::AddHttpHeaders( ...@@ -463,23 +458,13 @@ void IdentificationSettingsManager::AddHttpHeaders(
continue; continue;
} }
if (!p.suppress_header) { if (!p.suppress_header) {
const std::string& value = p.is_for_auth ? GetAuthHeader(i) : p.value; if (!p.value.empty())
if (!value.empty()) headers->SetHeaderIfMissing(p.name, p.value);
headers->SetHeaderIfMissing(p.name, value);
} }
++i; ++i;
} }
} }
void IdentificationSettingsManager::UpdateAuthHeaders(
std::vector<chromecast::mojom::IndexValuePairPtr> auth_headers) {
lock_.AssertAcquired();
for (auto& auth_header : auth_headers) {
DCHECK(auth_header->index < substitutable_params_.size());
auth_headers_[auth_header->index] = auth_header->value;
}
}
bool IdentificationSettingsManager::IsAppAllowedForDeviceIdentification() bool IdentificationSettingsManager::IsAppAllowedForDeviceIdentification()
const { const {
return is_allowed_for_device_identification_; return is_allowed_for_device_identification_;
...@@ -604,7 +589,7 @@ void IdentificationSettingsManager::SignatureComplete( ...@@ -604,7 +589,7 @@ void IdentificationSettingsManager::SignatureComplete(
if (!signature_headers.empty()) { if (!signature_headers.empty()) {
next_refresh_time_ = next_refresh_time; next_refresh_time_ = next_refresh_time;
} }
UpdateAuthHeaders(std::move(signature_headers)); UpdateSubstitutableParamValues(std::move(signature_headers));
create_signature_in_progress_ = false; create_signature_in_progress_ = false;
} }
...@@ -615,7 +600,7 @@ void IdentificationSettingsManager::SignatureComplete( ...@@ -615,7 +600,7 @@ void IdentificationSettingsManager::SignatureComplete(
int IdentificationSettingsManager::EnsureCerts() { int IdentificationSettingsManager::EnsureCerts() {
lock_.AssertAcquired(); lock_.AssertAcquired();
if (!auth_headers_.empty()) if (cert_initialized_)
return net::OK; return net::OK;
if (create_cert_in_progress_) if (create_cert_in_progress_)
...@@ -635,20 +620,11 @@ void IdentificationSettingsManager::InitCerts( ...@@ -635,20 +620,11 @@ void IdentificationSettingsManager::InitCerts(
std::vector<chromecast::mojom::IndexValuePairPtr> cert_headers) { std::vector<chromecast::mojom::IndexValuePairPtr> cert_headers) {
{ {
base::AutoLock lock(lock_); base::AutoLock lock(lock_);
UpdateAuthHeaders(std::move(cert_headers)); UpdateSubstitutableParamValues(std::move(cert_headers));
create_cert_in_progress_ = false; create_cert_in_progress_ = false;
cert_initialized_ = true;
} }
CreateSignatureAsync(); CreateSignatureAsync();
} }
std::string IdentificationSettingsManager::GetAuthHeader(uint32_t index) const {
base::AutoLock lock(lock_);
const auto& it = auth_headers_.find(index);
if (it == auth_headers_.end()) {
LOG(ERROR) << "Auth header is not available: " << index;
return std::string();
}
return it->second;
}
} // namespace chromecast } // namespace chromecast
...@@ -71,10 +71,9 @@ class IdentificationSettingsManager ...@@ -71,10 +71,9 @@ class IdentificationSettingsManager
std::string name; std::string name;
std::string replacement_token; std::string replacement_token;
std::string suppression_token; std::string suppression_token;
bool is_signature; bool is_signature = false;
bool suppress_header = false; bool suppress_header = false;
bool need_query = false; bool need_query = false;
bool is_for_auth;
std::string value; std::string value;
}; };
...@@ -185,9 +184,8 @@ class IdentificationSettingsManager ...@@ -185,9 +184,8 @@ class IdentificationSettingsManager
// Whether a signature creation request is sent. // Whether a signature creation request is sent.
bool create_signature_in_progress_ GUARDED_BY(lock_) = false; bool create_signature_in_progress_ GUARDED_BY(lock_) = false;
// Header indices should align with the indices in |substitutable_params_|. // Whether certificates have been initialized.
base::flat_map<uint32_t /* header_index */, std::string /* header_value */> bool cert_initialized_ GUARDED_BY(lock_) = false;
auth_headers_ GUARDED_BY(lock_);
// When the next time the signature needs to be refreshed. // When the next time the signature needs to be refreshed.
base::Time next_refresh_time_ GUARDED_BY(lock_); base::Time next_refresh_time_ GUARDED_BY(lock_);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment