summaryrefslogtreecommitdiffstats
path: root/chromeos/network
diff options
context:
space:
mode:
authorpstew <pstew@chromium.org>2014-12-09 09:16:30 -0800
committerCommit bot <commit-bot@chromium.org>2014-12-09 17:16:50 +0000
commit024846bf53930e5c59e3811809cf9d6554af7f62 (patch)
tree4050feafb82a97219d705ce8930f7f50a0375b7d /chromeos/network
parenta6ac28e973f41924c90b215fef8140925edb5406 (diff)
downloadchromium_src-024846bf53930e5c59e3811809cf9d6554af7f62.zip
chromium_src-024846bf53930e5c59e3811809cf9d6554af7f62.tar.gz
chromium_src-024846bf53930e5c59e3811809cf9d6554af7f62.tar.bz2
Call network re-evaluation in the constructor's message loop
Capture the message loop the NetworkChangeNotifierChromeos was constructed with, and use this message loop instead of calling the poll closure inline. This has a side effect of requiring a weak pointer since the closure will now be called asynchronously. BUG=251141 R=stevenjb@chromium.org Review URL: https://codereview.chromium.org/752463003 Cr-Commit-Position: refs/heads/master@{#307490}
Diffstat (limited to 'chromeos/network')
-rw-r--r--chromeos/network/network_change_notifier_chromeos.cc8
-rw-r--r--chromeos/network/network_change_notifier_chromeos.h9
2 files changed, 13 insertions, 4 deletions
diff --git a/chromeos/network/network_change_notifier_chromeos.cc b/chromeos/network/network_change_notifier_chromeos.cc
index 39a37d5..a6014b03 100644
--- a/chromeos/network/network_change_notifier_chromeos.cc
+++ b/chromeos/network/network_change_notifier_chromeos.cc
@@ -53,8 +53,10 @@ void NetworkChangeNotifierChromeos::DnsConfigService::OnNetworkChange() {
NetworkChangeNotifierChromeos::NetworkChangeNotifierChromeos()
: NetworkChangeNotifier(NetworkChangeCalculatorParamsChromeos()),
connection_type_(CONNECTION_NONE),
- poll_callback_(base::Bind(&NetworkChangeNotifierChromeos::PollForState,
- base::Unretained(this))) {
+ message_loop_(base::MessageLoopProxy::current()),
+ weak_ptr_factory_(this) {
+ poll_callback_ = base::Bind(&NetworkChangeNotifierChromeos::PollForState,
+ weak_ptr_factory_.GetWeakPtr());
}
NetworkChangeNotifierChromeos::~NetworkChangeNotifierChromeos() {
@@ -92,7 +94,7 @@ NetworkChangeNotifierChromeos::GetCurrentConnectionType() const {
// |this|, to allow PollForState() to modify our cached state.
// TODO(gauravsh): Figure out why we would have missed this notification.
if (connection_type_ == CONNECTION_NONE)
- poll_callback_.Run();
+ message_loop_->PostTask(FROM_HERE, poll_callback_);
return connection_type_;
}
diff --git a/chromeos/network/network_change_notifier_chromeos.h b/chromeos/network/network_change_notifier_chromeos.h
index a2ad695..82149d0 100644
--- a/chromeos/network/network_change_notifier_chromeos.h
+++ b/chromeos/network/network_change_notifier_chromeos.h
@@ -11,6 +11,8 @@
#include "base/callback.h"
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "base/message_loop/message_loop_proxy.h"
#include "chromeos/chromeos_export.h"
#include "chromeos/dbus/power_manager_client.h"
#include "chromeos/network/network_state_handler_observer.h"
@@ -82,10 +84,15 @@ class CHROMEOS_EXPORT NetworkChangeNotifierChromeos
std::vector<std::string> dns_servers_;
// Service path for the current default network.
std::string service_path_;
+
+ scoped_ptr<DnsConfigService> dns_config_service_;
+
// Callback for refreshing network state.
base::Closure poll_callback_;
- scoped_ptr<DnsConfigService> dns_config_service_;
+ // For setting up network refresh polling callbacks.
+ scoped_refptr<base::MessageLoopProxy> message_loop_;
+ base::WeakPtrFactory<NetworkChangeNotifierChromeos> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierChromeos);
};