1aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// 2aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// Copyright (C) 2011 The Android Open Source Project 3aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// 4aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// Licensed under the Apache License, Version 2.0 (the "License"); 5aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// you may not use this file except in compliance with the License. 6aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// You may obtain a copy of the License at 7aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// 8aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// http://www.apache.org/licenses/LICENSE-2.0 9aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// 10aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// Unless required by applicable law or agreed to in writing, software 11aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// distributed under the License is distributed on an "AS IS" BASIS, 12aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// See the License for the specific language governing permissions and 14aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// limitations under the License. 15aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// 16000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes 17cf175a098081f3f0e9ca52d997a7ce1585c14c2dGilad Arnold#ifndef UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H_ 18cf175a098081f3f0e9ca52d997a7ce1585c14c2dGilad Arnold#define UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H_ 19000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes 20d2779df63aaad8b65fc5d4badee7dbc9bed7f2b6Alex Vakulenko#include <deque> 21000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes#include <string> 22000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes 23000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes#include <gtest/gtest_prod.h> // for FRIEND_TEST 24000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes 253f39d5cc753905874d8d93bef94f857b8808f19eAlex Vakulenko#include <brillo/message_loops/message_loop.h> 2660ca1a7bca7cc804ec80b510483081ef894de4cdAlex Deymo 27305345001d85ca2282112c2a30fe75c7a4773491Alex Deymo#include "update_engine/libcros_proxy.h" 28000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes#include "update_engine/proxy_resolver.h" 29000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes 30000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyesnamespace chromeos_update_engine { 31000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes 32000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyesextern const char kLibCrosServiceName[]; 33000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyesextern const char kLibCrosProxyResolveName[]; 34000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyesextern const char kLibCrosProxyResolveSignalInterface[]; 35000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes 36000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyesclass ChromeBrowserProxyResolver : public ProxyResolver { 37000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes public: 38305345001d85ca2282112c2a30fe75c7a4773491Alex Deymo explicit ChromeBrowserProxyResolver(LibCrosProxy* libcros_proxy); 39610277efc6f7e5239158dfa4bb3b1021804326e0Alex Deymo ~ChromeBrowserProxyResolver() override; 40305345001d85ca2282112c2a30fe75c7a4773491Alex Deymo 41305345001d85ca2282112c2a30fe75c7a4773491Alex Deymo // Initialize the ProxyResolver using the provided DBus proxies. 42000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes bool Init(); 43000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes 443582194c10c47ffcda9ad7881e7fa6eed2404406Alex Deymo ProxyRequestId GetProxiesForUrl(const std::string& url, 453582194c10c47ffcda9ad7881e7fa6eed2404406Alex Deymo const ProxiesResolvedFn& callback) override; 463582194c10c47ffcda9ad7881e7fa6eed2404406Alex Deymo bool CancelProxyRequest(ProxyRequestId request) override; 47000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes 48000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes private: 49000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes FRIEND_TEST(ChromeBrowserProxyResolverTest, ParseTest); 50000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes FRIEND_TEST(ChromeBrowserProxyResolverTest, SuccessTest); 513582194c10c47ffcda9ad7881e7fa6eed2404406Alex Deymo struct ProxyRequestData { 523582194c10c47ffcda9ad7881e7fa6eed2404406Alex Deymo brillo::MessageLoop::TaskId timeout_id; 533582194c10c47ffcda9ad7881e7fa6eed2404406Alex Deymo ProxiesResolvedFn callback; 543582194c10c47ffcda9ad7881e7fa6eed2404406Alex Deymo }; 553582194c10c47ffcda9ad7881e7fa6eed2404406Alex Deymo typedef std::multimap<std::string, std::unique_ptr<ProxyRequestData>> 56f9cb98c0cacccca803db48502c7bd461d04cb6b0Ben Chan CallbacksMap; 57000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes 58305345001d85ca2282112c2a30fe75c7a4773491Alex Deymo // Called when the signal in UpdateEngineLibcrosProxyResolvedInterface is 59305345001d85ca2282112c2a30fe75c7a4773491Alex Deymo // connected. 60305345001d85ca2282112c2a30fe75c7a4773491Alex Deymo void OnSignalConnected(const std::string& interface_name, 61305345001d85ca2282112c2a30fe75c7a4773491Alex Deymo const std::string& signal_name, 62305345001d85ca2282112c2a30fe75c7a4773491Alex Deymo bool successful); 63305345001d85ca2282112c2a30fe75c7a4773491Alex Deymo 64000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes // Handle a reply from Chrome: 65305345001d85ca2282112c2a30fe75c7a4773491Alex Deymo void OnProxyResolvedSignal(const std::string& source_url, 66305345001d85ca2282112c2a30fe75c7a4773491Alex Deymo const std::string& proxy_info, 67305345001d85ca2282112c2a30fe75c7a4773491Alex Deymo const std::string& error_message); 68305345001d85ca2282112c2a30fe75c7a4773491Alex Deymo 693582194c10c47ffcda9ad7881e7fa6eed2404406Alex Deymo // Handle no reply. The |request| pointer points to the ProxyRequestData in 703582194c10c47ffcda9ad7881e7fa6eed2404406Alex Deymo // the |callbacks_| map that triggered this timeout. 713582194c10c47ffcda9ad7881e7fa6eed2404406Alex Deymo void HandleTimeout(std::string source_url, ProxyRequestData* request); 72d2779df63aaad8b65fc5d4badee7dbc9bed7f2b6Alex Vakulenko 73000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes // Parses a string-encoded list of proxies and returns a deque 74000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes // of individual proxies. The last one will always be kNoProxy. 75000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes static std::deque<std::string> ParseProxyString(const std::string& input); 76d2779df63aaad8b65fc5d4badee7dbc9bed7f2b6Alex Vakulenko 773582194c10c47ffcda9ad7881e7fa6eed2404406Alex Deymo // Process a proxy response by calling all the callbacks associated with the 783582194c10c47ffcda9ad7881e7fa6eed2404406Alex Deymo // passed |source_url|. All the timeouts associated with these callbacks will 793582194c10c47ffcda9ad7881e7fa6eed2404406Alex Deymo // be removed. 803582194c10c47ffcda9ad7881e7fa6eed2404406Alex Deymo void ProcessUrlResponse(const std::string& source_url, 813582194c10c47ffcda9ad7881e7fa6eed2404406Alex Deymo const std::deque<std::string>& proxies); 82000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes 831877c3938afb2cc46c959d1158316671cf3460d9Gilad Arnold // Shutdown the dbus proxy object. 841877c3938afb2cc46c959d1158316671cf3460d9Gilad Arnold void Shutdown(); 851877c3938afb2cc46c959d1158316671cf3460d9Gilad Arnold 86305345001d85ca2282112c2a30fe75c7a4773491Alex Deymo // DBus proxies to request a HTTP proxy resolution. The request is done in the 87305345001d85ca2282112c2a30fe75c7a4773491Alex Deymo // service_interface_proxy() interface and the response is received as a 88305345001d85ca2282112c2a30fe75c7a4773491Alex Deymo // signal in the ue_proxy_resolved_interface(). 89305345001d85ca2282112c2a30fe75c7a4773491Alex Deymo LibCrosProxy* libcros_proxy_; 90305345001d85ca2282112c2a30fe75c7a4773491Alex Deymo 91000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes int timeout_; 92000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes CallbacksMap callbacks_; 93000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes DISALLOW_COPY_AND_ASSIGN(ChromeBrowserProxyResolver); 94000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes}; 95000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes 96000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes} // namespace chromeos_update_engine 97000d895da247697f4e4e0c67a3a847f71fca8eb9Andrew de los Reyes 98cf175a098081f3f0e9ca52d997a7ce1585c14c2dGilad Arnold#endif // UPDATE_ENGINE_CHROME_BROWSER_PROXY_RESOLVER_H_ 99