OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS 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 "update_engine/chrome_proxy_resolver.h" | 5 #include "update_engine/chrome_proxy_resolver.h" |
6 | 6 |
7 #include <base/json/json_reader.h> | 7 #include <base/json/json_reader.h> |
8 #include <base/scoped_ptr.h> | 8 #include <base/scoped_ptr.h> |
9 #include <base/values.h> | 9 #include <base/values.h> |
10 | 10 |
11 #include "update_engine/utils.h" | 11 #include "update_engine/utils.h" |
12 | 12 |
| 13 using google::protobuf::Closure; |
| 14 using google::protobuf::NewCallback; |
| 15 using std::deque; |
13 using std::string; | 16 using std::string; |
14 using std::vector; | 17 using std::vector; |
15 | 18 |
16 namespace chromeos_update_engine { | 19 namespace chromeos_update_engine { |
17 | 20 |
18 const char kSessionManagerService[] = "org.chromium.SessionManager"; | 21 const char kSessionManagerService[] = "org.chromium.SessionManager"; |
19 const char kSessionManagerPath[] = "/org/chromium/SessionManager"; | 22 const char kSessionManagerPath[] = "/org/chromium/SessionManager"; |
20 const char kSessionManagerInterface[] = "org.chromium.SessionManagerInterface"; | 23 const char kSessionManagerInterface[] = "org.chromium.SessionManagerInterface"; |
21 const char kSessionManagerRetrievePropertyMethod[] = | 24 const char kSessionManagerRetrievePropertyMethod[] = |
22 "RetrieveProperty"; | 25 "RetrieveProperty"; |
23 const char kSessionManagerProxySettingsKey[] = "cros.proxy.everywhere"; | 26 const char kSessionManagerProxySettingsKey[] = "cros.proxy.everywhere"; |
24 | 27 |
25 bool ChromeProxyResolver::GetProxiesForUrl( | 28 bool ChromeProxyResolver::GetProxiesForUrl( |
26 const std::string& url, | 29 const std::string& url, |
27 std::deque<std::string>* out_proxies) { | 30 ProxiesResolvedFn callback, |
28 // First, query dbus for the currently stored settings | 31 void* data) { |
29 DBusGProxy* proxy = DbusProxy(); | 32 ChromeProxyResolverClosureArgs args; |
30 TEST_AND_RETURN_FALSE(proxy); | 33 args.url = url; |
31 string json_settings; | 34 args.callback = callback; |
32 TEST_AND_RETURN_FALSE(GetJsonProxySettings(proxy, &json_settings)); | 35 args.data = data; |
33 LOG(INFO) << "got settings:" << json_settings; | 36 Closure* closure = NewCallback(this, |
34 TEST_AND_RETURN_FALSE( | 37 &ChromeProxyResolver::GetProxiesForUrlCallback, |
35 GetProxiesForUrlWithSettings(url, json_settings, out_proxies)); | 38 args); |
| 39 g_idle_add(utils::GlibRunClosure, closure); |
36 return true; | 40 return true; |
37 } | 41 } |
38 | 42 |
| 43 void ChromeProxyResolver::GetProxiesForUrlCallback( |
| 44 ChromeProxyResolverClosureArgs args) { |
| 45 deque<string> proxies; |
| 46 // First, query dbus for the currently stored settings |
| 47 DBusGProxy* proxy = DbusProxy(); |
| 48 if (proxy) { |
| 49 string json_settings; |
| 50 if (GetJsonProxySettings(proxy, &json_settings)) { |
| 51 LOG(INFO) << "got settings:" << json_settings; |
| 52 GetProxiesForUrlWithSettings(args.url, json_settings, &proxies); |
| 53 } |
| 54 } |
| 55 (*args.callback)(proxies, args.data); |
| 56 } |
| 57 |
39 bool ChromeProxyResolver::GetJsonProxySettings(DBusGProxy* proxy, | 58 bool ChromeProxyResolver::GetJsonProxySettings(DBusGProxy* proxy, |
40 std::string* out_json) { | 59 std::string* out_json) { |
41 gchar* value = NULL; | 60 gchar* value = NULL; |
42 GArray* sig = NULL; | 61 GArray* sig = NULL; |
43 GError* error = NULL; | 62 GError* error = NULL; |
44 TEST_AND_RETURN_FALSE( | 63 TEST_AND_RETURN_FALSE( |
45 dbus_->ProxyCall(proxy, | 64 dbus_->ProxyCall(proxy, |
46 kSessionManagerRetrievePropertyMethod, | 65 kSessionManagerRetrievePropertyMethod, |
47 &error, | 66 &error, |
48 G_TYPE_STRING, kSessionManagerProxySettingsKey, | 67 G_TYPE_STRING, kSessionManagerProxySettingsKey, |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 } | 195 } |
177 if (utils::StringHasPrefix(proxy, kNoProxy)) { | 196 if (utils::StringHasPrefix(proxy, kNoProxy)) { |
178 // known failure case. don't log. | 197 // known failure case. don't log. |
179 return false; | 198 return false; |
180 } | 199 } |
181 LOG(INFO) << "Unknown proxy type: " << proxy; | 200 LOG(INFO) << "Unknown proxy type: " << proxy; |
182 return false; | 201 return false; |
183 } | 202 } |
184 | 203 |
185 } // namespace chromeos_update_engine | 204 } // namespace chromeos_update_engine |
OLD | NEW |