Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
|
gauravsh
2013/02/26 21:25:03
NIT: 2013
pneubeck (no reviews)
2013/02/27 09:49:25
Done.
| |
| 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"; | |
|
gauravsh
2013/02/26 21:25:03
You should add a comment that these are error name
pneubeck (no reviews)
2013/02/27 09:49:25
Done.
| |
| 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) { | |
|
stevenjb
2013/02/26 17:31:24
Can we add a network_event_log event here?
pneubeck (no reviews)
2013/02/27 09:49:25
Done.
| |
| 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& service_path, | |
| 95 const network_handler::DictionaryResultCallback& callback, | |
| 96 const network_handler::ErrorCallback& error_callback) const { | |
| 97 // TODO(pneubeck): Merging! | |
|
stevenjb
2013/02/26 17:31:24
Clarify?
pneubeck (no reviews)
2013/02/27 09:49:25
Done.
| |
| 98 NetworkConfigurationHandler::Get()->GetProperties( | |
| 99 service_path, | |
| 100 base::Bind(&TranslatePropertiesAndRunCallback, callback), | |
| 101 error_callback); | |
| 102 } | |
| 103 | |
| 104 void ManagedNetworkConfigurationHandler::SetProperties( | |
| 105 const std::string& service_path, | |
| 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(service_path); | |
| 111 | |
| 112 if (!state) { | |
| 113 RunErrorCallback(service_path, | |
| 114 kUnknownServicePath, | |
| 115 kUnknownServicePathMessage, | |
| 116 error_callback); | |
| 117 } | |
| 118 std::string guid = state->guid(); | |
| 119 if (guid.empty()) { | |
| 120 RunErrorCallback(service_path, | |
| 121 kSetOnUnconfiguredNetwork, | |
| 122 kSetOnUnconfiguredNetworkMessage, | |
| 123 error_callback); | |
| 124 } | |
| 125 | |
| 126 // TODO(pneubeck): Merging! | |
|
stevenjb
2013/02/26 17:31:24
ditto. I assume you mean 'merge properties'?
pneubeck (no reviews)
2013/02/27 09:49:25
Done.
| |
| 127 | |
| 128 scoped_ptr<base::DictionaryValue> shill_dictionary( | |
| 129 onc::TranslateONCObjectToShill( | |
| 130 &onc::kNetworkConfigurationSignature, | |
| 131 properties)); | |
| 132 | |
| 133 NetworkConfigurationHandler::Get()->SetProperties(service_path, | |
| 134 *shill_dictionary, | |
| 135 callback, | |
| 136 error_callback); | |
| 137 } | |
| 138 | |
| 139 void ManagedNetworkConfigurationHandler::Connect( | |
| 140 const std::string& service_path, | |
| 141 const base::Closure& callback, | |
| 142 const network_handler::ErrorCallback& error_callback) const { | |
| 143 // TODO(pneubeck): Update user profile if necessary. | |
| 144 NetworkConfigurationHandler::Get()->Connect(service_path, | |
| 145 callback, | |
| 146 error_callback); | |
| 147 } | |
| 148 | |
| 149 void ManagedNetworkConfigurationHandler::Disconnect( | |
| 150 const std::string& service_path, | |
| 151 const base::Closure& callback, | |
| 152 const network_handler::ErrorCallback& error_callback) const { | |
| 153 NetworkConfigurationHandler::Get()->Disconnect(service_path, | |
| 154 callback, | |
| 155 error_callback); | |
| 156 } | |
| 157 | |
| 158 void ManagedNetworkConfigurationHandler::CreateConfiguration( | |
| 159 const base::DictionaryValue& properties, | |
| 160 const network_handler::StringResultCallback& callback, | |
| 161 const network_handler::ErrorCallback& error_callback) const { | |
| 162 scoped_ptr<base::DictionaryValue> modified_properties( | |
| 163 properties.DeepCopy()); | |
| 164 | |
| 165 // If there isn't already a GUID attached to these properties, then | |
| 166 // generate one and add it. | |
| 167 std::string guid; | |
| 168 if (!properties.GetString(onc::network_config::kGUID, &guid)) { | |
| 169 guid = base::GenerateGUID(); | |
| 170 modified_properties->SetStringWithoutPathExpansion( | |
| 171 onc::network_config::kGUID, guid); | |
| 172 } else { | |
| 173 NOTREACHED(); // TODO(pneubeck): Handle this case, too. | |
| 174 } | |
| 175 | |
| 176 // TODO(pneubeck): Merging! | |
|
stevenjb
2013/02/26 17:31:24
ditto
pneubeck (no reviews)
2013/02/27 09:49:25
Done.
| |
| 177 | |
| 178 scoped_ptr<base::DictionaryValue> shill_dictionary( | |
| 179 onc::TranslateONCObjectToShill(&onc::kNetworkConfigurationSignature, | |
| 180 properties)); | |
| 181 | |
| 182 NetworkConfigurationHandler::Get()->CreateConfiguration(*shill_dictionary, | |
| 183 callback, | |
| 184 error_callback); | |
| 185 } | |
| 186 | |
| 187 void ManagedNetworkConfigurationHandler::RemoveConfiguration( | |
| 188 const std::string& service_path, | |
| 189 const base::Closure& callback, | |
| 190 const network_handler::ErrorCallback& error_callback) const { | |
| 191 NetworkConfigurationHandler::Get()->RemoveConfiguration(service_path, | |
| 192 callback, | |
| 193 error_callback); | |
| 194 } | |
| 195 | |
| 196 ManagedNetworkConfigurationHandler::ManagedNetworkConfigurationHandler() { | |
| 197 } | |
| 198 | |
| 199 ManagedNetworkConfigurationHandler::~ManagedNetworkConfigurationHandler() { | |
| 200 } | |
| 201 | |
| 202 } // namespace chromeos | |
| OLD | NEW |