Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/net/managed_network_configuration_handler.h" | |
| 6 | |
| 7 #include <string> | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/bind.h" | |
| 11 #include "base/guid.h" | |
| 12 #include "base/logging.h" | |
| 13 #include "base/memory/ref_counted.h" | |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/values.h" | |
| 16 #include "chromeos/dbus/dbus_method_call_status.h" | |
| 17 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 18 #include "chromeos/dbus/shill_manager_client.h" | |
| 19 #include "chromeos/dbus/shill_service_client.h" | |
| 20 #include "chromeos/network/network_configuration_handler.h" | |
| 21 #include "chromeos/network/network_state.h" | |
| 22 #include "chromeos/network/network_state_handler.h" | |
| 23 #include "chromeos/network/onc/onc_constants.h" | |
| 24 #include "chromeos/network/onc/onc_signature.h" | |
| 25 #include "chromeos/network/onc/onc_translator.h" | |
| 26 #include "dbus/object_path.h" | |
| 27 #include "third_party/cros_system_api/dbus/service_constants.h" | |
| 28 | |
| 29 namespace chromeos { | |
| 30 | |
| 31 namespace { | |
| 32 | |
| 33 ManagedNetworkConfigurationHandler* g_configuration_handler_instance = NULL; | |
| 34 | |
| 35 const char kErrorMessage[] = "errorMessage"; | |
| 36 const char kErrorName[] = "errorName"; | |
| 37 const char kServicePath[] = "servicePath"; | |
| 38 const char kSetOnUnconfiguredNetworkMessage[] = | |
| 39 "Unable to modify properties of an unconfigured network."; | |
| 40 const char kSetOnUnconfiguredNetwork[] = "Error.SetCalledOnUnconfiguredNetwork"; | |
| 41 const char kUnknownServicePathMessage[] = "Service path is unknown."; | |
| 42 const char kUnknownServicePath[] = "Error.UnknownServicePath"; | |
| 43 | |
| 44 void RunErrorCallback(const std::string& service_path, | |
| 45 const std::string& error_name, | |
| 46 const std::string& error_message, | |
| 47 const network_handler::ErrorCallback& error_callback) { | |
| 48 error_callback.Run( | |
| 49 error_name, | |
| 50 make_scoped_ptr( | |
| 51 network_handler::CreateErrorData(service_path, | |
| 52 error_name, | |
| 53 error_message))); | |
| 54 } | |
| 55 | |
| 56 void TranslatePropertiesAndRunCallback( | |
| 57 const network_handler::DictionaryResultCallback& callback, | |
| 58 const std::string& service_path, | |
| 59 const base::DictionaryValue& shill_properties) { | |
| 60 scoped_ptr<base::DictionaryValue> onc_network( | |
| 61 onc::TranslateShillServiceToONCPart( | |
| 62 shill_properties, | |
| 63 &onc::kNetworkConfigurationSignature)); | |
| 64 callback.Run(service_path, *onc_network); | |
| 65 } | |
| 66 | |
| 67 } // namespace | |
| 68 | |
| 69 // static | |
| 70 void ManagedNetworkConfigurationHandler::Initialize() { | |
| 71 CHECK(!g_configuration_handler_instance); | |
| 72 g_configuration_handler_instance = new ManagedNetworkConfigurationHandler; | |
| 73 } | |
| 74 | |
| 75 // static | |
| 76 bool ManagedNetworkConfigurationHandler::IsInitialized() { | |
| 77 return g_configuration_handler_instance; | |
| 78 } | |
| 79 | |
| 80 // static | |
| 81 void ManagedNetworkConfigurationHandler::Shutdown() { | |
| 82 CHECK(g_configuration_handler_instance); | |
| 83 delete g_configuration_handler_instance; | |
| 84 g_configuration_handler_instance = NULL; | |
| 85 } | |
| 86 | |
| 87 // static | |
| 88 ManagedNetworkConfigurationHandler* ManagedNetworkConfigurationHandler::Get() { | |
| 89 CHECK(g_configuration_handler_instance); | |
| 90 return g_configuration_handler_instance; | |
| 91 } | |
| 92 | |
| 93 void ManagedNetworkConfigurationHandler::GetProperties( | |
| 94 const std::string& id, | |
| 95 const network_handler::DictionaryResultCallback& callback, | |
| 96 const network_handler::ErrorCallback& error_callback) const { | |
| 97 // TODO(pneubeck): Merging! | |
| 98 NetworkConfigurationHandler::Get()->GetProperties( | |
| 99 id, // service path | |
| 100 base::Bind(&TranslatePropertiesAndRunCallback, callback), | |
| 101 error_callback); | |
| 102 } | |
| 103 | |
| 104 void ManagedNetworkConfigurationHandler::SetProperties( | |
| 105 const std::string& id, | |
| 106 const base::DictionaryValue& properties, | |
| 107 const base::Closure& callback, | |
| 108 const network_handler::ErrorCallback& error_callback) const { | |
| 109 const NetworkState* state = | |
| 110 NetworkStateHandler::Get()->GetNetworkState(id /*service path*/); | |
| 111 | |
| 112 if (!state) { | |
| 113 RunErrorCallback(id, // service path | |
| 114 kUnknownServicePath, | |
| 115 kUnknownServicePathMessage, | |
| 116 error_callback); | |
| 117 } | |
| 118 std::string guid = state->guid(); | |
| 119 if (guid.empty()) { | |
| 120 RunErrorCallback(id, // service path | |
| 121 kSetOnUnconfiguredNetwork, | |
| 122 kSetOnUnconfiguredNetworkMessage, | |
| 123 error_callback); | |
| 124 } | |
| 125 | |
| 126 std::string newGuid; | |
| 127 properties.GetStringWithoutPathExpansion(onc::network_config::kGUID, | |
| 128 &newGuid); | |
| 129 | |
| 130 DCHECK(guid == newGuid); // TODO(pneubeck): Handle the other case, too. | |
|
Greg Spencer (Chromium)
2013/02/19 22:58:26
Can you say what the "other case" is in the commen
pneubeck (no reviews)
2013/02/22 10:22:31
Actually, I think, the ManagedNetworkConfiguration
| |
| 131 | |
| 132 // TODO(pneubeck): Merging! | |
| 133 | |
| 134 scoped_ptr<base::DictionaryValue> shill_dictionary( | |
| 135 onc::TranslateONCObjectToShill( | |
| 136 &onc::kNetworkConfigurationSignature, | |
| 137 properties)); | |
| 138 | |
| 139 NetworkConfigurationHandler::Get()->SetProperties(id, // service path | |
| 140 *shill_dictionary, | |
| 141 callback, | |
| 142 error_callback); | |
| 143 } | |
| 144 | |
| 145 void ManagedNetworkConfigurationHandler::Connect( | |
| 146 const std::string& id, | |
| 147 const base::Closure& callback, | |
| 148 const network_handler::ErrorCallback& error_callback) const { | |
| 149 // TODO(pneubeck): Update user profile if necessary. | |
| 150 NetworkConfigurationHandler::Get()->Connect(id, // service path | |
| 151 callback, | |
| 152 error_callback); | |
| 153 } | |
| 154 | |
| 155 void ManagedNetworkConfigurationHandler::Disconnect( | |
| 156 const std::string& id, | |
| 157 const base::Closure& callback, | |
| 158 const network_handler::ErrorCallback& error_callback) const { | |
| 159 NetworkConfigurationHandler::Get()->Disconnect(id, // service path | |
| 160 callback, | |
| 161 error_callback); | |
| 162 } | |
| 163 | |
| 164 void ManagedNetworkConfigurationHandler::CreateConfiguration( | |
| 165 const base::DictionaryValue& properties, | |
| 166 const network_handler::StringResultCallback& callback, | |
| 167 const network_handler::ErrorCallback& error_callback) const { | |
| 168 scoped_ptr<base::DictionaryValue> modified_properties( | |
| 169 properties.DeepCopy()); | |
| 170 | |
| 171 // If there isn't already a GUID attached to these properties, then | |
| 172 // generate one and add it. | |
| 173 std::string guid; | |
| 174 if (!properties.GetString(onc::network_config::kGUID, &guid)) { | |
| 175 guid = base::GenerateGUID(); | |
| 176 modified_properties->SetStringWithoutPathExpansion( | |
| 177 onc::network_config::kGUID, guid); | |
| 178 } else { | |
| 179 NOTREACHED(); // TODO(pneubeck): Handle this case, too. | |
| 180 } | |
| 181 | |
| 182 // TODO(pneubeck): Merging! | |
| 183 | |
| 184 scoped_ptr<base::DictionaryValue> shill_dictionary( | |
| 185 onc::TranslateONCObjectToShill(&onc::kNetworkConfigurationSignature, | |
| 186 properties)); | |
| 187 | |
| 188 NetworkConfigurationHandler::Get()->CreateConfiguration(*shill_dictionary, | |
| 189 callback, | |
| 190 error_callback); | |
| 191 } | |
| 192 | |
| 193 void ManagedNetworkConfigurationHandler::RemoveConfiguration( | |
| 194 const std::string& id, | |
| 195 const base::Closure& callback, | |
| 196 const network_handler::ErrorCallback& error_callback) const { | |
| 197 NetworkConfigurationHandler::Get()->RemoveConfiguration(id, // service path | |
| 198 callback, | |
| 199 error_callback); | |
| 200 } | |
| 201 | |
| 202 ManagedNetworkConfigurationHandler::ManagedNetworkConfigurationHandler() { | |
| 203 } | |
| 204 | |
| 205 ManagedNetworkConfigurationHandler::~ManagedNetworkConfigurationHandler() { | |
| 206 } | |
| 207 | |
| 208 } // namespace chromeos | |
| OLD | NEW |