| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ | 6 #define CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 // Enables/disables offline mode. | 366 // Enables/disables offline mode. |
| 367 virtual void EnableOfflineMode(bool enable) = 0; | 367 virtual void EnableOfflineMode(bool enable) = 0; |
| 368 | 368 |
| 369 // Fetches IP configs for a given device_path | 369 // Fetches IP configs for a given device_path |
| 370 virtual NetworkIPConfigVector GetIPConfigs( | 370 virtual NetworkIPConfigVector GetIPConfigs( |
| 371 const std::string& device_path) = 0; | 371 const std::string& device_path) = 0; |
| 372 | 372 |
| 373 // Fetches debug network info for display in about:network. | 373 // Fetches debug network info for display in about:network. |
| 374 // The page will have a meta refresh of |refresh| seconds if |refresh| > 0. | 374 // The page will have a meta refresh of |refresh| seconds if |refresh| > 0. |
| 375 virtual std::string GetHtmlInfo(int refresh) = 0; | 375 virtual std::string GetHtmlInfo(int refresh) = 0; |
| 376 }; | |
| 377 | 376 |
| 378 // This class handles the interaction with the ChromeOS network library APIs. | 377 // Get library implementation. |
| 379 // Classes can add themselves as observers. Users can get an instance of this | 378 static NetworkLibrary* GetImpl(bool stub); |
| 380 // library class like this: NetworkLibrary::Get() | |
| 381 class NetworkLibraryImpl : public NetworkLibrary, | |
| 382 public URLRequestJobTracker::JobObserver { | |
| 383 public: | |
| 384 NetworkLibraryImpl(); | |
| 385 virtual ~NetworkLibraryImpl(); | |
| 386 | |
| 387 // URLRequestJobTracker::JobObserver methods (called on the IO thread): | |
| 388 virtual void OnJobAdded(URLRequestJob* job); | |
| 389 virtual void OnJobRemoved(URLRequestJob* job); | |
| 390 virtual void OnJobDone(URLRequestJob* job, const URLRequestStatus& status); | |
| 391 virtual void OnJobRedirect(URLRequestJob* job, const GURL& location, | |
| 392 int status_code); | |
| 393 virtual void OnBytesRead(URLRequestJob* job, int byte_count); | |
| 394 | |
| 395 // NetworkLibrary overrides. | |
| 396 virtual void AddObserver(Observer* observer); | |
| 397 virtual void RemoveObserver(Observer* observer); | |
| 398 | |
| 399 virtual const EthernetNetwork& ethernet_network() const { return ethernet_; } | |
| 400 virtual bool ethernet_connecting() const { return ethernet_.connecting(); } | |
| 401 virtual bool ethernet_connected() const { return ethernet_.connected(); } | |
| 402 | |
| 403 virtual const std::string& wifi_name() const { return wifi_.name(); } | |
| 404 virtual bool wifi_connecting() const { return wifi_.connecting(); } | |
| 405 virtual bool wifi_connected() const { return wifi_.connected(); } | |
| 406 virtual int wifi_strength() const { return wifi_.strength(); } | |
| 407 | |
| 408 virtual const std::string& cellular_name() const { return cellular_.name(); } | |
| 409 virtual bool cellular_connecting() const { return cellular_.connecting(); } | |
| 410 virtual bool cellular_connected() const { return cellular_.connected(); } | |
| 411 virtual int cellular_strength() const { return cellular_.strength(); } | |
| 412 | |
| 413 virtual bool Connected() const; | |
| 414 virtual bool Connecting() const; | |
| 415 virtual const std::string& IPAddress() const; | |
| 416 | |
| 417 virtual const WifiNetworkVector& wifi_networks() const { | |
| 418 return wifi_networks_; | |
| 419 } | |
| 420 | |
| 421 virtual const WifiNetworkVector& remembered_wifi_networks() const { | |
| 422 return remembered_wifi_networks_; | |
| 423 } | |
| 424 | |
| 425 virtual const CellularNetworkVector& cellular_networks() const { | |
| 426 return cellular_networks_; | |
| 427 } | |
| 428 | |
| 429 virtual const CellularNetworkVector& remembered_cellular_networks() const { | |
| 430 return remembered_cellular_networks_; | |
| 431 } | |
| 432 | |
| 433 virtual bool FindWifiNetworkByPath(const std::string& path, | |
| 434 WifiNetwork* network) const; | |
| 435 virtual bool FindCellularNetworkByPath(const std::string& path, | |
| 436 CellularNetwork* network) const; | |
| 437 | |
| 438 virtual void RequestWifiScan(); | |
| 439 virtual bool GetWifiAccessPoints(WifiAccessPointVector* result); | |
| 440 virtual bool ConnectToPreferredNetworkIfAvailable(); | |
| 441 virtual bool PreferredNetworkConnected(); | |
| 442 virtual bool PreferredNetworkFailed(); | |
| 443 virtual void ConnectToWifiNetwork(WifiNetwork network, | |
| 444 const std::string& password, | |
| 445 const std::string& identity, | |
| 446 const std::string& certpath); | |
| 447 virtual void ConnectToWifiNetwork(const std::string& ssid, | |
| 448 const std::string& password, | |
| 449 const std::string& identity, | |
| 450 const std::string& certpath, | |
| 451 bool auto_connect); | |
| 452 virtual void ConnectToCellularNetwork(CellularNetwork network); | |
| 453 virtual void DisconnectFromWirelessNetwork(const WirelessNetwork& network); | |
| 454 virtual void SaveCellularNetwork(const CellularNetwork& network); | |
| 455 virtual void SaveWifiNetwork(const WifiNetwork& network); | |
| 456 virtual void ForgetWirelessNetwork(const std::string& service_path); | |
| 457 | |
| 458 virtual bool ethernet_available() const { | |
| 459 return available_devices_ & (1 << TYPE_ETHERNET); | |
| 460 } | |
| 461 virtual bool wifi_available() const { | |
| 462 return available_devices_ & (1 << TYPE_WIFI); | |
| 463 } | |
| 464 virtual bool cellular_available() const { | |
| 465 return available_devices_ & (1 << TYPE_CELLULAR); | |
| 466 } | |
| 467 | |
| 468 virtual bool ethernet_enabled() const { | |
| 469 return enabled_devices_ & (1 << TYPE_ETHERNET); | |
| 470 } | |
| 471 virtual bool wifi_enabled() const { | |
| 472 return enabled_devices_ & (1 << TYPE_WIFI); | |
| 473 } | |
| 474 virtual bool cellular_enabled() const { | |
| 475 return enabled_devices_ & (1 << TYPE_CELLULAR); | |
| 476 } | |
| 477 | |
| 478 virtual bool offline_mode() const { return offline_mode_; } | |
| 479 | |
| 480 virtual void EnableEthernetNetworkDevice(bool enable); | |
| 481 virtual void EnableWifiNetworkDevice(bool enable); | |
| 482 virtual void EnableCellularNetworkDevice(bool enable); | |
| 483 virtual void EnableOfflineMode(bool enable); | |
| 484 virtual NetworkIPConfigVector GetIPConfigs(const std::string& device_path); | |
| 485 virtual std::string GetHtmlInfo(int refresh); | |
| 486 | |
| 487 virtual void UpdateSystemInfo(); | |
| 488 | |
| 489 private: | |
| 490 | |
| 491 // This method is called when there's a change in network status. | |
| 492 // This method is called on a background thread. | |
| 493 static void NetworkStatusChangedHandler(void* object); | |
| 494 | |
| 495 // This parses SystemInfo into: | |
| 496 // - an EthernetNetwork | |
| 497 // - a WifiNetworkVector of wifi networks | |
| 498 // - a CellularNetworkVector of cellular networks. | |
| 499 // - a WifiNetworkVector of remembered wifi networks | |
| 500 // - a CellularNetworkVector of remembered cellular networks. | |
| 501 static void ParseSystem(SystemInfo* system, | |
| 502 EthernetNetwork* ethernet, | |
| 503 WifiNetworkVector* wifi_networks, | |
| 504 CellularNetworkVector* ceullular_networks, | |
| 505 WifiNetworkVector* remembered_wifi_networks, | |
| 506 CellularNetworkVector* remembered_ceullular_networks); | |
| 507 | |
| 508 // This methods loads the initial list of networks on startup and starts the | |
| 509 // monitoring of network changes. | |
| 510 void Init(); | |
| 511 // Initialize with test data. | |
| 512 void InitTestData(); | |
| 513 | |
| 514 // Returns the preferred wifi network. | |
| 515 WifiNetwork* GetPreferredNetwork(); | |
| 516 | |
| 517 // Gets the WifiNetwork with the given name. Returns NULL if not found. | |
| 518 // Only used by GetPreferredNetwork() to lookup "Google" and "GoogleA" (hack) | |
| 519 WifiNetwork* GetWifiNetworkByName(const std::string& name); | |
| 520 | |
| 521 // Gets the WirelessNetwork (WifiNetwork or CellularNetwork) by path | |
| 522 template<typename T> | |
| 523 T* GetWirelessNetworkByPath(std::vector<T>& networks, | |
| 524 const std::string& path); | |
| 525 template<typename T> | |
| 526 const T* GetWirelessNetworkByPath(const std::vector<T>& networks, | |
| 527 const std::string& path) const; | |
| 528 | |
| 529 // Enables/disables the specified network device. | |
| 530 void EnableNetworkDeviceType(ConnectionType device, bool enable); | |
| 531 | |
| 532 // Update the cached network status. | |
| 533 // This will notify all the Observers. | |
| 534 void UpdateNetworkStatus(); | |
| 535 | |
| 536 // Checks network traffic to see if there is any uploading. | |
| 537 // If there is download traffic, then true is passed in for download. | |
| 538 // If there is network traffic then start timer that invokes | |
| 539 // NetworkTrafficTimerFired. | |
| 540 void CheckNetworkTraffic(bool download); | |
| 541 | |
| 542 // Called when the timer fires and we need to send out NetworkTraffic | |
| 543 // notifications. | |
| 544 void NetworkTrafficTimerFired(); | |
| 545 | |
| 546 // This is a helper method to notify the observers on the UI thread. | |
| 547 void NotifyNetworkTraffic(int traffic_type); | |
| 548 | |
| 549 // This will notify all obeservers on the UI thread. | |
| 550 void NotifyObservers(); | |
| 551 | |
| 552 ObserverList<Observer> observers_; | |
| 553 | |
| 554 // The amount of time to wait between each NetworkTraffic notifications. | |
| 555 static const int kNetworkTrafficeTimerSecs; | |
| 556 | |
| 557 // Timer for sending NetworkTraffic notification every | |
| 558 // kNetworkTrafficeTimerSecs seconds. | |
| 559 base::OneShotTimer<NetworkLibraryImpl> timer_; | |
| 560 | |
| 561 // The current traffic type that will be sent out for the next NetworkTraffic | |
| 562 // notification. This is a bitfield of TrafficTypeMasks. | |
| 563 int traffic_type_; | |
| 564 | |
| 565 // The network status connection for monitoring network status changes. | |
| 566 MonitorNetworkConnection network_status_connection_; | |
| 567 | |
| 568 // The ethernet network. | |
| 569 EthernetNetwork ethernet_; | |
| 570 | |
| 571 // The list of available wifi networks. | |
| 572 WifiNetworkVector wifi_networks_; | |
| 573 | |
| 574 // The current connected (or connecting) wifi network. | |
| 575 WifiNetwork wifi_; | |
| 576 | |
| 577 // The remembered wifi networks. | |
| 578 WifiNetworkVector remembered_wifi_networks_; | |
| 579 | |
| 580 // The list of available cellular networks. | |
| 581 CellularNetworkVector cellular_networks_; | |
| 582 | |
| 583 // The current connected (or connecting) cellular network. | |
| 584 CellularNetwork cellular_; | |
| 585 | |
| 586 // The remembered cellular networks. | |
| 587 CellularNetworkVector remembered_cellular_networks_; | |
| 588 | |
| 589 // The current available network devices. Bitwise flag of ConnectionTypes. | |
| 590 int available_devices_; | |
| 591 | |
| 592 // The current enabled network devices. Bitwise flag of ConnectionTypes. | |
| 593 int enabled_devices_; | |
| 594 | |
| 595 // The current connected network devices. Bitwise flag of ConnectionTypes. | |
| 596 int connected_devices_; | |
| 597 | |
| 598 bool offline_mode_; | |
| 599 | |
| 600 DISALLOW_COPY_AND_ASSIGN(NetworkLibraryImpl); | |
| 601 }; | 379 }; |
| 602 | 380 |
| 603 } // namespace chromeos | 381 } // namespace chromeos |
| 604 | 382 |
| 605 #endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ | 383 #endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ |
| OLD | NEW |