GoogleGit

blob: 86a596c7a1af32ce5a207b89abb623db92c188f2 [file] [log] [blame]
  1. // Copyright (c) 2010 The Chromium 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. #include "net/proxy/proxy_config_service_android.h"
  5. #include "net/proxy/proxy_config.h"
  6. namespace net {
  7. void ProxyConfigServiceAndroid::AddObserver(Observer* observer) {
  8. observers_.AddObserver(observer);
  9. }
  10. void ProxyConfigServiceAndroid::RemoveObserver(Observer* observer) {
  11. observers_.RemoveObserver(observer);
  12. }
  13. ProxyConfigService::ConfigAvailability ProxyConfigServiceAndroid::GetLatestProxyConfig(ProxyConfig* config) {
  14. if (!config)
  15. return ProxyConfigService::CONFIG_UNSET;
  16. if (m_proxy.empty()) {
  17. *config = ProxyConfig::CreateDirect();
  18. } else {
  19. config->proxy_rules().ParseFromString(m_proxy);
  20. }
  21. return ProxyConfigService::CONFIG_VALID;
  22. }
  23. void ProxyConfigServiceAndroid::UpdateProxySettings(std::string& proxy,
  24. std::string& exList) {
  25. if (proxy == m_proxy)
  26. return;
  27. m_proxy = proxy;
  28. ProxyConfig config;
  29. config.proxy_rules().ParseFromString(m_proxy);
  30. size_t pos;
  31. while ( (pos = exList.find(',')) != std::string::npos) {
  32. config.proxy_rules().bypass_rules.AddRuleFromString(exList.substr(0, pos));
  33. exList.erase(0, pos + 1);
  34. }
  35. config.proxy_rules().bypass_rules.AddRuleFromString(exList);
  36. FOR_EACH_OBSERVER(Observer, observers_,
  37. OnProxyConfigChanged(config,
  38. ProxyConfigService::CONFIG_VALID));
  39. }
  40. } // namespace net