Commit 82b5e9aa authored by Anna Malova's avatar Anna Malova Committed by Commit Bot

Convert DnsConfigServicePosix to use RepeatingCallback.

Bug: 1007815
Change-Id: I14f5647a693f63d63ffa457190e02dac0727ef00
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2089756
Commit-Queue: Matt Menke <mmenke@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#747313}
parent 12f35d22
...@@ -60,7 +60,7 @@ const base::FilePath::CharType kFilePathHosts[] = ...@@ -60,7 +60,7 @@ const base::FilePath::CharType kFilePathHosts[] =
// There is no public API to watch the DNS configuration on iOS. // There is no public API to watch the DNS configuration on iOS.
class DnsConfigWatcher { class DnsConfigWatcher {
public: public:
using CallbackType = base::Callback<void(bool succeeded)>; using CallbackType = base::RepeatingCallback<void(bool succeeded)>;
bool Watch(const CallbackType& callback) { bool Watch(const CallbackType& callback) {
return false; return false;
...@@ -78,7 +78,7 @@ class DnsConfigWatcher : public NetworkChangeNotifier::NetworkChangeObserver { ...@@ -78,7 +78,7 @@ class DnsConfigWatcher : public NetworkChangeNotifier::NetworkChangeObserver {
NetworkChangeNotifier::RemoveNetworkChangeObserver(this); NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
} }
using CallbackType = base::Callback<void(bool succeeded)>; using CallbackType = base::RepeatingCallback<void(bool succeeded)>;
bool Watch(const CallbackType& callback) { bool Watch(const CallbackType& callback) {
callback_ = callback; callback_ = callback;
...@@ -110,13 +110,13 @@ const base::FilePath::CharType kFilePathConfig[] = ...@@ -110,13 +110,13 @@ const base::FilePath::CharType kFilePathConfig[] =
class DnsConfigWatcher { class DnsConfigWatcher {
public: public:
using CallbackType = base::Callback<void(bool succeeded)>; using CallbackType = base::RepeatingCallback<void(bool succeeded)>;
bool Watch(const CallbackType& callback) { bool Watch(const CallbackType& callback) {
callback_ = callback; callback_ = callback;
return watcher_.Watch(base::FilePath(kFilePathConfig), false, return watcher_.Watch(base::FilePath(kFilePathConfig), false,
base::Bind(&DnsConfigWatcher::OnCallback, base::BindRepeating(&DnsConfigWatcher::OnCallback,
base::Unretained(this))); base::Unretained(this)));
} }
private: private:
...@@ -246,8 +246,8 @@ class DnsConfigServicePosix::Watcher { ...@@ -246,8 +246,8 @@ class DnsConfigServicePosix::Watcher {
bool Watch() { bool Watch() {
bool success = true; bool success = true;
if (!config_watcher_.Watch(base::Bind(&Watcher::OnConfigChanged, if (!config_watcher_.Watch(base::BindRepeating(&Watcher::OnConfigChanged,
base::Unretained(this)))) { base::Unretained(this)))) {
LOG(ERROR) << "DNS config watch failed to start."; LOG(ERROR) << "DNS config watch failed to start.";
success = false; success = false;
UMA_HISTOGRAM_ENUMERATION("AsyncDNS.WatchStatus", UMA_HISTOGRAM_ENUMERATION("AsyncDNS.WatchStatus",
...@@ -257,9 +257,9 @@ class DnsConfigServicePosix::Watcher { ...@@ -257,9 +257,9 @@ class DnsConfigServicePosix::Watcher {
// Hosts file should never change on Android or iOS (and watching it on Android // Hosts file should never change on Android or iOS (and watching it on Android
// is problematic; see http://crbug.com/600442), so don't watch it there. // is problematic; see http://crbug.com/600442), so don't watch it there.
#if !defined(OS_ANDROID) && !defined(OS_IOS) #if !defined(OS_ANDROID) && !defined(OS_IOS)
if (!hosts_watcher_.Watch( if (!hosts_watcher_.Watch(base::FilePath(service_->file_path_hosts_), false,
base::FilePath(service_->file_path_hosts_), false, base::BindRepeating(&Watcher::OnHostsChanged,
base::Bind(&Watcher::OnHostsChanged, base::Unretained(this)))) { base::Unretained(this)))) {
LOG(ERROR) << "DNS hosts watch failed to start."; LOG(ERROR) << "DNS hosts watch failed to start.";
success = false; success = false;
UMA_HISTOGRAM_ENUMERATION("AsyncDNS.WatchStatus", UMA_HISTOGRAM_ENUMERATION("AsyncDNS.WatchStatus",
......
...@@ -252,8 +252,8 @@ class DnsConfigServicePosixTest : public testing::Test { ...@@ -252,8 +252,8 @@ class DnsConfigServicePosixTest : public testing::Test {
// Regression test for https://crbug.com/704662. // Regression test for https://crbug.com/704662.
TEST_F(DnsConfigServicePosixTest, ChangeConfigMultipleTimes) { TEST_F(DnsConfigServicePosixTest, ChangeConfigMultipleTimes) {
service_->WatchConfig(base::Bind(&DnsConfigServicePosixTest::OnConfigChanged, service_->WatchConfig(base::BindRepeating(
base::Unretained(this))); &DnsConfigServicePosixTest::OnConfigChanged, base::Unretained(this)));
task_environment_.RunUntilIdle(); task_environment_.RunUntilIdle();
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
......
...@@ -70,7 +70,7 @@ namespace net { ...@@ -70,7 +70,7 @@ namespace net {
namespace internal { namespace internal {
bool DnsConfigWatcher::Watch( bool DnsConfigWatcher::Watch(
const base::Callback<void(bool succeeded)>& callback) { const base::RepeatingCallback<void(bool succeeded)>& callback) {
if (!GetDnsInfoApi().dns_configuration_notify_key) if (!GetDnsInfoApi().dns_configuration_notify_key)
return false; return false;
return watcher_.Watch(GetDnsInfoApi().dns_configuration_notify_key(), return watcher_.Watch(GetDnsInfoApi().dns_configuration_notify_key(),
......
...@@ -15,7 +15,7 @@ namespace internal { ...@@ -15,7 +15,7 @@ namespace internal {
// Watches DNS configuration on Mac. // Watches DNS configuration on Mac.
class DnsConfigWatcher { class DnsConfigWatcher {
public: public:
bool Watch(const base::Callback<void(bool succeeded)>& callback); bool Watch(const base::RepeatingCallback<void(bool succeeded)>& callback);
// Returns an error if the DNS configuration is invalid. // Returns an error if the DNS configuration is invalid.
// Returns CONFIG_PARSE_POSIX_OK otherwise. // Returns CONFIG_PARSE_POSIX_OK otherwise.
......
...@@ -18,7 +18,7 @@ namespace net { ...@@ -18,7 +18,7 @@ namespace net {
class NotifyWatcherMac { class NotifyWatcherMac {
public: public:
// Called on received notification with true on success and false on error. // Called on received notification with true on success and false on error.
typedef base::Callback<void(bool succeeded)> CallbackType; typedef base::RepeatingCallback<void(bool succeeded)> CallbackType;
NotifyWatcherMac(); NotifyWatcherMac();
......
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