From 437a9f8fd20379f3314d1f515dca115dac0aaaaf Mon Sep 17 00:00:00 2001 From: "stevenjb@chromium.org" Date: Tue, 28 May 2013 18:33:30 +0000 Subject: Add NetworkHandler to own network handlers in src/chromeos/network This is just some code cleanup and should have no behavior changes. BUG=239073 For webui/chromeos, browser/geolocation: TBR=nkostylev@chromium.org,joth@chromium.org Review URL: https://chromiumcodereview.appspot.com/14729017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@202609 0039d316-1c4b-4281-b951-d872f2087c98 --- chromeos/network/network_configuration_handler.cc | 70 +++++++++++------------ 1 file changed, 32 insertions(+), 38 deletions(-) (limited to 'chromeos/network/network_configuration_handler.cc') diff --git a/chromeos/network/network_configuration_handler.cc b/chromeos/network/network_configuration_handler.cc index 91c87a0..903e606 100644 --- a/chromeos/network/network_configuration_handler.cc +++ b/chromeos/network/network_configuration_handler.cc @@ -24,8 +24,6 @@ namespace chromeos { namespace { -NetworkConfigurationHandler* g_configuration_handler_instance = NULL; - // None of these error messages are user-facing: they should only appear in // logs. const char kErrorsListTag[] = "errors"; @@ -93,17 +91,6 @@ void RunCallbackWithDictionaryValue( } } -void RunCreateNetworkCallback( - const network_handler::StringResultCallback& callback, - const dbus::ObjectPath& service_path) { - callback.Run(service_path.value()); - // This may also get called when CreateConfiguration is used to update an - // existing configuration, so request a service update just in case. - // TODO(pneubeck): Separate 'Create' and 'Update' calls and only trigger - // this on an update. - NetworkStateHandler::Get()->RequestUpdateForNetwork(service_path.value()); -} - void IgnoreObjectPathCallback(const base::Closure& callback, const dbus::ObjectPath& object_path) { callback.Run(); @@ -111,26 +98,6 @@ void IgnoreObjectPathCallback(const base::Closure& callback, } // namespace -// static -void NetworkConfigurationHandler::Initialize() { - CHECK(!g_configuration_handler_instance); - g_configuration_handler_instance = new NetworkConfigurationHandler; -} - -// static -void NetworkConfigurationHandler::Shutdown() { - CHECK(g_configuration_handler_instance); - delete g_configuration_handler_instance; - g_configuration_handler_instance = NULL; -} - -// static -NetworkConfigurationHandler* NetworkConfigurationHandler::Get() { - CHECK(g_configuration_handler_instance) - << "NetworkConfigurationHandler::Get() called before Initialize()"; - return g_configuration_handler_instance; -} - void NetworkConfigurationHandler::GetProperties( const std::string& service_path, const network_handler::DictionaryResultCallback& callback, @@ -153,7 +120,7 @@ void NetworkConfigurationHandler::SetProperties( base::Bind(&IgnoreObjectPathCallback, callback), base::Bind(&network_handler::ShillErrorCallbackFunction, service_path, error_callback)); - NetworkStateHandler::Get()->RequestUpdateForNetwork(service_path); + network_state_handler_->RequestUpdateForNetwork(service_path); } void NetworkConfigurationHandler::ClearProperties( @@ -176,7 +143,7 @@ void NetworkConfigurationHandler::ClearProperties( void NetworkConfigurationHandler::CreateConfiguration( const base::DictionaryValue& properties, const network_handler::StringResultCallback& callback, - const network_handler::ErrorCallback& error_callback) const { + const network_handler::ErrorCallback& error_callback) { ShillManagerClient* manager = DBusThreadManager::Get()->GetShillManagerClient(); @@ -193,13 +160,15 @@ void NetworkConfigurationHandler::CreateConfiguration( manager->ConfigureServiceForProfile( dbus::ObjectPath(profile), properties, - base::Bind(&RunCreateNetworkCallback, callback), + base::Bind(&NetworkConfigurationHandler::RunCreateNetworkCallback, + AsWeakPtr(), callback), base::Bind(&network_handler::ShillErrorCallbackFunction, "", error_callback)); } else { manager->GetService( properties, - base::Bind(&RunCreateNetworkCallback, callback), + base::Bind(&NetworkConfigurationHandler::RunCreateNetworkCallback, + AsWeakPtr(), callback), base::Bind(&network_handler::ShillErrorCallbackFunction, "", error_callback)); } @@ -216,10 +185,35 @@ void NetworkConfigurationHandler::RemoveConfiguration( service_path, error_callback)); } -NetworkConfigurationHandler::NetworkConfigurationHandler() { +NetworkConfigurationHandler::NetworkConfigurationHandler() + : network_state_handler_(NULL) { } NetworkConfigurationHandler::~NetworkConfigurationHandler() { } +void NetworkConfigurationHandler::Init( + NetworkStateHandler* network_state_handler) { + network_state_handler_ = network_state_handler; +} + +void NetworkConfigurationHandler::RunCreateNetworkCallback( + const network_handler::StringResultCallback& callback, + const dbus::ObjectPath& service_path) { + callback.Run(service_path.value()); + // This may also get called when CreateConfiguration is used to update an + // existing configuration, so request a service update just in case. + // TODO(pneubeck): Separate 'Create' and 'Update' calls and only trigger + // this on an update. + network_state_handler_->RequestUpdateForNetwork(service_path.value()); +} + +// static +NetworkConfigurationHandler* NetworkConfigurationHandler::InitializeForTest( + NetworkStateHandler* network_state_handler) { + NetworkConfigurationHandler* handler = new NetworkConfigurationHandler(); + handler->Init(network_state_handler); + return handler; +} + } // namespace chromeos -- cgit v1.1