| OLD | NEW |
| 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 #ifndef CHROMEOS_NETWORK_NETWORK_CONFIGURATION_HANDLER_H_ | 5 #ifndef CHROMEOS_NETWORK_NETWORK_CONFIGURATION_HANDLER_H_ |
| 6 #define CHROMEOS_NETWORK_NETWORK_CONFIGURATION_HANDLER_H_ | 6 #define CHROMEOS_NETWORK_NETWORK_CONFIGURATION_HANDLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 14 #include "base/memory/weak_ptr.h" |
| 14 #include "chromeos/chromeos_export.h" | 15 #include "chromeos/chromeos_export.h" |
| 16 #include "chromeos/network/network_handler.h" |
| 15 #include "chromeos/network/network_handler_callbacks.h" | 17 #include "chromeos/network/network_handler_callbacks.h" |
| 16 | 18 |
| 17 namespace base { | 19 namespace base { |
| 18 class DictionaryValue; | 20 class DictionaryValue; |
| 19 } | 21 } |
| 20 | 22 |
| 23 namespace dbus { |
| 24 class ObjectPath; |
| 25 } |
| 26 |
| 21 namespace chromeos { | 27 namespace chromeos { |
| 22 | 28 |
| 23 // The NetworkConfigurationHandler class is used to create and configure | 29 // The NetworkConfigurationHandler class is used to create and configure |
| 24 // networks in ChromeOS. It mostly calls through to the Shill service API, and | 30 // networks in ChromeOS. It mostly calls through to the Shill service API, and |
| 25 // most calls are asynchronous for that reason. No calls will block on DBus | 31 // most calls are asynchronous for that reason. No calls will block on DBus |
| 26 // calls. | 32 // calls. |
| 27 // | 33 // |
| 28 // This is owned and it's lifetime managed by the Chrome startup code. It's | 34 // This is owned and it's lifetime managed by the Chrome startup code. It's |
| 29 // basically a singleton, but with explicit lifetime management. | 35 // basically a singleton, but with explicit lifetime management. |
| 30 // | 36 // |
| 31 // For accessing lists of remembered networks, and other state information, see | 37 // For accessing lists of remembered networks, and other state information, see |
| 32 // the class NetworkStateHandler. | 38 // the class NetworkStateHandler. |
| 33 // | 39 // |
| 34 // Note on callbacks: Because all the functions here are meant to be | 40 // Note on callbacks: Because all the functions here are meant to be |
| 35 // asynchronous, they all take a |callback| of some type, and an | 41 // asynchronous, they all take a |callback| of some type, and an |
| 36 // |error_callback|. When the operation succeeds, |callback| will be called, and | 42 // |error_callback|. When the operation succeeds, |callback| will be called, and |
| 37 // when it doesn't, |error_callback| will be called with information about the | 43 // when it doesn't, |error_callback| will be called with information about the |
| 38 // error, including a symbolic name for the error and often some error message | 44 // error, including a symbolic name for the error and often some error message |
| 39 // that is suitable for logging. None of the error message text is meant for | 45 // that is suitable for logging. None of the error message text is meant for |
| 40 // user consumption. | 46 // user consumption. |
| 41 | 47 |
| 42 class CHROMEOS_EXPORT NetworkConfigurationHandler { | 48 class CHROMEOS_EXPORT NetworkConfigurationHandler |
| 49 : public base::SupportsWeakPtr<NetworkConfigurationHandler> { |
| 43 public: | 50 public: |
| 44 ~NetworkConfigurationHandler(); | 51 ~NetworkConfigurationHandler(); |
| 45 | 52 |
| 46 // Sets the global instance. Must be called before any calls to Get(). | |
| 47 static void Initialize(); | |
| 48 | |
| 49 // Destroys the global instance. | |
| 50 static void Shutdown(); | |
| 51 | |
| 52 // Gets the global instance. Initialize() must be called first. | |
| 53 static NetworkConfigurationHandler* Get(); | |
| 54 | |
| 55 // Gets the properties of the network with id |service_path|. See note on | 53 // Gets the properties of the network with id |service_path|. See note on |
| 56 // |callback| and |error_callback|, in class description above. | 54 // |callback| and |error_callback|, in class description above. |
| 57 void GetProperties( | 55 void GetProperties( |
| 58 const std::string& service_path, | 56 const std::string& service_path, |
| 59 const network_handler::DictionaryResultCallback& callback, | 57 const network_handler::DictionaryResultCallback& callback, |
| 60 const network_handler::ErrorCallback& error_callback) const; | 58 const network_handler::ErrorCallback& error_callback) const; |
| 61 | 59 |
| 62 // Sets the properties of the network with id |service_path|. This means the | 60 // Sets the properties of the network with id |service_path|. This means the |
| 63 // given properties will be merged with the existing settings, and it won't | 61 // given properties will be merged with the existing settings, and it won't |
| 64 // clear any existing properties. See note on |callback| and |error_callback|, | 62 // clear any existing properties. See note on |callback| and |error_callback|, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 81 const network_handler::ErrorCallback& error_callback); | 79 const network_handler::ErrorCallback& error_callback); |
| 82 | 80 |
| 83 // Creates a network with the given properties in the active Shill profile, | 81 // Creates a network with the given properties in the active Shill profile, |
| 84 // and returns the new service_path to |callback| if successful. See note on | 82 // and returns the new service_path to |callback| if successful. See note on |
| 85 // |callback| and |error_callback|, in class description above. | 83 // |callback| and |error_callback|, in class description above. |
| 86 // This may also be used to update an existing matching configuration, see | 84 // This may also be used to update an existing matching configuration, see |
| 87 // Shill documentation for Manager.ConfigureService and Manger.GetService. | 85 // Shill documentation for Manager.ConfigureService and Manger.GetService. |
| 88 void CreateConfiguration( | 86 void CreateConfiguration( |
| 89 const base::DictionaryValue& properties, | 87 const base::DictionaryValue& properties, |
| 90 const network_handler::StringResultCallback& callback, | 88 const network_handler::StringResultCallback& callback, |
| 91 const network_handler::ErrorCallback& error_callback) const; | 89 const network_handler::ErrorCallback& error_callback); |
| 92 | 90 |
| 93 // Removes the network |service_path| from the remembered network list in the | 91 // Removes the network |service_path| from the remembered network list in the |
| 94 // active Shill profile. The network may still show up in the visible networks | 92 // active Shill profile. The network may still show up in the visible networks |
| 95 // after this, but no profile configuration will remain. See note on | 93 // after this, but no profile configuration will remain. See note on |
| 96 // |callback| and |error_callback|, in class description above. | 94 // |callback| and |error_callback|, in class description above. |
| 97 void RemoveConfiguration( | 95 void RemoveConfiguration( |
| 98 const std::string& service_path, | 96 const std::string& service_path, |
| 99 const base::Closure& callback, | 97 const base::Closure& callback, |
| 100 const network_handler::ErrorCallback& error_callback) const; | 98 const network_handler::ErrorCallback& error_callback) const; |
| 101 | 99 |
| 102 private: | 100 // Construct and initialize an instance for testing. |
| 101 static NetworkConfigurationHandler* InitializeForTest( |
| 102 NetworkStateHandler* network_state_handler); |
| 103 |
| 104 protected: |
| 105 friend class NetworkHandler; |
| 103 friend class NetworkConfigurationHandlerTest; | 106 friend class NetworkConfigurationHandlerTest; |
| 107 |
| 104 NetworkConfigurationHandler(); | 108 NetworkConfigurationHandler(); |
| 109 void Init(NetworkStateHandler* network_state_handler); |
| 110 |
| 111 void RunCreateNetworkCallback( |
| 112 const network_handler::StringResultCallback& callback, |
| 113 const dbus::ObjectPath& service_path); |
| 114 |
| 115 NetworkStateHandler* network_state_handler_; |
| 105 | 116 |
| 106 DISALLOW_COPY_AND_ASSIGN(NetworkConfigurationHandler); | 117 DISALLOW_COPY_AND_ASSIGN(NetworkConfigurationHandler); |
| 107 }; | 118 }; |
| 108 | 119 |
| 109 } // namespace chromeos | 120 } // namespace chromeos |
| 110 | 121 |
| 111 #endif // CHROMEOS_NETWORK_NETWORK_CONFIGURATION_HANDLER_H_ | 122 #endif // CHROMEOS_NETWORK_NETWORK_CONFIGURATION_HANDLER_H_ |
| OLD | NEW |