Home | History | Annotate | Download | only in proxy
      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 
      5 #include "net/proxy/proxy_config_service_android.h"
      6 
      7 #include "net/proxy/proxy_config.h"
      8 
      9 namespace net {
     10 
     11 void ProxyConfigServiceAndroid::AddObserver(Observer* observer) {
     12   observers_.AddObserver(observer);
     13 }
     14 
     15 void ProxyConfigServiceAndroid::RemoveObserver(Observer* observer) {
     16   observers_.RemoveObserver(observer);
     17 }
     18 
     19 ProxyConfigService::ConfigAvailability ProxyConfigServiceAndroid::GetLatestProxyConfig(ProxyConfig* config) {
     20   if (!config)
     21     return ProxyConfigService::CONFIG_UNSET;
     22 
     23   if (m_proxy.empty()) {
     24     *config = ProxyConfig::CreateDirect();
     25   } else {
     26     config->proxy_rules().ParseFromString(m_proxy);
     27   }
     28   return ProxyConfigService::CONFIG_VALID;
     29 }
     30 
     31 void ProxyConfigServiceAndroid::UpdateProxySettings(std::string& proxy,
     32                                                     std::string& exList) {
     33   if (proxy == m_proxy)
     34     return;
     35 
     36   m_proxy = proxy;
     37   ProxyConfig config;
     38   config.proxy_rules().ParseFromString(m_proxy);
     39 
     40   size_t pos;
     41   while ( (pos = exList.find(',')) != std::string::npos) {
     42     config.proxy_rules().bypass_rules.AddRuleFromString(exList.substr(0, pos));
     43     exList.erase(0, pos + 1);
     44   }
     45   config.proxy_rules().bypass_rules.AddRuleFromString(exList);
     46 
     47   FOR_EACH_OBSERVER(Observer, observers_,
     48                     OnProxyConfigChanged(config,
     49                                          ProxyConfigService::CONFIG_VALID));
     50 }
     51 
     52 } // namespace net
     53