Commit 2c3849ca authored by Jimmy Gong's avatar Jimmy Gong Committed by Commit Bot

Implement OnNetworkChangeObserver interface on SmbService

- Implements Net::NetworkChangeNotifier::NetworkChangeObserver to
  SmbService.
- Optimizes the workflow of host name resolution by calling on host
  discovery whenever a network change is discovered, rather than
  only running host discovery on an error returned by
  StartReadDirectory.

Bug: 922273
Test: manual end to end
Change-Id: I9e91a1527fe06570b3d82c7abc92c448c07ed74a
Reviewed-on: https://chromium-review.googlesource.com/c/1484501
Commit-Queue: jimmy gong <jimmyxgong@chromium.org>
Reviewed-by: default avatarBailey Berro <baileyberro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635203}
parent 18a62fe6
......@@ -121,7 +121,9 @@ SmbService::SmbService(Profile* profile,
}
}
SmbService::~SmbService() {}
SmbService::~SmbService() {
net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
}
// static
SmbService* SmbService::Get(content::BrowserContext* context) {
......@@ -525,6 +527,7 @@ void SmbService::CompleteSetup(
base::BindRepeating(&SmbService::RequestUpdatedSharePath,
base::Unretained(this))));
RestoreMounts();
net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
}
void SmbService::FireMountCallback(MountResponse callback,
......@@ -662,6 +665,22 @@ bool SmbService::ShouldRunHostDiscoveryAgain() const {
previous_host_discovery_time_ + kHostDiscoveryInterval;
}
void SmbService::OnNetworkChanged(
net::NetworkChangeNotifier::ConnectionType type) {
user_manager::User* user =
chromeos::ProfileHelper::Get()->GetUserByProfile(profile_);
if (!user) {
// If a network change occurs on the lockscreen, do nothing.
return;
}
// Run host discovery to refresh list of cached hosts for subsequent name
// resolution attempts.
share_finder_->DiscoverHostsInNetwork(base::DoNothing()
/* HostDiscoveryResponse */);
}
void SmbService::RecordMountCount() const {
const std::vector<ProvidedFileSystemInfo> file_systems =
GetProviderService()->GetProvidedFileSystemInfoList(provider_id_);
......
......@@ -25,6 +25,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chromeos/dbus/smb_provider_client.h"
#include "components/keyed_service/core/keyed_service.h"
#include "net/base/network_change_notifier.h"
namespace base {
class FilePath;
......@@ -46,6 +47,7 @@ using file_system_provider::Service;
// Creates and manages an smb file system.
class SmbService : public KeyedService,
public net::NetworkChangeNotifier::NetworkChangeObserver,
public base::SupportsWeakPtr<SmbService> {
public:
using MountResponse = base::OnceCallback<void(SmbMountResult result)>;
......@@ -245,6 +247,11 @@ class SmbService : public KeyedService,
// false if HostDiscovery was recently run.
bool ShouldRunHostDiscoveryAgain() const;
// NetworkChangeNotifier::NetworkChangeObserver override. Runs HostDiscovery
// when network detects a change.
void OnNetworkChanged(
net::NetworkChangeNotifier::ConnectionType type) override;
// Records metrics on the number of SMB mounts a user has.
void RecordMountCount() const;
......
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