AU: remove obsolete proxy resolver code
The module chrome_proxy_resolver has been long obsoleted by
chrome_browser_proxy_resolver, only that it kept living in our codebase,
if only for the use of a single static method, which had nothing to do
with proxy resolution and in fact is Curl specific. This CL removes it
along with its build/execution dependencies.
BUG=chromium:208655
TEST=Builds fine and unit tests running
Change-Id: Iff50c2c75451e5f3ddbc27c5a90a8b1a421a5d8d
Reviewed-on: https://gerrit.chromium.org/gerrit/63147
Tested-by: Gilad Arnold <garnold@chromium.org>
Reviewed-by: Alex Deymo <deymo@chromium.org>
Reviewed-by: Don Garrett <dgarrett@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
diff --git a/SConstruct b/SConstruct
index c60f1d0..9d34cd4 100644
--- a/SConstruct
+++ b/SConstruct
@@ -246,7 +246,6 @@
bzip_extent_writer.cc
certificate_checker.cc
chrome_browser_proxy_resolver.cc
- chrome_proxy_resolver.cc
clock.cc
connection_manager.cc
constants.cc
@@ -300,7 +299,6 @@
bzip_extent_writer_unittest.cc
certificate_checker_unittest.cc
chrome_browser_proxy_resolver_unittest.cc
- chrome_proxy_resolver_unittest.cc
connection_manager_unittest.cc
cycle_breaker_unittest.cc
delta_diff_generator_unittest.cc
diff --git a/chrome_proxy_resolver.cc b/chrome_proxy_resolver.cc
deleted file mode 100644
index 2c1c1ca..0000000
--- a/chrome_proxy_resolver.cc
+++ /dev/null
@@ -1,205 +0,0 @@
-// Copyright (c) 2011 The Chromium OS 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 "update_engine/chrome_proxy_resolver.h"
-
-#include <base/json/json_reader.h>
-#include <base/memory/scoped_ptr.h>
-#include <base/values.h>
-
-#include "update_engine/utils.h"
-
-using google::protobuf::Closure;
-using google::protobuf::NewCallback;
-using std::deque;
-using std::string;
-using std::vector;
-
-namespace chromeos_update_engine {
-
-const char kSessionManagerService[] = "org.chromium.SessionManager";
-const char kSessionManagerPath[] = "/org/chromium/SessionManager";
-const char kSessionManagerInterface[] = "org.chromium.SessionManagerInterface";
-const char kSessionManagerRetrievePropertyMethod[] =
- "RetrieveProperty";
-const char kSessionManagerProxySettingsKey[] = "cros.proxy.everywhere";
-
-bool ChromeProxyResolver::GetProxiesForUrl(
- const std::string& url,
- ProxiesResolvedFn callback,
- void* data) {
- ChromeProxyResolverClosureArgs args;
- args.url = url;
- args.callback = callback;
- args.data = data;
- Closure* closure = NewCallback(this,
- &ChromeProxyResolver::GetProxiesForUrlCallback,
- args);
- g_idle_add(utils::GlibRunClosure, closure);
- return true;
-}
-
-void ChromeProxyResolver::GetProxiesForUrlCallback(
- ChromeProxyResolverClosureArgs args) {
- deque<string> proxies;
- // First, query dbus for the currently stored settings
- DBusGProxy* proxy = DbusProxy();
- if (proxy) {
- string json_settings;
- if (GetJsonProxySettings(proxy, &json_settings)) {
- LOG(INFO) << "got settings:" << json_settings;
- GetProxiesForUrlWithSettings(args.url, json_settings, &proxies);
- }
- }
- (*args.callback)(proxies, args.data);
-}
-
-bool ChromeProxyResolver::GetJsonProxySettings(DBusGProxy* proxy,
- std::string* out_json) {
- gchar* value = NULL;
- GArray* sig = NULL;
- GError* error = NULL;
- TEST_AND_RETURN_FALSE(
- dbus_->ProxyCall(proxy,
- kSessionManagerRetrievePropertyMethod,
- &error,
- G_TYPE_STRING, kSessionManagerProxySettingsKey,
- G_TYPE_INVALID,
- G_TYPE_STRING, &value,
- DBUS_TYPE_G_UCHAR_ARRAY, &sig,
- G_TYPE_INVALID));
- g_array_free(sig, false);
- out_json->assign(value);
- g_free(value);
- return true;
-}
-
-DBusGProxy* ChromeProxyResolver::DbusProxy() {
- GError* error = NULL;
- DBusGConnection* bus = dbus_->BusGet(DBUS_BUS_SYSTEM, &error);
- if (!bus) {
- LOG(ERROR) << "Failed to get System Dbus: "
- << utils::GetAndFreeGError(&error);
- return NULL;
- }
- DBusGProxy* proxy = dbus_->ProxyNewForNameOwner(bus,
- kSessionManagerService,
- kSessionManagerPath,
- kSessionManagerInterface,
- &error);
- if (!proxy) {
- LOG(ERROR) << "Error getting FlimFlam proxy: "
- << utils::GetAndFreeGError(&error);
- }
- return proxy;
-}
-
-namespace {
-enum ProxyMode {
- kProxyModeDirect = 0,
- kProxyModeAutoDetect,
- kProxyModePACScript,
- kProxyModeSingle,
- kProxyModeProxyPerScheme
-};
-} // namespace {}
-
-bool ChromeProxyResolver::GetProxiesForUrlWithSettings(
- const string& url,
- const string& json_settings,
- std::deque<std::string>* out_proxies) {
- base::JSONReader parser;
-
- scoped_ptr<Value> root(parser.ReadToValue(json_settings));
- if (!root.get()) {
- LOG(ERROR) << "Unable to parse \"" << json_settings << "\": "
- << parser.GetErrorMessage();
- return false;
- }
-
- TEST_AND_RETURN_FALSE(root->IsType(Value::TYPE_DICTIONARY));
-
- DictionaryValue* root_dict = dynamic_cast<DictionaryValue*>(root.get());
- TEST_AND_RETURN_FALSE(root_dict);
- int mode = -1;
- TEST_AND_RETURN_FALSE(root_dict->GetInteger("mode", &mode));
-
- LOG(INFO) << "proxy mode: " << mode;
- if (mode != kProxyModeSingle &&
- mode != kProxyModeProxyPerScheme) {
- LOG(INFO) << "unsupported proxy scheme";
- out_proxies->clear();
- out_proxies->push_back(kNoProxy);
- return true;
- }
- if (mode == kProxyModeSingle) {
- LOG(INFO) << "single proxy mode";
- string proxy_string;
- TEST_AND_RETURN_FALSE(root_dict->GetString("single.server", &proxy_string));
- if (proxy_string.find("://") == string::npos) {
- // missing protocol, assume http.
- proxy_string = string("http://") + proxy_string;
- }
- out_proxies->clear();
- out_proxies->push_back(proxy_string);
- LOG(INFO) << "single proxy: " << (*out_proxies)[0];
- out_proxies->push_back(kNoProxy);
- return true;
- }
- // Proxy per scheme mode.
- LOG(INFO) << "proxy per scheme mode";
-
- // Find which scheme we are
- bool url_is_http = utils::StringHasPrefix(url, "http://");
- if (!url_is_http)
- TEST_AND_RETURN_FALSE(utils::StringHasPrefix(url, "https://"));
-
- // Using "proto_*" variables to refer to http or https
- const string proto_path = url_is_http ? "http.server" : "https.server";
- const string socks_path = "socks.server";
-
- out_proxies->clear();
-
- string proto_server, socks_server;
- if (root_dict->GetString(proto_path, &proto_server)) {
- if (proto_server.find("://") == string::npos) {
- // missing protocol, assume http.
- proto_server = string("http://") + proto_server;
- }
- out_proxies->push_back(proto_server);
- LOG(INFO) << "got http/https server: " << proto_server;
- }
- if (root_dict->GetString(socks_path, &socks_server)) {
- out_proxies->push_back(socks_server);
- LOG(INFO) << "got socks server: " << proto_server;
- }
- out_proxies->push_back(kNoProxy);
- return true;
-}
-
-bool ChromeProxyResolver::GetProxyType(const std::string& proxy,
- curl_proxytype* out_type) {
- if (utils::StringHasPrefix(proxy, "socks5://") ||
- utils::StringHasPrefix(proxy, "socks://")) {
- *out_type = CURLPROXY_SOCKS5_HOSTNAME;
- return true;
- }
- if (utils::StringHasPrefix(proxy, "socks4://")) {
- *out_type = CURLPROXY_SOCKS4A;
- return true;
- }
- if (utils::StringHasPrefix(proxy, "http://") ||
- utils::StringHasPrefix(proxy, "https://")) {
- *out_type = CURLPROXY_HTTP;
- return true;
- }
- if (utils::StringHasPrefix(proxy, kNoProxy)) {
- // known failure case. don't log.
- return false;
- }
- LOG(INFO) << "Unknown proxy type: " << proxy;
- return false;
-}
-
-} // namespace chromeos_update_engine
diff --git a/chrome_proxy_resolver.h b/chrome_proxy_resolver.h
deleted file mode 100644
index 2df751e..0000000
--- a/chrome_proxy_resolver.h
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_CHROME_PROXY_RESOLVER_H__
-#define CHROMEOS_PLATFORM_UPDATE_ENGINE_CHROME_PROXY_RESOLVER_H__
-
-#include <deque>
-#include <string>
-
-#include <curl/curl.h>
-#include <gtest/gtest_prod.h> // for FRIEND_TEST
-
-#include "update_engine/dbus_interface.h"
-#include "update_engine/proxy_resolver.h"
-
-namespace chromeos_update_engine {
-
-extern const char kSessionManagerService[];
-extern const char kSessionManagerPath[];
-extern const char kSessionManagerInterface[];
-extern const char kSessionManagerRetrievePropertyMethod[];
-extern const char kSessionManagerProxySettingsKey[];
-
-// Class to resolve proxy for a url based on Chrome's proxy settings.
-
-// Currently only supports manual settings, not PAC files or autodetected
-// settings.
-
-struct ChromeProxyResolverClosureArgs {
- std::string url;
- ProxiesResolvedFn callback;
- void* data;
-};
-
-class ChromeProxyResolver : public ProxyResolver {
- public:
- explicit ChromeProxyResolver(DbusGlibInterface* dbus) : dbus_(dbus) {}
- virtual ~ChromeProxyResolver() {}
-
- virtual bool GetProxiesForUrl(const std::string& url,
- ProxiesResolvedFn callback,
- void* data);
-
- // Get the curl proxy type for a given proxy url. Returns true on success.
- // Note: if proxy is kNoProxy, this will return false.
- static bool GetProxyType(const std::string& proxy, curl_proxytype* out_type);
-
- private:
- FRIEND_TEST(ChromeProxyResolverTest, GetProxiesForUrlWithSettingsTest);
-
- // Closure callback, so we can pretend we need to wait on the main loop
- // before returing proxies to the client.
- void GetProxiesForUrlCallback(ChromeProxyResolverClosureArgs args);
-
- // Fetches a dbus proxy to session manager. Returns NULL on failure.
- DBusGProxy* DbusProxy();
-
- // Fetches the json-encoded proxy settings string from the session manager.
- bool GetJsonProxySettings(DBusGProxy* proxy, std::string* out_json);
-
- // Given a |url| and the json encoded settings |json_settings|,
- // returns the proper proxy servers in |out_proxies|. Returns true on
- // success.
- bool GetProxiesForUrlWithSettings(const std::string& url,
- const std::string& json_settings,
- std::deque<std::string>* out_proxies);
-
- DbusGlibInterface* dbus_;
-
- DISALLOW_COPY_AND_ASSIGN(ChromeProxyResolver);
-};
-
-} // namespace chromeos_update_engine
-
-#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_CHROME_PROXY_RESOLVER_H__
diff --git a/chrome_proxy_resolver_unittest.cc b/chrome_proxy_resolver_unittest.cc
deleted file mode 100644
index cab2d33..0000000
--- a/chrome_proxy_resolver_unittest.cc
+++ /dev/null
@@ -1,158 +0,0 @@
-// Copyright (c) 2009 The Chromium OS 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 <deque>
-#include <string>
-
-#include <gtest/gtest.h>
-
-#include "update_engine/chrome_proxy_resolver.h"
-#include "update_engine/mock_dbus_interface.h"
-
-using std::deque;
-using std::string;
-using ::testing::_;
-using ::testing::Return;
-using ::testing::SetArgumentPointee;
-using ::testing::StrEq;
-
-namespace chromeos_update_engine {
-
-class ChromeProxyResolverTest : public ::testing::Test { };
-
-TEST(ChromeProxyResolverTest, GetProxiesForUrlWithSettingsTest) {
- const string kSingle =
- "{\"mode\":3,\"single\":{\"server\":\"192.168.42.86:80\",\"src\":0}}";
- const string kSocks =
- "{\"mode\":4,\"socks\":{\"server\":\"socks5://192.168.42.83:5555\","
- "\"src\":0}}";
- const string kAll =
- "{\"http\":{\"server\":\"http_proxy:11\",\"src\":0},"
- "\"https\":{\"server\":\"https://https_proxy:22\",\"src\":0},"
- "\"mode\":4,"
- "\"socks\":{\"server\":\"socks5://socks:55\",\"src\":0}}";
- const string kHttpHttps =
- "{\"http\":{\"server\":\"http_proxy:11\",\"src\":0},"
- "\"https\":{\"server\":\"https://https_proxy:22\",\"src\":0},"
- "\"mode\":4}";
-
- ChromeProxyResolver resolver(NULL);
- deque<string> out;
- string urls[] = {"http://foo.com/update", "https://bar.com/foo.gz"};
- string multi_settings[] = {kAll, kHttpHttps};
- for (size_t i = 0; i < arraysize(urls); i++) {
- const string& url = urls[i];
- LOG(INFO) << "url: " << url;
- EXPECT_TRUE(resolver.GetProxiesForUrlWithSettings(url, kSingle, &out));
- EXPECT_EQ(2, out.size());
- EXPECT_EQ("http://192.168.42.86:80", out[0]);
- EXPECT_EQ(kNoProxy, out[1]);
-
- EXPECT_TRUE(resolver.GetProxiesForUrlWithSettings(url, kSocks, &out));
- EXPECT_EQ(2, out.size());
- EXPECT_EQ("socks5://192.168.42.83:5555", out[0]);
- EXPECT_EQ(kNoProxy, out[1]);
-
- for (size_t j = 0; j < arraysize(multi_settings); j++) {
- const string& settings = multi_settings[j];
- EXPECT_TRUE(resolver.GetProxiesForUrlWithSettings(url, settings, &out));
- EXPECT_EQ(j == 0 ? 3 : 2, out.size());
- if (i == 0)
- EXPECT_EQ("http://http_proxy:11", out[0]);
- else
- EXPECT_EQ("https://https_proxy:22", out[0]);
- if (j == 0)
- EXPECT_EQ("socks5://socks:55", out[1]);
- EXPECT_EQ(kNoProxy, out.back());
- }
- }
-
- // Bad JSON
- EXPECT_FALSE(resolver.GetProxiesForUrlWithSettings("http://foo.com",
- "}",
- &out));
-
- // Bad proxy scheme
- EXPECT_TRUE(resolver.GetProxiesForUrlWithSettings("http://foo.com",
- "{\"mode\":1}",
- &out));
- EXPECT_EQ(1, out.size());
- EXPECT_EQ(kNoProxy, out[0]);
-}
-
-namespace {
-void DbusInterfaceTestResolved(const std::deque<std::string>& proxies,
- void* data) {
- EXPECT_EQ(2, proxies.size());
- EXPECT_EQ("socks5://192.168.52.83:5555", proxies[0]);
- EXPECT_EQ(kNoProxy, proxies[1]);
- g_main_loop_quit(reinterpret_cast<GMainLoop*>(data));
-}
-}
-
-TEST(ChromeProxyResolverTest, DbusInterfaceTest) {
- long number = 1;
- DBusGConnection* kMockSystemBus =
- reinterpret_cast<DBusGConnection*>(number++);
- DBusGProxy* kMockSessionManagerProxy =
- reinterpret_cast<DBusGProxy*>(number++);
-
- const char settings[] =
- "{\"mode\":4,\"socks\":{\"server\":\"socks5://192.168.52.83:5555\","
- "\"src\":0}}";
-
- MockDbusGlib dbus_iface;
- ChromeProxyResolver resolver(&dbus_iface);
-
- GArray* ret_array = g_array_new(FALSE, FALSE, 1);
-
- EXPECT_CALL(dbus_iface, BusGet(DBUS_BUS_SYSTEM, _))
- .Times(1)
- .WillRepeatedly(Return(kMockSystemBus));
- EXPECT_CALL(dbus_iface,
- ProxyNewForNameOwner(kMockSystemBus,
- StrEq(kSessionManagerService),
- StrEq(kSessionManagerPath),
- StrEq(kSessionManagerInterface),
- _))
- .WillOnce(Return(kMockSessionManagerProxy));
- EXPECT_CALL(dbus_iface, ProxyCall(
- kMockSessionManagerProxy,
- StrEq(kSessionManagerRetrievePropertyMethod),
- _,
- G_TYPE_STRING, StrEq(kSessionManagerProxySettingsKey),
- G_TYPE_INVALID,
- G_TYPE_STRING, _,
- DBUS_TYPE_G_UCHAR_ARRAY, _))
- .WillOnce(DoAll(SetArgumentPointee<7>(strdup(settings)),
- SetArgumentPointee<9>(ret_array),
- Return(TRUE)));
-
- GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE);
-
- EXPECT_TRUE(resolver.GetProxiesForUrl("http://user:pass@foo.com:22",
- &DbusInterfaceTestResolved,
- loop));
- g_main_loop_run(loop);
- g_main_loop_unref(loop);
-}
-
-TEST(ChromeProxyResolverTest, GetProxyTypeTest) {
- curl_proxytype type;
- EXPECT_TRUE(ChromeProxyResolver::GetProxyType("socks://f.ru", &type));
- EXPECT_EQ(CURLPROXY_SOCKS5_HOSTNAME, type);
- EXPECT_TRUE(ChromeProxyResolver::GetProxyType("socks5://f.ru:9", &type));
- EXPECT_EQ(CURLPROXY_SOCKS5_HOSTNAME, type);
- EXPECT_TRUE(ChromeProxyResolver::GetProxyType("socks4://f.ru:9", &type));
- EXPECT_EQ(CURLPROXY_SOCKS4A, type);
- EXPECT_TRUE(ChromeProxyResolver::GetProxyType("http://f.no:88", &type));
- EXPECT_EQ(CURLPROXY_HTTP, type);
- EXPECT_TRUE(ChromeProxyResolver::GetProxyType("https://f.no:88", &type));
- EXPECT_EQ(CURLPROXY_HTTP, type);
- EXPECT_FALSE(ChromeProxyResolver::GetProxyType(kNoProxy, &type));
- EXPECT_FALSE(ChromeProxyResolver::GetProxyType("foo://", &type));
- EXPECT_FALSE(ChromeProxyResolver::GetProxyType("missing.com:8", &type));
-}
-
-} // namespace chromeos_update_engine
diff --git a/libcurl_http_fetcher.cc b/libcurl_http_fetcher.cc
index 7d82462..c095504 100644
--- a/libcurl_http_fetcher.cc
+++ b/libcurl_http_fetcher.cc
@@ -12,7 +12,6 @@
#include <base/stringprintf.h>
#include "update_engine/certificate_checker.h"
-#include "update_engine/chrome_proxy_resolver.h"
#include "update_engine/dbus_interface.h"
#include "update_engine/utils.h"
@@ -59,6 +58,30 @@
return force_build_type_ ? forced_official_build_ : utils::IsOfficialBuild();
}
+bool LibcurlHttpFetcher::GetProxyType(const std::string& proxy,
+ curl_proxytype* out_type) {
+ if (utils::StringHasPrefix(proxy, "socks5://") ||
+ utils::StringHasPrefix(proxy, "socks://")) {
+ *out_type = CURLPROXY_SOCKS5_HOSTNAME;
+ return true;
+ }
+ if (utils::StringHasPrefix(proxy, "socks4://")) {
+ *out_type = CURLPROXY_SOCKS4A;
+ return true;
+ }
+ if (utils::StringHasPrefix(proxy, "http://") ||
+ utils::StringHasPrefix(proxy, "https://")) {
+ *out_type = CURLPROXY_HTTP;
+ return true;
+ }
+ if (utils::StringHasPrefix(proxy, kNoProxy)) {
+ // known failure case. don't log.
+ return false;
+ }
+ LOG(INFO) << "Unknown proxy type: " << proxy;
+ return false;
+}
+
void LibcurlHttpFetcher::ResumeTransfer(const std::string& url) {
LOG(INFO) << "Starting/Resuming transfer";
CHECK(!transfer_in_progress_);
@@ -82,7 +105,7 @@
GetCurrentProxy().c_str()), CURLE_OK);
// Curl seems to require us to set the protocol
curl_proxytype type;
- if (ChromeProxyResolver::GetProxyType(GetCurrentProxy(), &type)) {
+ if (GetProxyType(GetCurrentProxy(), &type)) {
CHECK_EQ(curl_easy_setopt(curl_handle_,
CURLOPT_PROXYTYPE,
type), CURLE_OK);
diff --git a/libcurl_http_fetcher.h b/libcurl_http_fetcher.h
index 7dba810..07753a8 100644
--- a/libcurl_http_fetcher.h
+++ b/libcurl_http_fetcher.h
@@ -197,6 +197,11 @@
// Sets the curl options for HTTPS URL.
void SetCurlOptionsForHttps();
+ // Convert a proxy URL into a curl proxy type, if applicable. Returns true iff
+ // conversion was successful, false otherwise (in which case nothing is
+ // written to |out_type|).
+ bool GetProxyType(const std::string& proxy, curl_proxytype* out_type);
+
// Handles for the libcurl library
CURLM *curl_multi_handle_;
CURL *curl_handle_;