blob: 2df751e38f401c752695ea270466a01fe4505a1b [file] [log] [blame]
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -08001// 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
3// found in the LICENSE file.
4
5#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_CHROME_PROXY_RESOLVER_H__
6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_CHROME_PROXY_RESOLVER_H__
7
Andrew de los Reyes45168102010-11-22 11:13:50 -08008#include <deque>
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -08009#include <string>
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -080010
11#include <curl/curl.h>
12#include <gtest/gtest_prod.h> // for FRIEND_TEST
13
14#include "update_engine/dbus_interface.h"
15#include "update_engine/proxy_resolver.h"
16
17namespace chromeos_update_engine {
18
19extern const char kSessionManagerService[];
20extern const char kSessionManagerPath[];
21extern const char kSessionManagerInterface[];
22extern const char kSessionManagerRetrievePropertyMethod[];
23extern const char kSessionManagerProxySettingsKey[];
24
25// Class to resolve proxy for a url based on Chrome's proxy settings.
26
27// Currently only supports manual settings, not PAC files or autodetected
28// settings.
29
Andrew de los Reyesf3ed8e72011-02-16 10:35:46 -080030struct ChromeProxyResolverClosureArgs {
31 std::string url;
32 ProxiesResolvedFn callback;
33 void* data;
34};
35
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -080036class ChromeProxyResolver : public ProxyResolver {
37 public:
38 explicit ChromeProxyResolver(DbusGlibInterface* dbus) : dbus_(dbus) {}
39 virtual ~ChromeProxyResolver() {}
40
41 virtual bool GetProxiesForUrl(const std::string& url,
Andrew de los Reyesf3ed8e72011-02-16 10:35:46 -080042 ProxiesResolvedFn callback,
43 void* data);
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -080044
45 // Get the curl proxy type for a given proxy url. Returns true on success.
46 // Note: if proxy is kNoProxy, this will return false.
Andrew de los Reyes45168102010-11-22 11:13:50 -080047 static bool GetProxyType(const std::string& proxy, curl_proxytype* out_type);
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -080048
49 private:
50 FRIEND_TEST(ChromeProxyResolverTest, GetProxiesForUrlWithSettingsTest);
51
Andrew de los Reyesf3ed8e72011-02-16 10:35:46 -080052 // Closure callback, so we can pretend we need to wait on the main loop
53 // before returing proxies to the client.
54 void GetProxiesForUrlCallback(ChromeProxyResolverClosureArgs args);
55
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -080056 // Fetches a dbus proxy to session manager. Returns NULL on failure.
57 DBusGProxy* DbusProxy();
58
59 // Fetches the json-encoded proxy settings string from the session manager.
60 bool GetJsonProxySettings(DBusGProxy* proxy, std::string* out_json);
61
62 // Given a |url| and the json encoded settings |json_settings|,
63 // returns the proper proxy servers in |out_proxies|. Returns true on
64 // success.
65 bool GetProxiesForUrlWithSettings(const std::string& url,
66 const std::string& json_settings,
Andrew de los Reyes45168102010-11-22 11:13:50 -080067 std::deque<std::string>* out_proxies);
Andrew de los Reyes9cd120d2010-11-18 17:50:03 -080068
69 DbusGlibInterface* dbus_;
70
71 DISALLOW_COPY_AND_ASSIGN(ChromeProxyResolver);
72};
73
74} // namespace chromeos_update_engine
75
76#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_CHROME_PROXY_RESOLVER_H__