Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: chromeos/network/proxy/proxy_config_handler.cc

Issue 2442313003: Move some proxy config code out of src/chrome (Closed)
Patch Set: Fix DEPS Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/net/proxy_config_handler.h" 5 #include "chromeos/network/proxy/proxy_config_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/chromeos/net/onc_utils.h"
13 #include "chrome/common/pref_names.h"
14 #include "chromeos/dbus/dbus_thread_manager.h" 12 #include "chromeos/dbus/dbus_thread_manager.h"
15 #include "chromeos/dbus/shill_service_client.h" 13 #include "chromeos/dbus/shill_service_client.h"
16 #include "chromeos/network/network_handler_callbacks.h" 14 #include "chromeos/network/network_handler_callbacks.h"
17 #include "chromeos/network/network_profile.h" 15 #include "chromeos/network/network_profile.h"
18 #include "chromeos/network/network_profile_handler.h" 16 #include "chromeos/network/network_profile_handler.h"
19 #include "chromeos/network/network_state.h" 17 #include "chromeos/network/network_state.h"
20 #include "chromeos/network/network_state_handler.h" 18 #include "chromeos/network/network_state_handler.h"
21 #include "chromeos/network/onc/onc_utils.h" 19 #include "chromeos/network/onc/onc_utils.h"
20 #include "components/onc/onc_pref_names.h"
22 #include "components/pref_registry/pref_registry_syncable.h" 21 #include "components/pref_registry/pref_registry_syncable.h"
23 #include "components/prefs/pref_registry_simple.h" 22 #include "components/prefs/pref_registry_simple.h"
24 #include "components/proxy_config/proxy_config_dictionary.h" 23 #include "components/proxy_config/proxy_config_dictionary.h"
24 #include "components/proxy_config/proxy_config_pref_names.h"
25 #include "dbus/object_path.h" 25 #include "dbus/object_path.h"
26 #include "third_party/cros_system_api/dbus/service_constants.h" 26 #include "third_party/cros_system_api/dbus/service_constants.h"
27 27
28 namespace chromeos { 28 namespace chromeos {
29 29
30 namespace { 30 namespace {
31 31
32 void NotifyNetworkStateHandler(const std::string& service_path) { 32 void NotifyNetworkStateHandler(const std::string& service_path) {
33 if (NetworkHandler::IsInitialized()) { 33 if (NetworkHandler::IsInitialized()) {
34 NetworkHandler::Get()->network_state_handler()->RequestUpdateForNetwork( 34 NetworkHandler::Get()->network_state_handler()->RequestUpdateForNetwork(
35 service_path); 35 service_path);
36 } 36 }
37 } 37 }
38 38
39 } // namespace 39 } // namespace
40 40
41 namespace proxy_config { 41 namespace proxy_config {
42 42
43 std::unique_ptr<ProxyConfigDictionary> GetProxyConfigForNetwork( 43 std::unique_ptr<ProxyConfigDictionary> GetProxyConfigForNetwork(
44 const PrefService* profile_prefs, 44 const PrefService* profile_prefs,
45 const PrefService* local_state_prefs, 45 const PrefService* local_state_prefs,
46 const NetworkState& network, 46 const NetworkState& network,
47 ::onc::ONCSource* onc_source) { 47 ::onc::ONCSource* onc_source) {
48 const base::DictionaryValue* network_policy = 48 const base::DictionaryValue* network_policy = onc::GetPolicyForNetwork(
49 onc::GetPolicyForNetwork( 49 profile_prefs, local_state_prefs, network, onc_source);
50 profile_prefs, local_state_prefs, network, onc_source);
51 50
52 if (network_policy) { 51 if (network_policy) {
53 const base::DictionaryValue* proxy_policy = NULL; 52 const base::DictionaryValue* proxy_policy = NULL;
54 network_policy->GetDictionaryWithoutPathExpansion( 53 network_policy->GetDictionaryWithoutPathExpansion(
55 ::onc::network_config::kProxySettings, &proxy_policy); 54 ::onc::network_config::kProxySettings, &proxy_policy);
56 if (!proxy_policy) { 55 if (!proxy_policy) {
57 // This policy doesn't set a proxy for this network. Nonetheless, this 56 // This policy doesn't set a proxy for this network. Nonetheless, this
58 // disallows changes by the user. 57 // disallows changes by the user.
59 return std::unique_ptr<ProxyConfigDictionary>(); 58 return std::unique_ptr<ProxyConfigDictionary>();
60 } 59 }
61 60
62 std::unique_ptr<base::DictionaryValue> proxy_dict = 61 std::unique_ptr<base::DictionaryValue> proxy_dict =
63 onc::ConvertOncProxySettingsToProxyConfig(*proxy_policy); 62 onc::ConvertOncProxySettingsToProxyConfig(*proxy_policy);
64 return base::MakeUnique<ProxyConfigDictionary>(proxy_dict.get()); 63 return base::MakeUnique<ProxyConfigDictionary>(proxy_dict.get());
65 } 64 }
66 65
67 if (network.profile_path().empty()) 66 if (network.profile_path().empty())
68 return std::unique_ptr<ProxyConfigDictionary>(); 67 return std::unique_ptr<ProxyConfigDictionary>();
69 68
70 const NetworkProfile* profile = NetworkHandler::Get() 69 const NetworkProfile* profile =
71 ->network_profile_handler()->GetProfileForPath(network.profile_path()); 70 NetworkHandler::Get()->network_profile_handler()->GetProfileForPath(
71 network.profile_path());
72 if (!profile) { 72 if (!profile) {
73 VLOG(1) << "Unknown profile_path '" << network.profile_path() << "'."; 73 VLOG(1) << "Unknown profile_path '" << network.profile_path() << "'.";
74 return std::unique_ptr<ProxyConfigDictionary>(); 74 return std::unique_ptr<ProxyConfigDictionary>();
75 } 75 }
76 if (!profile_prefs && profile->type() == NetworkProfile::TYPE_USER) { 76 if (!profile_prefs && profile->type() == NetworkProfile::TYPE_USER) {
77 // This case occurs, for example, if called from the proxy config tracker 77 // This case occurs, for example, if called from the proxy config tracker
78 // created for the system request context and the signin screen. Both don't 78 // created for the system request context and the signin screen. Both don't
79 // use profile prefs and shouldn't depend on the user's not shared proxy 79 // use profile prefs and shouldn't depend on the user's not shared proxy
80 // settings. 80 // settings.
81 VLOG(1) 81 VLOG(1)
(...skipping 16 matching lines...) Expand all
98 chromeos::ShillServiceClient* shill_service_client = 98 chromeos::ShillServiceClient* shill_service_client =
99 DBusThreadManager::Get()->GetShillServiceClient(); 99 DBusThreadManager::Get()->GetShillServiceClient();
100 100
101 // The user's proxy setting is not stored in the Chrome preference yet. We 101 // The user's proxy setting is not stored in the Chrome preference yet. We
102 // still rely on Shill storing it. 102 // still rely on Shill storing it.
103 ProxyPrefs::ProxyMode mode; 103 ProxyPrefs::ProxyMode mode;
104 if (!proxy_config.GetMode(&mode) || mode == ProxyPrefs::MODE_DIRECT) { 104 if (!proxy_config.GetMode(&mode) || mode == ProxyPrefs::MODE_DIRECT) {
105 // Return empty string for direct mode for portal check to work correctly. 105 // Return empty string for direct mode for portal check to work correctly.
106 // TODO(pneubeck): Consider removing this legacy code. 106 // TODO(pneubeck): Consider removing this legacy code.
107 shill_service_client->ClearProperty( 107 shill_service_client->ClearProperty(
108 dbus::ObjectPath(network.path()), 108 dbus::ObjectPath(network.path()), shill::kProxyConfigProperty,
109 shill::kProxyConfigProperty,
110 base::Bind(&NotifyNetworkStateHandler, network.path()), 109 base::Bind(&NotifyNetworkStateHandler, network.path()),
111 base::Bind(&network_handler::ShillErrorCallbackFunction, 110 base::Bind(&network_handler::ShillErrorCallbackFunction,
112 "SetProxyConfig.ClearProperty Failed", 111 "SetProxyConfig.ClearProperty Failed", network.path(),
113 network.path(),
114 network_handler::ErrorCallback())); 112 network_handler::ErrorCallback()));
115 } else { 113 } else {
116 std::string proxy_config_str; 114 std::string proxy_config_str;
117 base::JSONWriter::Write(proxy_config.GetDictionary(), &proxy_config_str); 115 base::JSONWriter::Write(proxy_config.GetDictionary(), &proxy_config_str);
118 shill_service_client->SetProperty( 116 shill_service_client->SetProperty(
119 dbus::ObjectPath(network.path()), 117 dbus::ObjectPath(network.path()), shill::kProxyConfigProperty,
120 shill::kProxyConfigProperty,
121 base::StringValue(proxy_config_str), 118 base::StringValue(proxy_config_str),
122 base::Bind(&NotifyNetworkStateHandler, network.path()), 119 base::Bind(&NotifyNetworkStateHandler, network.path()),
123 base::Bind(&network_handler::ShillErrorCallbackFunction, 120 base::Bind(&network_handler::ShillErrorCallbackFunction,
124 "SetProxyConfig.SetProperty Failed", 121 "SetProxyConfig.SetProperty Failed", network.path(),
125 network.path(),
126 network_handler::ErrorCallback())); 122 network_handler::ErrorCallback()));
127 } 123 }
128 } 124 }
129 125
130 } // namespace proxy_config 126 } // namespace proxy_config
131 127
132 } // namespace chromeos 128 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/proxy/proxy_config_handler.h ('k') | chromeos/network/proxy/proxy_config_service_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698