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

Side by Side Diff: net/base/network_change_notifier_linux.cc

Issue 9147026: API for connection type (Ethernet/WIFI/WWAN ...) in NetworkChangeNotifier. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed a typo Created 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // This implementation of NetworkChangeNotifier's offline state detection 5 // This implementation of NetworkChangeNotifier's offline state detection
6 // depends on D-Bus and NetworkManager, and is known to work on at least 6 // depends on D-Bus and NetworkManager, and is known to work on at least
7 // GNOME version 2.30. If D-Bus or NetworkManager are unavailable, this 7 // GNOME version 2.30. If D-Bus or NetworkManager are unavailable, this
8 // implementation will always behave as if it is online. 8 // implementation will always behave as if it is online.
9 9
10 #include "net/base/network_change_notifier_linux.h" 10 #include "net/base/network_change_notifier_linux.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 system_bus_(bus) { } 76 system_bus_(bus) { }
77 77
78 ~NetworkManagerApi() { } 78 ~NetworkManagerApi() { }
79 79
80 // Should be called on a helper thread which must be of type IO. 80 // Should be called on a helper thread which must be of type IO.
81 void Init(); 81 void Init();
82 82
83 // Must be called by the helper thread's CleanUp() method. 83 // Must be called by the helper thread's CleanUp() method.
84 void CleanUp(); 84 void CleanUp();
85 85
86 // Implementation of NetworkChangeNotifierLinux::IsCurrentlyOffline(). 86 // Implementation of NetworkChangeNotifierLinux::GetCurrentConnectionType().
87 // Safe to call from any thread, but will block until Init() has completed. 87 // Safe to call from any thread, but will block until Init() has completed.
88 bool IsCurrentlyOffline(); 88 NetworkChangeNotifier::ConnectionType GetCurrentConnectionType();
89 89
90 private: 90 private:
91 // Callbacks for D-Bus API. 91 // Callbacks for D-Bus API.
92 void OnInitialResponse(dbus::Response* response) { 92 void OnInitialResponse(dbus::Response* response) {
93 HandleResponse(response); 93 HandleResponse(response);
94 offline_state_initialized_.Signal(); 94 offline_state_initialized_.Signal();
95 } 95 }
96 96
97 void OnSignaled(dbus::Signal* signal); 97 void OnSignaled(dbus::Signal* signal);
98 98
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 case NM_LEGACY_STATE_ASLEEP: 225 case NM_LEGACY_STATE_ASLEEP:
226 case NM_STATE_ASLEEP: 226 case NM_STATE_ASLEEP:
227 // Networking disabled or no devices on system 227 // Networking disabled or no devices on system
228 return true; 228 return true;
229 default: 229 default:
230 // Unknown status 230 // Unknown status
231 return false; 231 return false;
232 } 232 }
233 } 233 }
234 234
235 bool NetworkManagerApi::IsCurrentlyOffline() { 235 NetworkChangeNotifier::ConnectionType
236 NetworkManagerApi::GetCurrentConnectionType() {
236 // http://crbug.com/125097 237 // http://crbug.com/125097
237 base::ThreadRestrictions::ScopedAllowWait allow_wait; 238 base::ThreadRestrictions::ScopedAllowWait allow_wait;
238 offline_state_initialized_.Wait(); 239 offline_state_initialized_.Wait();
239 base::AutoLock lock(is_offline_lock_); 240 base::AutoLock lock(is_offline_lock_);
240 return is_offline_; 241 // TODO(droger): Return something more detailed than CONNECTION_UNKNOWN.
242 return is_offline_ ? NetworkChangeNotifier::CONNECTION_NONE :
243 NetworkChangeNotifier::CONNECTION_UNKNOWN;
241 } 244 }
242 245
243 class NetworkChangeNotifierLinux::Thread 246 class NetworkChangeNotifierLinux::Thread
244 : public base::Thread, public MessageLoopForIO::Watcher { 247 : public base::Thread, public MessageLoopForIO::Watcher {
245 public: 248 public:
246 explicit Thread(dbus::Bus* bus); 249 explicit Thread(dbus::Bus* bus);
247 virtual ~Thread(); 250 virtual ~Thread();
248 251
249 // MessageLoopForIO::Watcher: 252 // MessageLoopForIO::Watcher:
250 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; 253 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
251 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE; 254 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE;
252 255
253 // Plumbing for NetworkChangeNotifier::IsCurrentlyOffline. 256 // Plumbing for NetworkChangeNotifier::GetCurrentConnectionType.
254 // Safe to call from any thread. 257 // Safe to call from any thread.
255 bool IsCurrentlyOffline() { 258 NetworkChangeNotifier::ConnectionType GetCurrentConnectionType() {
256 return network_manager_api_.IsCurrentlyOffline(); 259 return network_manager_api_.GetCurrentConnectionType();
257 } 260 }
258 261
259 protected: 262 protected:
260 // base::Thread 263 // base::Thread
261 virtual void Init() OVERRIDE; 264 virtual void Init() OVERRIDE;
262 virtual void CleanUp() OVERRIDE; 265 virtual void CleanUp() OVERRIDE;
263 266
264 private: 267 private:
265 // Starts listening for netlink messages. Also handles the messages if there 268 // Starts listening for netlink messages. Also handles the messages if there
266 // are any available on the netlink socket. 269 // are any available on the netlink socket.
(...skipping 13 matching lines...) Expand all
280 283
281 internal::DnsConfigWatcher dns_watcher_; 284 internal::DnsConfigWatcher dns_watcher_;
282 285
283 DISALLOW_COPY_AND_ASSIGN(Thread); 286 DISALLOW_COPY_AND_ASSIGN(Thread);
284 }; 287 };
285 288
286 NetworkChangeNotifierLinux::Thread::Thread(dbus::Bus* bus) 289 NetworkChangeNotifierLinux::Thread::Thread(dbus::Bus* bus)
287 : base::Thread("NetworkChangeNotifier"), 290 : base::Thread("NetworkChangeNotifier"),
288 netlink_fd_(kInvalidSocket), 291 netlink_fd_(kInvalidSocket),
289 network_manager_api_( 292 network_manager_api_(
290 base::Bind(&NetworkChangeNotifier 293 base::Bind(&NetworkChangeNotifier::
291 ::NotifyObserversOfOnlineStateChange), 294 NotifyObserversOfConnectionTypeChange),
292 bus) { 295 bus) {
293 } 296 }
294 297
295 NetworkChangeNotifierLinux::Thread::~Thread() { 298 NetworkChangeNotifierLinux::Thread::~Thread() {
296 DCHECK(!Thread::IsRunning()); 299 DCHECK(!Thread::IsRunning());
297 } 300 }
298 301
299 void NetworkChangeNotifierLinux::Thread::Init() { 302 void NetworkChangeNotifierLinux::Thread::Init() {
300 netlink_fd_ = InitializeNetlinkSocket(); 303 netlink_fd_ = InitializeNetlinkSocket();
301 if (netlink_fd_ < 0) { 304 if (netlink_fd_ < 0) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 base::Thread::Options thread_options(MessageLoop::TYPE_IO, 0); 388 base::Thread::Options thread_options(MessageLoop::TYPE_IO, 0);
386 notifier_thread_->StartWithOptions(thread_options); 389 notifier_thread_->StartWithOptions(thread_options);
387 } 390 }
388 391
389 NetworkChangeNotifierLinux::~NetworkChangeNotifierLinux() { 392 NetworkChangeNotifierLinux::~NetworkChangeNotifierLinux() {
390 // Stopping from here allows us to sanity- check that the notifier 393 // Stopping from here allows us to sanity- check that the notifier
391 // thread shut down properly. 394 // thread shut down properly.
392 notifier_thread_->Stop(); 395 notifier_thread_->Stop();
393 } 396 }
394 397
395 bool NetworkChangeNotifierLinux::IsCurrentlyOffline() const { 398 NetworkChangeNotifier::ConnectionType
396 return notifier_thread_->IsCurrentlyOffline(); 399 NetworkChangeNotifierLinux::GetCurrentConnectionType() const {
400 return notifier_thread_->GetCurrentConnectionType();
397 } 401 }
398 402
399 } // namespace net 403 } // namespace net
OLDNEW
« no previous file with comments | « net/base/network_change_notifier_linux.h ('k') | net/base/network_change_notifier_linux_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698