OLD | NEW |
---|---|
(Empty) | |
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 "chromeos/dbus/dbus_thread_manager.h" | |
13 #include "chromeos/dbus/shill_service_client.h" | |
14 #include "chromeos/network/network_state.h" | |
15 #include "chromeos/network/network_state_handler.h" | |
16 #include "dbus/object_path.h" | |
17 #include "third_party/cros_system_api/dbus/service_constants.h" | |
18 | |
19 namespace { | |
20 | |
21 void LogError(const std::string& error_name, | |
22 const std::string& error_message) { | |
23 LOG(ERROR) << "Could not clear or set ProxyConfig: " << error_message; | |
24 } | |
25 | |
26 } // namespace | |
27 | |
28 namespace chromeos { | |
29 | |
30 namespace proxy_config { | |
31 | |
32 scoped_ptr<ProxyConfigDictionary> GetProxyConfigOfNetwork( | |
Mattias Nissler (ping if slow)
2013/06/07 09:10:14
nit: ForNetwork is probably more accurate, as prox
pneubeck (no reviews)
2013/06/07 09:46:10
Done.
| |
33 const NetworkState& network) { | |
34 const base::DictionaryValue& value = network.proxy_config(); | |
35 if (value.empty()) | |
36 return scoped_ptr<ProxyConfigDictionary>(); | |
37 return make_scoped_ptr(new ProxyConfigDictionary(&value)); | |
38 } | |
39 | |
40 void SetProxyConfigOfNetwork(const ProxyConfigDictionary& proxy_config, | |
Mattias Nissler (ping if slow)
2013/06/07 09:10:14
ditto
pneubeck (no reviews)
2013/06/07 09:46:10
Done.
| |
41 const NetworkState& network) { | |
42 chromeos::ShillServiceClient* shill_service_client = | |
43 DBusThreadManager::Get()->GetShillServiceClient(); | |
44 | |
45 ProxyPrefs::ProxyMode mode; | |
46 if (!proxy_config.GetMode(&mode) || mode == ProxyPrefs::MODE_DIRECT) { | |
47 // TODO(pneubeck): Consider removing this legacy code. Return empty string | |
48 // for direct mode for portal check to work correctly. | |
49 shill_service_client->ClearProperty( | |
50 dbus::ObjectPath(network.path()), | |
51 flimflam::kProxyConfigProperty, | |
52 base::Bind(&base::DoNothing), | |
53 base::Bind(&LogError)); | |
54 } else { | |
55 std::string proxy_config_str; | |
56 base::JSONWriter::Write(&proxy_config.GetDictionary(), &proxy_config_str); | |
57 shill_service_client->SetProperty( | |
58 dbus::ObjectPath(network.path()), | |
59 flimflam::kProxyConfigProperty, | |
60 base::StringValue(proxy_config_str), | |
61 base::Bind(&base::DoNothing), | |
62 base::Bind(&LogError)); | |
63 } | |
64 | |
65 if (NetworkHandler::IsInitialized()) { | |
66 NetworkHandler::Get()->network_state_handler()-> | |
67 RequestUpdateForNetwork(network.path()); | |
68 } | |
69 } | |
70 | |
71 } // namespace proxy_config | |
72 | |
73 } // namespace chromeos | |
OLD | NEW |