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_MANAGED_NETWORK_CONFIGURATION_HANDLER_H_ |
6 #define CHROMEOS_NETWORK_NETWORK_CONFIGURATION_HANDLER_H_ | 6 #define CHROMEOS_NETWORK_MANAGED_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 "chromeos/chromeos_export.h" | 14 #include "chromeos/chromeos_export.h" |
15 #include "chromeos/network/network_handler_callbacks.h" | 15 #include "chromeos/network/network_handler_callbacks.h" |
16 | 16 |
17 namespace base { | 17 namespace base { |
18 class DictionaryValue; | 18 class DictionaryValue; |
19 } | 19 } |
20 | 20 |
21 namespace chromeos { | 21 namespace chromeos { |
22 | 22 |
23 // The NetworkConfigurationHandler class is used to create and configure | 23 // The ManagedNetworkConfigurationHandler class is used to create and configure |
24 // networks in ChromeOS. It mostly calls through to the Shill service API, and | 24 // networks in ChromeOS using ONC, and to enforce and apply policy coded in the |
25 // most calls are asynchronous for that reason. No calls will block on DBus | 25 // ONC. It sends Shill dictionaries to and calls through to the |
26 // calls. | 26 // NetworkConfigurationHandler to do the work of configuring networks. To |
27 // | |
28 // This is owned and it's lifetime managed by aura::Shell. | |
29 // | 27 // |
30 // For accessing lists of remembered networks, and other state information, see | 28 // For accessing lists of remembered networks, and other state information, see |
31 // the class NetworkStateHandler. | 29 // the class NetworkStateHandler. |
32 // | 30 // |
| 31 // The lifetime of ManagedNetworkConfigurationHandler is managed by by the |
| 32 // Chrome startup code. |
| 33 // |
| 34 // For accessing lists of remembered networks, and other state information, see |
| 35 // the class NetworkStateHandler. |
| 36 // |
| 37 // This class takes ONC GUIDs as identifiers, and uses those to look up the |
| 38 // service path of the requested network to pass on to Shill. When it passes |
| 39 // properties to Shill, it first applies policy to the given properties and |
| 40 // passes the result. |
| 41 // |
33 // Note on callbacks: Because all the functions here are meant to be | 42 // Note on callbacks: Because all the functions here are meant to be |
34 // asynchronous, they all take a |callback| of some type, and an | 43 // asynchronous, they all take a |callback| of some type, and an |
35 // |error_callback|. When the operation succeeds, |callback| will be called, and | 44 // |error_callback|. When the operation succeeds, |callback| will be called, and |
36 // when it doesn't, |error_callback| will be called with information about the | 45 // when it doesn't, |error_callback| will be called with information about the |
37 // error, including a symbolic name for the error and often some error message | 46 // error, including a symbolic name for the error and often some error message |
38 // that is suitable for logging. None of the error message text is meant for | 47 // that is suitable for logging. None of the error message text is meant for |
39 // user consumption. | 48 // user consumption. |
40 | 49 |
41 class CHROMEOS_EXPORT NetworkConfigurationHandler { | 50 class CHROMEOS_EXPORT ManagedNetworkConfigurationHandler { |
42 public: | 51 public: |
43 ~NetworkConfigurationHandler(); | 52 // Initialize the singleton. |
44 | |
45 // Sets the global instance. Must be called before any calls to Get(). | |
46 static void Initialize(); | 53 static void Initialize(); |
47 | 54 |
48 // Destroys the global instance. | 55 // Destroy the singleton. |
49 static void Shutdown(); | 56 static void Shutdown(); |
50 | 57 |
51 // Gets the global instance. Initialize() must be called first. | 58 // Initialize must be called before this. |
52 static NetworkConfigurationHandler* Get(); | 59 static ManagedNetworkConfigurationHandler* Get(); |
53 | 60 |
54 // Gets the properties of the network with id |service_path|. See note on | 61 // Gets the properties of the network with id |guid|. See note on |
55 // |callback| and |error_callback|, in class description above. | 62 // |callback| and |error_callback|, in class description above. |
56 void GetProperties( | 63 void GetProperties( |
57 const std::string& service_path, | 64 const std::string& guid, |
58 const network_handler::DictionaryResultCallback& callback, | 65 const network_handler::DictionaryResultCallback& callback, |
59 const network_handler::ErrorCallback& error_callback) const; | 66 const network_handler::ErrorCallback& error_callback) const; |
60 | 67 |
61 // Sets the properties of the network with id |service_path|. This means the | 68 // Sets the properties of the network with id |guid|. This means the |
62 // given properties will be merged with the existing settings, and it won't | 69 // given properties will be merged with the existing settings, and it won't |
63 // clear any existing properties. See note on |callback| and |error_callback|, | 70 // clear any existing properties. See note on |callback| and |error_callback|, |
64 // in class description above. | 71 // in class description above. |
65 void SetProperties( | 72 void SetProperties( |
66 const std::string& service_path, | 73 const std::string& guid, |
67 const base::DictionaryValue& properties, | 74 const base::DictionaryValue& properties, |
68 const base::Closure& callback, | 75 const base::Closure& callback, |
69 const network_handler::ErrorCallback& error_callback) const; | 76 const network_handler::ErrorCallback& error_callback) const; |
70 | 77 |
71 // Removes the properties with the given property paths. If any of them are | 78 // Removes the properties with the given property paths. If any of them are |
72 // unable to be cleared, the |error_callback| will only be run once with | 79 // unable to be cleared, the |error_callback| will only be run once with |
73 // accumulated information about all of the errors as a list attached to the | 80 // accumulated information about all of the errors as a list attached to the |
74 // "errors" key of the error data, and the |callback| will not be run, even | 81 // "errors" key of the error data, and the |callback| will not be run, even |
75 // though some of the properties may have been cleared. If there are no | 82 // though some of the properties may have been cleared. If there are no |
76 // errors, |callback| will be run. | 83 // errors, |callback| will be run. |
77 void ClearProperties(const std::string& service_path, | 84 void ClearProperties(const std::string& guid, |
78 const std::vector<std::string>& property_paths, | 85 const std::vector<std::string>& property_paths, |
79 const base::Closure& callback, | 86 const base::Closure& callback, |
80 const network_handler::ErrorCallback& error_callback); | 87 const network_handler::ErrorCallback& error_callback); |
81 | 88 |
82 // Initiates a connection with network that has id |service_path|. See note on | 89 // Initiates a connection with network that has id |guid|. See note on |
83 // |callback| and |error_callback|, in class description above. | 90 // |callback| and |error_callback|, in class description above. |
84 void Connect(const std::string& service_path, | 91 void Connect(const std::string& guid, |
85 const base::Closure& callback, | 92 const base::Closure& callback, |
86 const network_handler::ErrorCallback& error_callback) const; | 93 const network_handler::ErrorCallback& error_callback) const; |
87 | 94 |
88 // Initiates a disconnect with the network at |service_path|. See note on | 95 // Initiates a disconnect with the network at |guid|. See note on |
89 // |callback| and |error_callback|, in class description above. | 96 // |callback| and |error_callback|, in class description above. |
90 void Disconnect(const std::string& service_path, | 97 void Disconnect(const std::string& guid, |
91 const base::Closure& callback, | 98 const base::Closure& callback, |
92 const network_handler::ErrorCallback& error_callback) const; | 99 const network_handler::ErrorCallback& error_callback) const; |
93 | 100 |
94 | 101 |
95 // Creates a network with the given properties in the active Shill profile, | 102 // Creates a network with the given properties in the active Shill profile, |
96 // and returns the properties to |callback| if successful, along with the new | 103 // and returns the new GUID to |callback| if successful. See note on |
97 // service_path. See note on |callback| and |error_callback|, in class | 104 // |callback| and |error_callback|, in class description above. |
98 // description above. | |
99 void CreateConfiguration( | 105 void CreateConfiguration( |
100 const base::DictionaryValue& properties, | 106 const base::DictionaryValue& properties, |
101 const network_handler::StringResultCallback& callback, | 107 const network_handler::StringResultCallback& callback, |
102 const network_handler::ErrorCallback& error_callback) const; | 108 const network_handler::ErrorCallback& error_callback) const; |
103 | 109 |
104 // Removes the network |service_path| from the remembered network list in the | 110 // Removes the network |guid| from the remembered network list in the |
105 // active Shill profile. The network may still show up in the visible networks | 111 // active Shill profile. The network may still show up in the visible networks |
106 // after this, but no profile configuration will remain. See note on | 112 // after this, but no profile configuration will remain. See note on |
107 // |callback| and |error_callback|, in class description above. | 113 // |callback| and |error_callback|, in class description above. |
108 void RemoveConfiguration( | 114 void RemoveConfiguration( |
109 const std::string& service_path, | 115 const std::string& guid, |
110 const base::Closure& callback, | 116 const base::Closure& callback, |
111 const network_handler::ErrorCallback& error_callback) const; | 117 const network_handler::ErrorCallback& error_callback) const; |
112 | 118 |
113 private: | 119 private: |
114 friend class NetworkConfigurationHandlerTest; | 120 ManagedNetworkConfigurationHandler(); |
115 NetworkConfigurationHandler(); | 121 ~ManagedNetworkConfigurationHandler(); |
116 | 122 |
117 DISALLOW_COPY_AND_ASSIGN(NetworkConfigurationHandler); | 123 DISALLOW_COPY_AND_ASSIGN(ManagedNetworkConfigurationHandler); |
118 }; | 124 }; |
119 | 125 |
120 } // namespace chromeos | 126 } // namespace chromeos |
121 | 127 |
122 #endif // CHROMEOS_NETWORK_NETWORK_CONFIGURATION_HANDLER_H_ | 128 #endif // CHROMEOS_NETWORK_MANAGED_NETWORK_CONFIGURATION_HANDLER_H_ |
OLD | NEW |