wifi_service.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // Copyright 2013 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. #ifndef COMPONENTS_WIFI_WIFI_SERVICE_H_
  5. #define COMPONENTS_WIFI_WIFI_SERVICE_H_
  6. #include <memory>
  7. #include <set>
  8. #include <string>
  9. #include <vector>
  10. #include "base/callback.h"
  11. #include "base/memory/ref_counted.h"
  12. #include "base/task/sequenced_task_runner.h"
  13. #include "base/task/single_thread_task_runner.h"
  14. #include "base/values.h"
  15. #include "components/wifi/wifi_export.h"
  16. namespace wifi {
  17. // WiFiService interface used by implementation of chrome.networkingPrivate
  18. // JavaScript extension API. All methods should be called on worker thread.
  19. // It could be created on any (including UI) thread, so nothing expensive should
  20. // be done in the constructor. See |NetworkingPrivateService| for wrapper
  21. // accessible on UI thread.
  22. class WIFI_EXPORT WiFiService {
  23. public:
  24. using NetworkGuidList = std::vector<std::string>;
  25. using NetworkGuidListCallback =
  26. base::RepeatingCallback<void(const NetworkGuidList& network_guid_list)>;
  27. WiFiService(const WiFiService&) = delete;
  28. WiFiService& operator=(const WiFiService&) = delete;
  29. virtual ~WiFiService() {}
  30. // Initialize WiFiService, store |task_runner| for posting worker tasks.
  31. virtual void Initialize(
  32. scoped_refptr<base::SequencedTaskRunner> task_runner) = 0;
  33. // UnInitialize WiFiService.
  34. virtual void UnInitialize() = 0;
  35. // Create instance of |WiFiService| for normal use.
  36. static WiFiService* Create();
  37. // Get Properties of network identified by |network_guid|. Populates
  38. // |properties| on success, |error| on failure.
  39. virtual void GetProperties(const std::string& network_guid,
  40. base::Value::Dict* properties,
  41. std::string* error) = 0;
  42. // Gets the merged properties of the network with id |network_guid| from the
  43. // sources: User settings, shared settings, user policy, device policy and
  44. // the currently active settings. Populates |managed_properties| on success,
  45. // |error| on failure.
  46. virtual void GetManagedProperties(const std::string& network_guid,
  47. base::Value::Dict* managed_properties,
  48. std::string* error) = 0;
  49. // Get the cached read-only properties of the network with id |network_guid|.
  50. // This is meant to be a higher performance function than |GetProperties|,
  51. // which requires a round trip to query the networking subsystem. It only
  52. // returns a subset of the properties returned by |GetProperties|. Populates
  53. // |properties| on success, |error| on failure.
  54. virtual void GetState(const std::string& network_guid,
  55. base::Value::Dict* properties,
  56. std::string* error) = 0;
  57. // Set Properties of network identified by |network_guid|. Populates |error|
  58. // on failure.
  59. virtual void SetProperties(const std::string& network_guid,
  60. base::Value::Dict properties,
  61. std::string* error) = 0;
  62. // Creates a new network configuration from |properties|. If |shared| is true,
  63. // share this network configuration with other users. If a matching configured
  64. // network already exists, this will fail and populate |error|. On success
  65. // populates the |network_guid| of the new network.
  66. virtual void CreateNetwork(bool shared,
  67. base::Value::Dict properties,
  68. std::string* network_guid,
  69. std::string* error) = 0;
  70. // Get list of visible networks of |network_type| (one of onc::network_type).
  71. // Populates |network_list| on success.
  72. virtual void GetVisibleNetworks(const std::string& network_type,
  73. bool include_details,
  74. base::Value::List* network_list) = 0;
  75. // Request network scan. Send |NetworkListChanged| event on completion.
  76. virtual void RequestNetworkScan() = 0;
  77. // Start connect to network identified by |network_guid|. Populates |error|
  78. // on failure.
  79. virtual void StartConnect(const std::string& network_guid,
  80. std::string* error) = 0;
  81. // Start disconnect from network identified by |network_guid|. Populates
  82. // |error| on failure.
  83. virtual void StartDisconnect(const std::string& network_guid,
  84. std::string* error) = 0;
  85. // Get WiFi Key for network identified by |network_guid| from the
  86. // system (if it has one) and store it in |key_data|. User privilege elevation
  87. // may be required, and function will fail if user privileges are not
  88. // sufficient. Populates |error| on failure.
  89. virtual void GetKeyFromSystem(const std::string& network_guid,
  90. std::string* key_data,
  91. std::string* error) = 0;
  92. // Set observers to run when |NetworksChanged| and |NetworksListChanged|
  93. // events needs to be sent. Notifications are posted on |task_runner|.
  94. virtual void SetEventObservers(
  95. scoped_refptr<base::SingleThreadTaskRunner> task_runner,
  96. NetworkGuidListCallback networks_changed_observer,
  97. NetworkGuidListCallback network_list_changed_observer) = 0;
  98. // Request update of Connected Network information. Send |NetworksChanged|
  99. // event on completion.
  100. virtual void RequestConnectedNetworkUpdate() = 0;
  101. // Get the SSID of the currently connected network, if any.
  102. virtual void GetConnectedNetworkSSID(std::string* ssid,
  103. std::string* error) = 0;
  104. protected:
  105. WiFiService() {}
  106. // Error constants.
  107. static const char kErrorAssociateToNetwork[];
  108. static const char kErrorInvalidData[];
  109. static const char kErrorNotConfigured[];
  110. static const char kErrorNotConnected[];
  111. static const char kErrorNotFound[];
  112. static const char kErrorNotImplemented[];
  113. static const char kErrorScanForNetworksWithName[];
  114. static const char kErrorWiFiService[];
  115. };
  116. } // namespace wifi
  117. #endif // COMPONENTS_WIFI_WIFI_SERVICE_H_