Commit 4121d448 authored by Bailey Berro's avatar Bailey Berro Committed by Commit Bot

Remove race condition in Smb Share discovery

Stores a mount call if host discovery is not yet complete and runs it as
soon as the first share names start coming back, indicating that host
discovery is complete.

The mount can be attempted before share discovery is complete because
mounting via a hostname is only dependent on host discovery for name
resolution.

Bug: 757625, 863178
Change-Id: If53ec9061c79a4f408278be4ddd990a7c9ca3791
Reviewed-on: https://chromium-review.googlesource.com/1136528Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Reviewed-by: default avatarScott Chen <scottchen@chromium.org>
Commit-Queue: Bailey Berro <baileyberro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575477}
parent 66e71f65
......@@ -59,9 +59,17 @@ void SmbHandler::HandleSmbMount(const base::ListValue* args) {
mo.display_name = mount_name.empty() ? mount_url : mount_name;
mo.writable = true;
service->Mount(mo, base::FilePath(mount_url), username, password,
base::BindOnce(&SmbHandler::HandleSmbMountResponse,
weak_ptr_factory_.GetWeakPtr()));
auto mount_response = base::BindOnce(&SmbHandler::HandleSmbMountResponse,
weak_ptr_factory_.GetWeakPtr());
auto mount_call = base::BindOnce(
&smb_client::SmbService::Mount, base::Unretained(service), mo,
base::FilePath(mount_url), username, password, std::move(mount_response));
if (host_discovery_done_) {
std::move(mount_call).Run();
} else {
stored_mount_call_ = std::move(mount_call);
}
}
void SmbHandler::HandleSmbMountResponse(SmbMountResult result) {
......@@ -78,6 +86,11 @@ void SmbHandler::HandleStartDiscovery(const base::ListValue* args) {
void SmbHandler::HandleGatherSharesResponse(
const std::vector<smb_client::SmbUrl>& shares_gathered) {
host_discovery_done_ = true;
if (!stored_mount_call_.is_null()) {
std::move(stored_mount_call_).Run();
}
// TODO(zentaro): Pass the shares discovered back to the UI.
// https://crbug.com/852199.
}
......
......@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_SMB_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_SMB_HANDLER_H_
#include "base/callback_forward.h"
#include "base/files/file.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
......@@ -41,6 +42,8 @@ class SmbHandler : public ::settings::SettingsPageUIHandler {
void HandleGatherSharesResponse(
const std::vector<smb_client::SmbUrl>& shares_gathered);
bool host_discovery_done_ = false;
base::OnceClosure stored_mount_call_;
Profile* const profile_;
base::WeakPtrFactory<SmbHandler> weak_ptr_factory_;
......
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