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

Unified Diff: chrome/browser/chromeos/net/network_change_notifier_chromeos.cc

Issue 7029019: Added ChromeOS-specific NetworkChangeNotifier specialization that is wired directly to flimflam. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 months 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 | « chrome/browser/chromeos/net/network_change_notifier_chromeos.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/net/network_change_notifier_chromeos.cc
===================================================================
--- chrome/browser/chromeos/net/network_change_notifier_chromeos.cc (revision 0)
+++ chrome/browser/chromeos/net/network_change_notifier_chromeos.cc (revision 0)
@@ -0,0 +1,88 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/net/network_change_notifier_chromeos.h"
+
+#include "base/task.h"
+#include "chrome/browser/chromeos/cros/cros_library.h"
+#include "content/browser/browser_thread.h"
+
+namespace chromeos {
+
+NetworkChangeNotifierChromeos::NetworkChangeNotifierChromeos()
+ : has_active_network_(false),
+ connectivity_state_(chromeos::CONN_STATE_UNKNOWN),
+ ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
+
+ chromeos::NetworkLibrary* lib =
+ chromeos::CrosLibrary::Get()->GetNetworkLibrary();
+ lib->AddNetworkManagerObserver(this);
+}
+
+NetworkChangeNotifierChromeos::~NetworkChangeNotifierChromeos() {
+ chromeos::NetworkLibrary* lib =
+ chromeos::CrosLibrary::Get()->GetNetworkLibrary();
+ lib->RemoveNetworkManagerObserver(this);
+ lib->RemoveObserverForAllNetworks(this);
+}
+
+void NetworkChangeNotifierChromeos::OnNetworkManagerChanged(
+ chromeos::NetworkLibrary* cros) {
+ UpdateNetworkState(cros);
+}
+
+bool NetworkChangeNotifierChromeos::IsCurrentlyOffline() const {
+ return connectivity_state_ != chromeos::CONN_STATE_UNRESTRICTED;
+}
+
+void NetworkChangeNotifierChromeos::UpdateNetworkState(
+ chromeos::NetworkLibrary* lib) {
+ const chromeos::Network* network = lib->active_network();
+
+ // Check if active network was added, removed or changed.
+ if ((!network && has_active_network_) ||
+ (network && (!has_active_network_ ||
+ network->service_path() != service_path_ ||
+ network->ip_address() != ip_address_))) {
+ if (has_active_network_)
+ lib->RemoveObserverForAllNetworks(this);
+ if (!network) {
+ has_active_network_ = false;
+ service_path_.clear();
+ ip_address_.clear();
+ } else {
+ has_active_network_ = true;
+ service_path_ = network->service_path();
+ lib->AddNetworkObserver(network->service_path(), this);
+ ip_address_ = network->ip_address();
+ }
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ NewRunnableFunction(
+ &NetworkChangeNotifierChromeos::NotifyObserversOfIPAddressChange));
+ }
+}
+
+void NetworkChangeNotifierChromeos::OnNetworkChanged(
+ chromeos::NetworkLibrary* cros,
+ const chromeos::Network* network) {
+ if (!network) {
+ NOTREACHED();
+ return;
+ }
+ // Active network changed?
+ if (network->service_path() != service_path_) {
+ UpdateNetworkState(cros);
+ return;
+ }
+ if (network->connectivity_state() != connectivity_state_) {
+ connectivity_state_ = network->connectivity_state();
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ method_factory_.NewRunnableMethod(
+ &NetworkChangeNotifierChromeos::NotifyObserversOfOnlineStateChange));
+ }
+}
+
+} // namespace net
Property changes on: chrome/browser/chromeos/net/network_change_notifier_chromeos.cc
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « chrome/browser/chromeos/net/network_change_notifier_chromeos.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698