Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
|
Sam Leffler
2011/05/17 02:34:28
it's 2011
| |
| 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 <errno.h> | |
| 8 #include <sys/socket.h> | |
| 9 | |
| 10 #include "base/compiler_specific.h" | |
|
oshima
2011/05/17 17:33:05
move this to header (for OVERRIDE)
zel
2011/05/18 00:43:33
Done.
| |
| 11 #include "base/eintr_wrapper.h" | |
| 12 #include "base/task.h" | |
|
oshima
2011/05/17 17:33:05
is this used?
zel
2011/05/18 00:43:33
Done.
| |
| 13 #include "base/threading/thread.h" | |
| 14 #include "chrome/browser/chromeos/cros/cros_library.h" | |
| 15 #include "net/base/net_errors.h" | |
| 16 | |
| 17 namespace net { | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 const int kInvalidSocket = -1; | |
|
Sam Leffler
2011/05/17 02:34:28
don't see this used
zel
2011/05/18 00:43:33
Done.
| |
| 22 | |
| 23 } // namespace | |
| 24 | |
| 25 NetworkChangeNotifierCros::NetworkChangeNotifierCros() | |
| 26 : connected_(false), | |
| 27 has_active_network_(false), | |
| 28 connectivity_state_(chromeos::CONN_STATE_UNKNOWN) { | |
| 29 | |
| 30 chromeos::NetworkLibrary* lib = | |
| 31 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | |
| 32 lib->AddNetworkManagerObserver(this); | |
| 33 UpdateNetworkState(lib); | |
| 34 } | |
| 35 | |
| 36 NetworkChangeNotifierCros::~NetworkChangeNotifierCros() { | |
| 37 chromeos::NetworkLibrary* lib = | |
| 38 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | |
| 39 lib->RemoveNetworkManagerObserver(this); | |
| 40 } | |
| 41 | |
| 42 void NetworkChangeNotifierCros::OnNetworkManagerChanged( | |
| 43 chromeos::NetworkLibrary* cros) { | |
| 44 UpdateNetworkState(cros); | |
| 45 } | |
| 46 | |
| 47 bool NetworkChangeNotifierCros::IsCurrentlyOffline() const { | |
| 48 return connectivity_state_ != chromeos::CONN_STATE_UNRESTRICTED; | |
| 49 } | |
| 50 | |
| 51 void NetworkChangeNotifierCros::UpdateNetworkState( | |
| 52 chromeos::NetworkLibrary* lib) { | |
| 53 const chromeos::Network* network = lib->active_network(); | |
| 54 // Check if the active network, its IP address or its connectivity status had | |
| 55 // changed. | |
| 56 if ((network && !has_active_network_) || (!network && has_active_network_) || | |
| 57 (network && (network->service_path() != service_path_ || | |
| 58 network->connectivity_state() != connectivity_state_)) || | |
| 59 lib->IPAddress() != ip_address_) { | |
|
oshima
2011/05/17 17:33:05
since the condition is a bit complicated, we need
oshima
2011/05/18 01:28:45
The code looks correct, but I'm still concerned ab
| |
| 60 if (network) { | |
| 61 has_active_network_ = true; | |
| 62 service_path_ = network->service_path(); | |
| 63 } else { | |
| 64 has_active_network_ = false; | |
| 65 service_path_.clear(); | |
| 66 } | |
| 67 ip_address_ = lib->IPAddress(); | |
|
Sam Leffler
2011/05/17 02:34:28
I'm not familiar with this stuff but how do these
zel
2011/05/18 00:43:33
Yes, on ChromeOS side this notification should be
| |
| 68 NotifyObserversOfIPAddressChange(); | |
| 69 } | |
| 70 if ((network && network->connectivity_state() != connectivity_state_) && | |
|
Sam Leffler
2011/05/17 02:34:28
Again, not familiar with semantics here, but flimf
oshima
2011/05/17 17:33:05
If network can be null, don't we have to notify of
zel
2011/05/18 00:43:33
This part is rewritten now. Please take a look at
| |
| 71 lib->Connected() != connected_) { | |
| 72 connectivity_state_ = network->connectivity_state(); | |
| 73 connected_ = lib->Connected(); | |
| 74 NotifyObserversOfOnlineStateChange(); | |
|
oshima
2011/05/17 17:33:05
I believe NetworkChangeNotifier clients expect to
zel
2011/05/18 00:43:33
Done.
| |
| 75 } | |
| 76 } | |
| 77 | |
| 78 } // namespace net | |
| OLD | NEW |