Index: chrome/browser/chromeos/net/managed_network_configuration_handler.cc |
diff --git a/chrome/browser/chromeos/net/managed_network_configuration_handler.cc b/chrome/browser/chromeos/net/managed_network_configuration_handler.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ad3d5bf6d6a2f6c66b473258fc1d0534231c4c7b |
--- /dev/null |
+++ b/chrome/browser/chromeos/net/managed_network_configuration_handler.cc |
@@ -0,0 +1,202 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/chromeos/net/managed_network_configuration_handler.h" |
+ |
+#include <string> |
+#include <vector> |
+ |
+#include "base/bind.h" |
+#include "base/guid.h" |
+#include "base/logging.h" |
+#include "base/memory/ref_counted.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/values.h" |
+#include "chromeos/dbus/dbus_method_call_status.h" |
+#include "chromeos/dbus/dbus_thread_manager.h" |
+#include "chromeos/dbus/shill_manager_client.h" |
+#include "chromeos/dbus/shill_service_client.h" |
+#include "chromeos/network/network_configuration_handler.h" |
+#include "chromeos/network/network_state.h" |
+#include "chromeos/network/network_state_handler.h" |
+#include "chromeos/network/onc/onc_constants.h" |
+#include "chromeos/network/onc/onc_signature.h" |
+#include "chromeos/network/onc/onc_translator.h" |
+#include "dbus/object_path.h" |
+#include "third_party/cros_system_api/dbus/service_constants.h" |
+ |
+namespace chromeos { |
+ |
+namespace { |
+ |
+ManagedNetworkConfigurationHandler* g_configuration_handler_instance = NULL; |
+ |
+const char kErrorMessage[] = "errorMessage"; |
+const char kErrorName[] = "errorName"; |
+const char kServicePath[] = "servicePath"; |
+const char kSetOnUnconfiguredNetworkMessage[] = |
+ "Unable to modify properties of an unconfigured network."; |
+const char kSetOnUnconfiguredNetwork[] = "Error.SetCalledOnUnconfiguredNetwork"; |
+const char kUnknownServicePathMessage[] = "Service path is unknown."; |
+const char kUnknownServicePath[] = "Error.UnknownServicePath"; |
+ |
+void RunErrorCallback(const std::string& service_path, |
+ const std::string& error_name, |
+ const std::string& error_message, |
+ const network_handler::ErrorCallback& error_callback) { |
+ error_callback.Run( |
+ error_name, |
+ make_scoped_ptr( |
+ network_handler::CreateErrorData(service_path, |
+ error_name, |
+ error_message))); |
+} |
+ |
+void TranslatePropertiesAndRunCallback( |
+ const network_handler::DictionaryResultCallback& callback, |
+ const std::string& service_path, |
+ const base::DictionaryValue& shill_properties) { |
+ scoped_ptr<base::DictionaryValue> onc_network( |
+ onc::TranslateShillServiceToONCPart( |
+ shill_properties, |
+ &onc::kNetworkConfigurationSignature)); |
+ callback.Run(service_path, *onc_network); |
+} |
+ |
+} // namespace |
+ |
+// static |
+void ManagedNetworkConfigurationHandler::Initialize() { |
+ CHECK(!g_configuration_handler_instance); |
+ g_configuration_handler_instance = new ManagedNetworkConfigurationHandler; |
+} |
+ |
+// static |
+bool ManagedNetworkConfigurationHandler::IsInitialized() { |
+ return g_configuration_handler_instance; |
+} |
+ |
+// static |
+void ManagedNetworkConfigurationHandler::Shutdown() { |
+ CHECK(g_configuration_handler_instance); |
+ delete g_configuration_handler_instance; |
+ g_configuration_handler_instance = NULL; |
+} |
+ |
+// static |
+ManagedNetworkConfigurationHandler* ManagedNetworkConfigurationHandler::Get() { |
+ CHECK(g_configuration_handler_instance); |
+ return g_configuration_handler_instance; |
+} |
+ |
+void ManagedNetworkConfigurationHandler::GetProperties( |
+ const std::string& id, |
+ const network_handler::DictionaryResultCallback& callback, |
+ const network_handler::ErrorCallback& error_callback) const { |
+ // TODO(pneubeck): Merging! |
+ NetworkConfigurationHandler::Get()->GetProperties( |
+ id, // service path |
+ base::Bind(&TranslatePropertiesAndRunCallback, callback), |
+ error_callback); |
+} |
+ |
+void ManagedNetworkConfigurationHandler::SetProperties( |
+ const std::string& id, |
+ const base::DictionaryValue& properties, |
+ const base::Closure& callback, |
+ const network_handler::ErrorCallback& error_callback) const { |
+ const NetworkState* state = |
+ NetworkStateHandler::Get()->GetNetworkState(id /*service path*/); |
+ |
+ if (!state) { |
+ RunErrorCallback(id, // service path |
+ kUnknownServicePath, |
+ kUnknownServicePathMessage, |
+ error_callback); |
+ } |
+ std::string guid = state->guid(); |
+ if (guid.empty()) { |
+ RunErrorCallback(id, // service path |
+ kSetOnUnconfiguredNetwork, |
+ kSetOnUnconfiguredNetworkMessage, |
+ error_callback); |
+ } |
+ |
+ // TODO(pneubeck): Merging! |
+ |
+ scoped_ptr<base::DictionaryValue> shill_dictionary( |
+ onc::TranslateONCObjectToShill( |
+ &onc::kNetworkConfigurationSignature, |
+ properties)); |
+ |
+ NetworkConfigurationHandler::Get()->SetProperties(id, // service path |
+ *shill_dictionary, |
+ callback, |
+ error_callback); |
+} |
+ |
+void ManagedNetworkConfigurationHandler::Connect( |
+ const std::string& id, |
+ const base::Closure& callback, |
+ const network_handler::ErrorCallback& error_callback) const { |
+ // TODO(pneubeck): Update user profile if necessary. |
+ NetworkConfigurationHandler::Get()->Connect(id, // service path |
+ callback, |
+ error_callback); |
+} |
+ |
+void ManagedNetworkConfigurationHandler::Disconnect( |
+ const std::string& id, |
+ const base::Closure& callback, |
+ const network_handler::ErrorCallback& error_callback) const { |
+ NetworkConfigurationHandler::Get()->Disconnect(id, // service path |
+ callback, |
+ error_callback); |
+} |
+ |
+void ManagedNetworkConfigurationHandler::CreateConfiguration( |
+ const base::DictionaryValue& properties, |
+ const network_handler::StringResultCallback& callback, |
+ const network_handler::ErrorCallback& error_callback) const { |
+ scoped_ptr<base::DictionaryValue> modified_properties( |
+ properties.DeepCopy()); |
+ |
+ // If there isn't already a GUID attached to these properties, then |
+ // generate one and add it. |
+ std::string guid; |
+ if (!properties.GetString(onc::network_config::kGUID, &guid)) { |
+ guid = base::GenerateGUID(); |
+ modified_properties->SetStringWithoutPathExpansion( |
+ onc::network_config::kGUID, guid); |
+ } else { |
+ NOTREACHED(); // TODO(pneubeck): Handle this case, too. |
+ } |
+ |
+ // TODO(pneubeck): Merging! |
+ |
+ scoped_ptr<base::DictionaryValue> shill_dictionary( |
+ onc::TranslateONCObjectToShill(&onc::kNetworkConfigurationSignature, |
+ properties)); |
+ |
+ NetworkConfigurationHandler::Get()->CreateConfiguration(*shill_dictionary, |
+ callback, |
+ error_callback); |
+} |
+ |
+void ManagedNetworkConfigurationHandler::RemoveConfiguration( |
+ const std::string& id, |
+ const base::Closure& callback, |
+ const network_handler::ErrorCallback& error_callback) const { |
+ NetworkConfigurationHandler::Get()->RemoveConfiguration(id, // service path |
+ callback, |
+ error_callback); |
+} |
+ |
+ManagedNetworkConfigurationHandler::ManagedNetworkConfigurationHandler() { |
+} |
+ |
+ManagedNetworkConfigurationHandler::~ManagedNetworkConfigurationHandler() { |
+} |
+ |
+} // namespace chromeos |