Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
| 16 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
| 17 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 18 #include "base/string16.h" | 18 #include "base/string16.h" |
| 19 #include "base/timer.h" | 19 #include "base/timer.h" |
| 20 #include "third_party/cros/chromeos_network.h" | 20 #include "third_party/cros/chromeos_network.h" |
| 21 | 21 |
| 22 namespace base { | 22 namespace base { |
| 23 class DictionaryValue; | 23 class DictionaryValue; |
| 24 class Value; | 24 class Value; |
| 25 } | 25 } |
| 26 | 26 |
| 27 namespace chromeos { | 27 namespace chromeos { |
| 28 | 28 |
| 29 class Network; | |
| 29 class NetworkDeviceParser; | 30 class NetworkDeviceParser; |
| 30 class NetworkParser; | 31 class NetworkParser; |
| 31 | 32 |
| 32 // This is the list of all implementation classes that are allowed | 33 // This is the list of all implementation classes that are allowed |
| 33 // access to the internals of the network library classes. | 34 // access to the internals of the network library classes. |
| 34 #define NETWORK_LIBRARY_IMPL_FRIENDS \ | 35 #define NETWORK_LIBRARY_IMPL_FRIENDS \ |
| 35 friend class NetworkLibraryImplBase; \ | 36 friend class NetworkLibraryImplBase; \ |
| 36 friend class NetworkLibraryImplCros; \ | 37 friend class NetworkLibraryImplCros; \ |
| 37 friend class NetworkLibraryImplStub; | 38 friend class NetworkLibraryImplStub; |
| 38 | 39 |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 std::string language; | 357 std::string language; |
| 357 | 358 |
| 358 CellularApn(); | 359 CellularApn(); |
| 359 CellularApn(const std::string& apn, const std::string& network_id, | 360 CellularApn(const std::string& apn, const std::string& network_id, |
| 360 const std::string& username, const std::string& password); | 361 const std::string& username, const std::string& password); |
| 361 ~CellularApn(); | 362 ~CellularApn(); |
| 362 void Set(const base::DictionaryValue& dict); | 363 void Set(const base::DictionaryValue& dict); |
| 363 }; | 364 }; |
| 364 typedef std::vector<CellularApn> CellularApnList; | 365 typedef std::vector<CellularApn> CellularApnList; |
| 365 | 366 |
| 367 // Holds meta information for a network property: Whether the property is under | |
| 368 // policy control, if it is user-editable, and whether the policy-provided | |
| 369 // default value, if applicable. | |
| 370 class NetworkPropertyUIData { | |
| 371 public: | |
| 372 // Enum values indicating the entity controlling the property. | |
| 373 enum Controller { | |
| 374 // Property is managed by policy. | |
| 375 CONTROLLER_POLICY, | |
| 376 // The user controls the policy. | |
| 377 CONTROLLER_USER, | |
| 378 }; | |
| 379 | |
| 380 // Initializes an empty object. | |
| 381 NetworkPropertyUIData(); | |
| 382 | |
| 383 // Updates the object from the network-level UI data. |property_key| may be | |
| 384 // null, in which case the there'll be no default value and |controller| will | |
| 385 // be set to CONTROLLER_POLICY iff the network is managed. | |
| 386 void UpdateFromNetwork(const Network* network, const char* property_key); | |
| 387 | |
| 388 Controller controller() const { return controller_; } | |
| 389 const base::Value* default_value() const { return default_value_.get(); } | |
| 390 bool editable() const { return controller() != CONTROLLER_POLICY; } | |
| 391 | |
| 392 private: | |
| 393 Controller controller_; | |
| 394 scoped_ptr<base::Value> default_value_; | |
| 395 | |
| 396 DISALLOW_COPY_AND_ASSIGN(NetworkPropertyUIData); | |
| 397 }; | |
|
stevenjb
2011/11/29 07:23:19
I think this would be better in its own file. netw
Mattias Nissler (ping if slow)
2011/11/29 14:48:50
Done.
| |
| 398 | |
| 366 // Cellular network is considered low data when less than 60 minues. | 399 // Cellular network is considered low data when less than 60 minues. |
| 367 static const int kCellularDataLowSecs = 60 * 60; | 400 static const int kCellularDataLowSecs = 60 * 60; |
| 368 | 401 |
| 369 // Cellular network is considered low data when less than 30 minues. | 402 // Cellular network is considered low data when less than 30 minues. |
| 370 static const int kCellularDataVeryLowSecs = 30 * 60; | 403 static const int kCellularDataVeryLowSecs = 30 * 60; |
| 371 | 404 |
| 372 // Cellular network is considered low data when less than 100MB. | 405 // Cellular network is considered low data when less than 100MB. |
| 373 static const int kCellularDataLowBytes = 100 * 1024 * 1024; | 406 static const int kCellularDataLowBytes = 100 * 1024 * 1024; |
| 374 | 407 |
| 375 // Cellular network is considered very low data when less than 50MB. | 408 // Cellular network is considered very low data when less than 50MB. |
| 376 static const int kCellularDataVeryLowBytes = 50 * 1024 * 1024; | 409 static const int kCellularDataVeryLowBytes = 50 * 1024 * 1024; |
| 377 | 410 |
| 378 // The value of priority if it is not set. | 411 // The value of priority if it is not set. |
| 379 const int kPriorityNotSet = 0; | 412 const int kPriorityNotSet = 0; |
| 380 // The value of priority if network is preferred. | 413 // The value of priority if network is preferred. |
| 381 const int kPriorityPreferred = 1; | 414 const int kPriorityPreferred = 1; |
| 382 | 415 |
| 383 // Keys used in the UI data dictionary. | 416 // Keys used in the UI data dictionary. |
| 384 | 417 |
| 385 // Source of the ONC network. This is an integer according to enum ONCSource. | 418 // Source of the ONC network. This is an integer according to enum ONCSource. |
| 386 extern const char kUIDataKeyONCSource[]; | 419 extern const char kUIDataKeyONCSource[]; |
| 420 extern const char kUIDataKeyProperties[]; | |
| 421 extern const char kUIDataKeyPropertiesController[]; | |
| 422 extern const char kUIDataKeyPropertiesControllerPolicy[]; | |
| 423 extern const char kUIDataKeyPropertiesControllerUser[]; | |
| 424 extern const char kUIDataKeyPropertiesDefaultValue[]; | |
| 425 | |
| 426 // Names of the properties stored in the dictionary under | |
| 427 // kUIDataKeyPropertiesController. | |
| 428 extern const char kUIDataPropertyAutoConnect[]; | |
| 429 extern const char kUIDataPropertyPreferred[]; | |
| 387 | 430 |
| 388 // Contains data related to the flimflam.Device interface, | 431 // Contains data related to the flimflam.Device interface, |
| 389 // e.g. ethernet, wifi, cellular. | 432 // e.g. ethernet, wifi, cellular. |
| 390 // TODO(dpolukhin): refactor to make base class and device specific derivatives. | 433 // TODO(dpolukhin): refactor to make base class and device specific derivatives. |
| 391 class NetworkDevice { | 434 class NetworkDevice { |
| 392 public: | 435 public: |
| 393 explicit NetworkDevice(const std::string& device_path); | 436 explicit NetworkDevice(const std::string& device_path); |
| 394 ~NetworkDevice(); | 437 ~NetworkDevice(); |
| 395 | 438 |
| 396 NetworkDeviceParser* device_parser() { return device_parser_.get(); } | 439 NetworkDeviceParser* device_parser() { return device_parser_.get(); } |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 627 | 670 |
| 628 bool added() const { return added_; } | 671 bool added() const { return added_; } |
| 629 bool notify_failure() const { return notify_failure_; } | 672 bool notify_failure() const { return notify_failure_; } |
| 630 const std::string& profile_path() const { return profile_path_; } | 673 const std::string& profile_path() const { return profile_path_; } |
| 631 NetworkProfileType profile_type() const { return profile_type_; } | 674 NetworkProfileType profile_type() const { return profile_type_; } |
| 632 | 675 |
| 633 const std::string& unique_id() const { return unique_id_; } | 676 const std::string& unique_id() const { return unique_id_; } |
| 634 int priority_order() const { return priority_order_; } | 677 int priority_order() const { return priority_order_; } |
| 635 | 678 |
| 636 const std::string& proxy_config() const { return proxy_config_; } | 679 const std::string& proxy_config() const { return proxy_config_; } |
| 680 | |
| 637 const DictionaryValue* ui_data() const { return &ui_data_; } | 681 const DictionaryValue* ui_data() const { return &ui_data_; } |
| 638 DictionaryValue* ui_data() { return &ui_data_; } | 682 DictionaryValue* ui_data() { return &ui_data_; } |
| 639 | 683 |
| 640 void set_notify_failure(bool state) { notify_failure_ = state; } | 684 void set_notify_failure(bool state) { notify_failure_ = state; } |
| 641 | 685 |
| 642 void SetPreferred(bool preferred); | 686 void SetPreferred(bool preferred); |
| 643 | 687 |
| 644 void SetAutoConnect(bool auto_connect); | 688 void SetAutoConnect(bool auto_connect); |
| 645 | 689 |
| 646 void SetName(const std::string& name); | 690 void SetName(const std::string& name); |
| 647 | 691 |
| 648 void SetSaveCredentials(bool save_credentials); | 692 void SetSaveCredentials(bool save_credentials); |
| 649 | 693 |
| 650 // Return a string representation of the state code. | 694 // Return a string representation of the state code. |
| 651 std::string GetStateString() const; | 695 std::string GetStateString() const; |
| 652 | 696 |
| 653 // Return a string representation of the error code. | 697 // Return a string representation of the error code. |
| 654 std::string GetErrorString() const; | 698 std::string GetErrorString() const; |
| 655 | 699 |
| 656 void SetProxyConfig(const std::string& proxy_config); | 700 void SetProxyConfig(const std::string& proxy_config); |
| 657 | 701 |
| 658 // Return true if the network must be in the user profile (e.g. has certs). | 702 // Return true if the network must be in the user profile (e.g. has certs). |
| 659 virtual bool RequiresUserProfile() const; | 703 virtual bool RequiresUserProfile() const; |
| 660 | 704 |
| 661 // Copy any credentials from a remembered network that are unset in |this|. | 705 // Copy any credentials from a remembered network that are unset in |this|. |
| 662 virtual void CopyCredentialsFromRemembered(Network* remembered); | 706 virtual void CopyCredentialsFromRemembered(Network* remembered); |
| 663 | 707 |
| 708 // Accessors returning policy management state information. | |
| 709 bool IsManagedByPolicy() const; | |
| 710 void GetUIDataForPreferred(NetworkPropertyUIData* ui_data) const; | |
| 711 void GetUIDataForAutoConnect(NetworkPropertyUIData* ui_data) const; | |
| 712 void GetUIDataForIPConfig(NetworkPropertyUIData* ui_data) const; | |
|
stevenjb
2011/11/29 07:23:19
These last three seem unnecessary. Why not just ca
Mattias Nissler (ping if slow)
2011/11/29 14:48:50
Obsolete in the new version.
| |
| 713 | |
| 664 // Static helper functions. | 714 // Static helper functions. |
| 665 static bool IsConnectedState(ConnectionState state) { | 715 static bool IsConnectedState(ConnectionState state) { |
| 666 return (state == STATE_READY || | 716 return (state == STATE_READY || |
| 667 state == STATE_ONLINE || | 717 state == STATE_ONLINE || |
| 668 state == STATE_PORTAL); | 718 state == STATE_PORTAL); |
| 669 } | 719 } |
| 670 static bool IsConnectingState(ConnectionState state) { | 720 static bool IsConnectingState(ConnectionState state) { |
| 671 return (state == STATE_ASSOCIATION || | 721 return (state == STATE_ASSOCIATION || |
| 672 state == STATE_CONFIGURATION || | 722 state == STATE_CONFIGURATION || |
| 673 state == STATE_CARRIER); | 723 state == STATE_CARRIER); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 709 virtual void SetBooleanProperty(const char* prop, bool b, bool* dest); | 759 virtual void SetBooleanProperty(const char* prop, bool b, bool* dest); |
| 710 virtual void SetIntegerProperty(const char* prop, int i, int* dest); | 760 virtual void SetIntegerProperty(const char* prop, int i, int* dest); |
| 711 virtual void SetValueProperty(const char* prop, base::Value* val); | 761 virtual void SetValueProperty(const char* prop, base::Value* val); |
| 712 virtual void ClearProperty(const char* prop); | 762 virtual void ClearProperty(const char* prop); |
| 713 | 763 |
| 714 // This will clear the property if string is empty. Otherwise, it will set it. | 764 // This will clear the property if string is empty. Otherwise, it will set it. |
| 715 virtual void SetOrClearStringProperty(const char* prop, | 765 virtual void SetOrClearStringProperty(const char* prop, |
| 716 const std::string& str, | 766 const std::string& str, |
| 717 std::string* dest); | 767 std::string* dest); |
| 718 | 768 |
| 769 // Check whether a property is configured by policy and should thus not be | |
| 770 // editable by the user. | |
| 771 bool IsManaged(const char* prop); | |
|
stevenjb
2011/11/29 07:23:19
This appears to be unimplemented?
Mattias Nissler (ping if slow)
2011/11/29 14:48:50
Good catch, this is a leftover. Removed.
| |
| 772 | |
| 719 void set_unique_id(const std::string& unique_id) { unique_id_ = unique_id; } | 773 void set_unique_id(const std::string& unique_id) { unique_id_ = unique_id; } |
| 720 | 774 |
| 721 private: | 775 private: |
| 722 // This allows NetworkParser and its subclasses access to device | 776 // This allows NetworkParser and its subclasses access to device |
| 723 // privates so that they can be reconstituted during parsing. The | 777 // privates so that they can be reconstituted during parsing. The |
| 724 // parsers only access things through the private set_ functions so | 778 // parsers only access things through the private set_ functions so |
| 725 // that this class can evolve without having to change all the | 779 // that this class can evolve without having to change all the |
| 726 // parsers. | 780 // parsers. |
| 727 friend class NetworkParser; | 781 friend class NetworkParser; |
| 728 friend class NativeNetworkParser; | 782 friend class NativeNetworkParser; |
| (...skipping 1030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1759 const std::string& service_path) = 0; | 1813 const std::string& service_path) = 0; |
| 1760 | 1814 |
| 1761 // Factory function, creates a new instance and returns ownership. | 1815 // Factory function, creates a new instance and returns ownership. |
| 1762 // For normal usage, access the singleton via CrosLibrary::Get(). | 1816 // For normal usage, access the singleton via CrosLibrary::Get(). |
| 1763 static NetworkLibrary* GetImpl(bool stub); | 1817 static NetworkLibrary* GetImpl(bool stub); |
| 1764 }; | 1818 }; |
| 1765 | 1819 |
| 1766 } // namespace chromeos | 1820 } // namespace chromeos |
| 1767 | 1821 |
| 1768 #endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ | 1822 #endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ |
| OLD | NEW |