Commit cdb29e05 authored by Jimmy Gong's avatar Jimmy Gong Committed by Commit Bot

Add TryResolveUrl to SmbShareFinder

- Introduces a method that attempts to resolve an SmbUrl and
  returns whether it was able to.
- This new method will be used to determine if a hostname was
  resolved during dynamic hostname resolution.

Bug: 922273
Test: compiles
Change-Id: I9c15a2ccfd07cd8f4f8c888c3358c42b74253984
Reviewed-on: https://chromium-review.googlesource.com/c/1444598
Commit-Queue: jimmy gong <jimmyxgong@chromium.org>
Reviewed-by: default avatarBailey Berro <baileyberro@chromium.org>
Auto-Submit: jimmy gong <jimmyxgong@chromium.org>
Cr-Commit-Position: refs/heads/master@{#630602}
parent e0e1aaed
...@@ -261,10 +261,10 @@ void SmbService::CallMount(const file_system_provider::MountOptions& options, ...@@ -261,10 +261,10 @@ void SmbService::CallMount(const file_system_provider::MountOptions& options,
// If using kerberos, the hostname should not be resolved since kerberos // If using kerberos, the hostname should not be resolved since kerberos
// service tickets are keyed on hosname. // service tickets are keyed on hosname.
const base::FilePath mount_path = const std::string url = use_chromad_kerberos
use_chromad_kerberos ? parsed_url.ToString()
? base::FilePath(parsed_url.ToString()) : share_finder_->GetResolvedUrl(parsed_url);
: base::FilePath(share_finder_->GetResolvedUrl(parsed_url)); const base::FilePath mount_path(url);
GetSmbProviderClient()->Mount( GetSmbProviderClient()->Mount(
mount_path, IsNTLMAuthenticationEnabled(), workgroup, username, mount_path, IsNTLMAuthenticationEnabled(), workgroup, username,
......
...@@ -52,13 +52,21 @@ std::string SmbShareFinder::GetResolvedUrl(const SmbUrl& url) const { ...@@ -52,13 +52,21 @@ std::string SmbShareFinder::GetResolvedUrl(const SmbUrl& url) const {
DCHECK(url.IsValid()); DCHECK(url.IsValid());
const std::string ip_address = scanner_.ResolveHost(url.GetHost()); const std::string ip_address = scanner_.ResolveHost(url.GetHost());
if (ip_address.empty()) { // Return the original URL if the resolved host cannot be found or if there is
// no change in the resolved IP address.
if (ip_address.empty() || ip_address == url.GetHost()) {
return url.ToString(); return url.ToString();
} }
return url.ReplaceHost(ip_address); return url.ReplaceHost(ip_address);
} }
bool SmbShareFinder::TryResolveUrl(const SmbUrl& url,
std::string* updated_url) const {
*updated_url = GetResolvedUrl(url);
return *updated_url != url.ToString();
}
void SmbShareFinder::OnHostsDiscovered(HostDiscoveryResponse discovery_callback, void SmbShareFinder::OnHostsDiscovered(HostDiscoveryResponse discovery_callback,
bool success, bool success,
const HostMap& hosts) { const HostMap& hosts) {
......
...@@ -58,6 +58,11 @@ class SmbShareFinder : public base::SupportsWeakPtr<SmbShareFinder> { ...@@ -58,6 +58,11 @@ class SmbShareFinder : public base::SupportsWeakPtr<SmbShareFinder> {
// otherwise returns ToString of |url|. // otherwise returns ToString of |url|.
std::string GetResolvedUrl(const SmbUrl& url) const; std::string GetResolvedUrl(const SmbUrl& url) const;
// Attempts to resolve |url|. If able to resolve |url|, returns true and sets
// |resolved_url| the the resolved url. If unable, returns false and sets
// |resolved_url| to ToString of |url|.
bool TryResolveUrl(const SmbUrl& url, std::string* updated_url) const;
private: private:
// Handles the response from discovering hosts in the network. // Handles the response from discovering hosts in the network.
void OnHostsDiscovered(HostDiscoveryResponse discovery_callback, void OnHostsDiscovered(HostDiscoveryResponse discovery_callback,
......
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