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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/net/network_change_notifier_chromeos.h"
6
7 #include "base/task.h"
8 #include "chrome/browser/chromeos/cros/cros_library.h"
9 #include "content/browser/browser_thread.h"
10
11 namespace chromeos {
12
13 NetworkChangeNotifierChromeos::NetworkChangeNotifierChromeos()
14 : has_active_network_(false),
15 connectivity_state_(chromeos::CONN_STATE_UNKNOWN),
16 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
17
18 chromeos::NetworkLibrary* lib =
19 chromeos::CrosLibrary::Get()->GetNetworkLibrary();
20 lib->AddNetworkManagerObserver(this);
21 }
22
23 NetworkChangeNotifierChromeos::~NetworkChangeNotifierChromeos() {
24 chromeos::NetworkLibrary* lib =
25 chromeos::CrosLibrary::Get()->GetNetworkLibrary();
26 lib->RemoveNetworkManagerObserver(this);
27 lib->RemoveObserverForAllNetworks(this);
28 }
29
30 void NetworkChangeNotifierChromeos::OnNetworkManagerChanged(
31 chromeos::NetworkLibrary* cros) {
32 UpdateNetworkState(cros);
33 }
34
35 bool NetworkChangeNotifierChromeos::IsCurrentlyOffline() const {
36 return connectivity_state_ != chromeos::CONN_STATE_UNRESTRICTED;
37 }
38
39 void NetworkChangeNotifierChromeos::UpdateNetworkState(
40 chromeos::NetworkLibrary* lib) {
41 const chromeos::Network* network = lib->active_network();
42
43 // Check if active network was added, removed or changed.
44 if ((network && !has_active_network_) || (!network && has_active_network_) ||
45 (network && (network->service_path() != service_path_ ||
46 network->ip_address() != ip_address_))) {
oshima 2011/05/18 01:42:44 All right, i think this is easier to follow, then
zel 2011/05/18 01:48:27 Done.
47 if (has_active_network_)
48 lib->RemoveObserverForAllNetworks(this);
49 if (!network) {
50 has_active_network_ = false;
51 service_path_.clear();
52 ip_address_.clear();
53 } else {
54 has_active_network_ = true;
55 service_path_ = network->service_path();
56 lib->AddNetworkObserver(network->service_path(), this);
57 ip_address_ = network->ip_address();
58 }
59 BrowserThread::PostTask(
60 BrowserThread::IO, FROM_HERE,
61 NewRunnableFunction(
62 &NetworkChangeNotifierChromeos::NotifyObserversOfIPAddressChange));
63 }
64 }
65
66 void NetworkChangeNotifierChromeos::OnNetworkChanged(
67 chromeos::NetworkLibrary* cros,
68 const chromeos::Network* network) {
69 if (!network) {
70 NOTREACHED();
71 return;
72 }
73 // Active network changed?
74 if (network->service_path() != service_path_) {
75 UpdateNetworkState(cros);
76 return;
77 }
78 if (network->connectivity_state() != connectivity_state_) {
79 connectivity_state_ = network->connectivity_state();
80 BrowserThread::PostTask(
81 BrowserThread::IO, FROM_HERE,
82 NewRunnableMethod(this,
83 &NetworkChangeNotifierChromeos::NotifyObserversOfOnlineStateChange));
84 }
85 }
86
87 } // namespace net
OLDNEW
« 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