Chromium Code Reviews| Index: chrome/browser/chromeos/net/proxy_config_handler.cc |
| diff --git a/chrome/browser/chromeos/net/proxy_config_handler.cc b/chrome/browser/chromeos/net/proxy_config_handler.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..22bfb8402b700ed74985f4e9f2db81d605049146 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/net/proxy_config_handler.cc |
| @@ -0,0 +1,73 @@ |
| +// Copyright (c) 2013 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/proxy_config_handler.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/json/json_writer.h" |
| +#include "base/logging.h" |
| +#include "base/values.h" |
| +#include "chrome/browser/prefs/proxy_config_dictionary.h" |
| +#include "chromeos/dbus/dbus_thread_manager.h" |
| +#include "chromeos/dbus/shill_service_client.h" |
| +#include "chromeos/network/network_state.h" |
| +#include "chromeos/network/network_state_handler.h" |
| +#include "dbus/object_path.h" |
| +#include "third_party/cros_system_api/dbus/service_constants.h" |
| + |
| +namespace { |
| + |
| +void LogError(const std::string& error_name, |
| + const std::string& error_message) { |
| + LOG(ERROR) << "Could not clear or set ProxyConfig: " << error_message; |
|
stevenjb
2013/06/06 18:21:12
Could you use network_handler::ShillErrorCallbackF
pneubeck (no reviews)
2013/06/07 09:46:10
Done.
|
| +} |
| + |
| +} // namespace |
| + |
| +namespace chromeos { |
| + |
| +namespace proxy_config { |
| + |
| +scoped_ptr<ProxyConfigDictionary> GetProxyConfigOfNetwork( |
| + const NetworkState& network) { |
| + const base::DictionaryValue& value = network.proxy_config(); |
| + if (value.empty()) |
| + return scoped_ptr<ProxyConfigDictionary>(); |
| + return make_scoped_ptr(new ProxyConfigDictionary(&value)); |
| +} |
| + |
| +void SetProxyConfigOfNetwork(const ProxyConfigDictionary& proxy_config, |
| + const NetworkState& network) { |
| + chromeos::ShillServiceClient* shill_service_client = |
| + DBusThreadManager::Get()->GetShillServiceClient(); |
| + |
| + ProxyPrefs::ProxyMode mode; |
| + if (!proxy_config.GetMode(&mode) || mode == ProxyPrefs::MODE_DIRECT) { |
| + // TODO(pneubeck): Consider removing this legacy code. Return empty string |
| + // for direct mode for portal check to work correctly. |
| + shill_service_client->ClearProperty( |
| + dbus::ObjectPath(network.path()), |
| + flimflam::kProxyConfigProperty, |
| + base::Bind(&base::DoNothing), |
| + base::Bind(&LogError)); |
| + } else { |
| + std::string proxy_config_str; |
| + base::JSONWriter::Write(&proxy_config.GetDictionary(), &proxy_config_str); |
| + shill_service_client->SetProperty( |
| + dbus::ObjectPath(network.path()), |
| + flimflam::kProxyConfigProperty, |
| + base::StringValue(proxy_config_str), |
| + base::Bind(&base::DoNothing), |
| + base::Bind(&LogError)); |
| + } |
| + |
| + if (NetworkHandler::IsInitialized()) { |
| + NetworkHandler::Get()->network_state_handler()-> |
| + RequestUpdateForNetwork(network.path()); |
| + } |
| +} |
| + |
| +} // namespace proxy_config |
| + |
| +} // namespace chromeos |