proxy_config_handler.cc revision 7dbb3d5cf0c15f500944d211057644d6a2f37371
1// Copyright (c) 2013 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/proxy_config_handler.h" 6 7#include "base/bind.h" 8#include "base/json/json_writer.h" 9#include "base/logging.h" 10#include "base/values.h" 11#include "chrome/browser/prefs/proxy_config_dictionary.h" 12#include "chrome/common/pref_names.h" 13#include "chromeos/dbus/dbus_thread_manager.h" 14#include "chromeos/dbus/shill_service_client.h" 15#include "chromeos/network/network_handler_callbacks.h" 16#include "chromeos/network/network_state.h" 17#include "chromeos/network/network_state_handler.h" 18#include "components/user_prefs/pref_registry_syncable.h" 19#include "dbus/object_path.h" 20#include "third_party/cros_system_api/dbus/service_constants.h" 21 22namespace chromeos { 23 24namespace proxy_config { 25 26scoped_ptr<ProxyConfigDictionary> GetProxyConfigForNetwork( 27 const NetworkState& network) { 28 const base::DictionaryValue& value = network.proxy_config(); 29 if (value.empty()) 30 return scoped_ptr<ProxyConfigDictionary>(); 31 return make_scoped_ptr(new ProxyConfigDictionary(&value)); 32} 33 34void SetProxyConfigForNetwork(const ProxyConfigDictionary& proxy_config, 35 const NetworkState& network) { 36 chromeos::ShillServiceClient* shill_service_client = 37 DBusThreadManager::Get()->GetShillServiceClient(); 38 39 ProxyPrefs::ProxyMode mode; 40 if (!proxy_config.GetMode(&mode) || mode == ProxyPrefs::MODE_DIRECT) { 41 // TODO(pneubeck): Consider removing this legacy code. Return empty string 42 // for direct mode for portal check to work correctly. 43 shill_service_client->ClearProperty( 44 dbus::ObjectPath(network.path()), 45 flimflam::kProxyConfigProperty, 46 base::Bind(&base::DoNothing), 47 base::Bind(&network_handler::ShillErrorCallbackFunction, 48 "SetProxyConfig.ClearProperty Failed", 49 network.path(), network_handler::ErrorCallback())); 50 } else { 51 std::string proxy_config_str; 52 base::JSONWriter::Write(&proxy_config.GetDictionary(), &proxy_config_str); 53 shill_service_client->SetProperty( 54 dbus::ObjectPath(network.path()), 55 flimflam::kProxyConfigProperty, 56 base::StringValue(proxy_config_str), 57 base::Bind(&base::DoNothing), 58 base::Bind(&network_handler::ShillErrorCallbackFunction, 59 "SetProxyConfig.SetProperty Failed", 60 network.path(), network_handler::ErrorCallback())); 61 } 62 63 if (NetworkHandler::IsInitialized()) { 64 NetworkHandler::Get()->network_state_handler()-> 65 RequestUpdateForNetwork(network.path()); 66 } 67} 68 69void RegisterProfilePrefs( 70 user_prefs::PrefRegistrySyncable* registry) { 71 registry->RegisterBooleanPref( 72 prefs::kUseSharedProxies, 73 false, 74 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 75} 76 77} // namespace proxy_config 78 79} // namespace chromeos 80