constexpr base::TimeDelta kPasskeyUpgradeRecencyThreshold = base::Minutes(5);
std::string GetRpId(const GURL& url) {
std::string rp_id = net::registry_controlled_domains::GetDomainAndRegistry(missing comments
std::string domain_rp_id =
net::registry_controlled_domains::GetDomainAndRegistry(
rp_id, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
if (domain_rp_id.empty()) {
domain_rp_id = rp_id;
}This code is almost the same as `GetRpId`. I *think* this can be deduplicated this way (to be verified):
```
std::string GetDomainAndRegistryOrHost(std::string_view host) {
std::string domain = net::registry_controlled_domains::GetDomainAndRegistry(
host, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
return domain.empty() ? std::string(host) : domain;
}
```
1st call site:
```
std::string domain_rp_id = GetDomainAndRegistryOrHost(params.RpId());
```
2nd call site:
```
`GetDomainAndRegistryOrHost(form->url.host()) == domain_rp_id`
```
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
constexpr base::TimeDelta kPasskeyUpgradeRecencyThreshold = base::Minutes(5);
std::string GetRpId(const GURL& url) {
std::string rp_id = net::registry_controlled_domains::GetDomainAndRegistry(Sourav Uttam Sinhamissing comments
Done
std::string domain_rp_id =
net::registry_controlled_domains::GetDomainAndRegistry(
rp_id, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
if (domain_rp_id.empty()) {
domain_rp_id = rp_id;
}This code is almost the same as `GetRpId`. I *think* this can be deduplicated this way (to be verified):
```
std::string GetDomainAndRegistryOrHost(std::string_view host) {
std::string domain = net::registry_controlled_domains::GetDomainAndRegistry(
host, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
return domain.empty() ? std::string(host) : domain;
}
```1st call site:
```
std::string domain_rp_id = GetDomainAndRegistryOrHost(params.RpId());
```2nd call site:
```
`GetDomainAndRegistryOrHost(form->url.host()) == domain_rp_id`
```
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
std::string rp_id = params.RpId();
std::string domain_rp_id = GetDomainAndRegistryOrHost(rp_id);Unnecessary string copy can be avoided:
```suggestion
std::string domain_rp_id = GetDomainAndRegistryOrHost(params.RpId());
```
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
std::string rp_id = params.RpId();
std::string domain_rp_id = GetDomainAndRegistryOrHost(rp_id);Unnecessary string copy can be avoided:
```suggestion
std::string domain_rp_id = GetDomainAndRegistryOrHost(params.RpId());
```
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
void OnGetPasswordStoreResults(This appears to be a deprecated method (see comment https://source.chromium.org/chromium/chromium/src/+/main:components/password_manager/core/browser/password_store/password_store_consumer.h;l=60;drc=d1c430bf8d4e459a748e6ec0ba277eddd4fceb53)
Can you instead use the `OnGetPasswordStoreResultsOrErrorFrom` method?
As a bonus, that method receives a `std::vector<PasswordForm>` instead of a `std::vector<std::unique_ptr<PasswordForm>>`, which makes way more sense in this context.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
bool CanPerformAutomaticPasskeyUpgradeForTesting(I just realized you don't need this function. PasskeyTabHelperTest is already a friend class to this class, so it can call CanPerformAutomaticPasskeyUpgrade directly.
This appears to be a deprecated method (see comment https://source.chromium.org/chromium/chromium/src/+/main:components/password_manager/core/browser/password_store/password_store_consumer.h;l=60;drc=d1c430bf8d4e459a748e6ec0ba277eddd4fceb53)
Can you instead use the `OnGetPasswordStoreResultsOrErrorFrom` method?
As a bonus, that method receives a `std::vector<PasswordForm>` instead of a `std::vector<std::unique_ptr<PasswordForm>>`, which makes way more sense in this context.
Done
I just realized you don't need this function. PasskeyTabHelperTest is already a friend class to this class, so it can call CanPerformAutomaticPasskeyUpgrade directly.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +0 |
if (std::holds_alternative<password_manager::PasswordStoreBackendError>(
results_or_error)) {
std::vector<std::string> request_ids_to_process;
for (const auto& [id, params] : registration_requests_) {
if (params.Type() ==
PasskeyRequestParams::RequestType::kConditionalCreate) {
request_ids_to_process.push_back(id);
}
}
for (const std::string& id : request_ids_to_process) {
auto it = registration_requests_.find(id);
if (it != registration_requests_.end()) {
DeferToRenderer(it->second.RequestInfo(), it->second.Type());
registration_requests_.erase(it);
}
}
return;
}
const auto& results =
std::get<password_manager::LoginsResult>(results_or_error);
std::vector<std::string> request_ids_to_process;
for (const auto& [id, params] : registration_requests_) {
if (params.Type() ==
PasskeyRequestParams::RequestType::kConditionalCreate) {
request_ids_to_process.push_back(id);
}
}
for (const std::string& id : request_ids_to_process) {
auto it = registration_requests_.find(id);
if (it == registration_requests_.end()) {
continue;
}
const RegistrationRequestParams& params = it->second;
if (CanPerformAutomaticPasskeyUpgrade(params, results)) {
StartPasskeyCreation(id);
} else {
DeferToRenderer(params.RequestInfo(), params.Type());
registration_requests_.erase(it);
}
}There a lot of code duplication here. Here's a quick improvement:
```suggestion
std::vector<std::string> request_ids_to_process;
for (const auto& [id, params] : registration_requests_) {
if (params.Type() == PasskeyRequestParams::RequestType::kConditionalCreate) {
request_ids_to_process.push_back(id);
}
}
const std::vector<password_manager::PasswordForm>* results = nullptr;
if (std::holds_alternative<password_manager::LoginsResult>(results_or_error)) {
results = &std::get<password_manager::LoginsResult>(results_or_error);
}
for (const std::string& id : request_ids_to_process) {
auto it = registration_requests_.find(id);
if (it == registration_requests_.end()) {
continue;
}const RegistrationRequestParams& params = it->second;
// Start creation only if we successfully retrieved results AND the upgrade is allowed.
if (results && CanPerformAutomaticPasskeyUpgrade(params, *results)) {
StartPasskeyCreation(id);
} else {
DeferToRenderer(params.RequestInfo(), params.Type());
registration_requests_.erase(it);
}
}
```
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
There a lot of code duplication here. Here's a quick improvement:
```suggestionstd::vector<std::string> request_ids_to_process;
for (const auto& [id, params] : registration_requests_) {
if (params.Type() == PasskeyRequestParams::RequestType::kConditionalCreate) {
request_ids_to_process.push_back(id);
}
}const std::vector<password_manager::PasswordForm>* results = nullptr;
if (std::holds_alternative<password_manager::LoginsResult>(results_or_error)) {
results = &std::get<password_manager::LoginsResult>(results_or_error);
}for (const std::string& id : request_ids_to_process) {
auto it = registration_requests_.find(id);
if (it == registration_requests_.end()) {
continue;
}const RegistrationRequestParams& params = it->second;// Start creation only if we successfully retrieved results AND the upgrade is allowed.
if (results && CanPerformAutomaticPasskeyUpgrade(params, *results)) {
StartPasskeyCreation(id);
} else {
DeferToRenderer(params.RequestInfo(), params.Type());
registration_requests_.erase(it);
}
}
```
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |