Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(626)

Unified Diff: net/base/network_change_notifier_linux.cc

Issue 8591021: Fix initial offline state response handling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Deal with review comments Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/base/network_change_notifier_linux_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/network_change_notifier_linux.cc
diff --git a/net/base/network_change_notifier_linux.cc b/net/base/network_change_notifier_linux.cc
index 95f54e24e5070e32ec0e06ef24fc2292c18e1c32..99167dc93610247b38ac3c6f33f3b0d3e523c896 100644
--- a/net/base/network_change_notifier_linux.cc
+++ b/net/base/network_change_notifier_linux.cc
@@ -88,16 +88,12 @@ class NetworkManagerApi {
private:
// Callbacks for D-Bus API.
- void OnStateChanged(dbus::Message* message);
-
- void OnResponse(dbus::Response* response) {
- OnStateChanged(response);
+ void OnInitialResponse(dbus::Response* response) {
+ HandleResponse(response);
offline_state_initialized_.Signal();
}
- void OnSignaled(dbus::Signal* signal) {
- OnStateChanged(signal);
- }
+ void OnSignaled(dbus::Signal* signal);
void OnConnected(const std::string&, const std::string&, bool success) {
if (!success) {
@@ -106,6 +102,9 @@ class NetworkManagerApi {
}
}
+ // Helper for OnInitialResponse.
+ void HandleResponse(dbus::Response* response);
+
// Converts a NetworkManager state uint to a bool.
static bool StateIsOffline(uint32 state);
@@ -147,7 +146,8 @@ void NetworkManagerApi::Init() {
builder.AppendString("State");
proxy->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
- base::Bind(&NetworkManagerApi::OnResponse, ptr_factory_.GetWeakPtr()));
+ base::Bind(&NetworkManagerApi::OnInitialResponse,
+ ptr_factory_.GetWeakPtr()));
// And sign up for notifications.
proxy->ConnectToSignal(
@@ -162,17 +162,32 @@ void NetworkManagerApi::CleanUp() {
ptr_factory_.InvalidateWeakPtrs();
}
-void NetworkManagerApi::OnStateChanged(dbus::Message* message) {
+void NetworkManagerApi::HandleResponse(dbus::Response* response) {
DCHECK_EQ(helper_thread_id_, base::PlatformThread::CurrentId());
- if (!message) {
+ if (!response) {
DLOG(WARNING) << "No response received for initial state request";
return;
}
- dbus::MessageReader reader(message);
+ dbus::MessageReader reader(response);
uint32 state = 0;
- if (!reader.HasMoreData() || !reader.PopUint32(&state)) {
+ if (!reader.PopVariantOfUint32(&state)) {
DLOG(WARNING) << "Unexpected response for NetworkManager State request: "
- << message->ToString();
+ << response->ToString();
+ return;
+ }
+ {
+ base::AutoLock lock(is_offline_lock_);
+ is_offline_ = StateIsOffline(state);
+ }
+}
+
+void NetworkManagerApi::OnSignaled(dbus::Signal* signal) {
+ DCHECK_EQ(helper_thread_id_, base::PlatformThread::CurrentId());
+ dbus::MessageReader reader(signal);
+ uint32 state = 0;
+ if (!reader.PopUint32(&state)) {
+ DLOG(WARNING) << "Unexpected signal for NetworkManager StateChanged: "
+ << signal->ToString();
return;
}
bool new_is_offline = StateIsOffline(state);
@@ -183,8 +198,7 @@ void NetworkManagerApi::OnStateChanged(dbus::Message* message) {
else
return;
}
- if (offline_state_initialized_.IsSignaled())
- notification_callback_.Run();
+ notification_callback_.Run();
}
bool NetworkManagerApi::StateIsOffline(uint32 state) {
« no previous file with comments | « no previous file | net/base/network_change_notifier_linux_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698