Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(419)

Side by Side Diff: net/proxy/proxy_config_service_linux.cc

Issue 155792: Try again: Add proxy config (using gnome-network-preferences) (Closed)
Patch Set: nits fixed Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/proxy/proxy_config_service_linux.h" 5 #include "net/proxy/proxy_config_service_linux.h"
6 6
7 #include <gconf/gconf-client.h> 7 #include <gconf/gconf-client.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/string_tokenizer.h" 11 #include "base/string_tokenizer.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/task.h" 13 #include "base/task.h"
14 #include "googleurl/src/url_canon.h" 14 #include "googleurl/src/url_canon.h"
15 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
16 #include "net/http/http_util.h" 16 #include "net/http/http_util.h"
17 #include "net/proxy/proxy_config.h" 17 #include "net/proxy/proxy_config.h"
18 #include "net/proxy/proxy_server.h" 18 #include "net/proxy/proxy_server.h"
19 19
20 namespace net { 20 namespace net {
21 21
22 namespace { 22 namespace {
23 23
24 class EnvironmentVariableGetterImpl
25 : public ProxyConfigServiceLinux::EnvironmentVariableGetter {
26 public:
27 virtual bool Getenv(const char* variable_name, std::string* result) {
28 const char* env_value = ::getenv(variable_name);
29 if (env_value) {
30 // Note that the variable may be defined but empty.
31 *result = env_value;
32 return true;
33 }
34 // Some commonly used variable names are uppercase while others
35 // are lowercase, which is inconsistent. Let's try to be helpful
36 // and look for a variable name with the reverse case.
37 char first_char = variable_name[0];
38 std::string alternate_case_var;
39 if (first_char >= 'a' && first_char <= 'z')
40 alternate_case_var = StringToUpperASCII(std::string(variable_name));
41 else if (first_char >= 'A' && first_char <= 'Z')
42 alternate_case_var = StringToLowerASCII(std::string(variable_name));
43 else
44 return false;
45 env_value = ::getenv(alternate_case_var.c_str());
46 if (env_value) {
47 *result = env_value;
48 return true;
49 }
50 return false;
51 }
52 };
53
54 // Given a proxy hostname from a setting, returns that hostname with 24 // Given a proxy hostname from a setting, returns that hostname with
55 // an appropriate proxy server scheme prefix. 25 // an appropriate proxy server scheme prefix.
56 // scheme indicates the desired proxy scheme: usually http, with 26 // scheme indicates the desired proxy scheme: usually http, with
57 // socks 4 or 5 as special cases. 27 // socks 4 or 5 as special cases.
58 // TODO(arindam): Remove URI string manipulation by using MapUrlSchemeToProxy. 28 // TODO(arindam): Remove URI string manipulation by using MapUrlSchemeToProxy.
59 std::string FixupProxyHostScheme(ProxyServer::Scheme scheme, 29 std::string FixupProxyHostScheme(ProxyServer::Scheme scheme,
60 std::string host) { 30 std::string host) {
61 if (scheme == ProxyServer::SCHEME_SOCKS4 && 31 if (scheme == ProxyServer::SCHEME_SOCKS4 &&
62 StartsWithASCII(host, "socks5://", false)) { 32 StartsWithASCII(host, "socks5://", false)) {
63 // We default to socks 4, but if the user specifically set it to 33 // We default to socks 4, but if the user specifically set it to
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 // Now the bypass list. 491 // Now the bypass list.
522 gconf_getter_->GetStringList("/system/http_proxy/ignore_hosts", 492 gconf_getter_->GetStringList("/system/http_proxy/ignore_hosts",
523 &config->proxy_bypass); 493 &config->proxy_bypass);
524 // Note that there are no settings with semantics corresponding to 494 // Note that there are no settings with semantics corresponding to
525 // config->proxy_bypass_local_names. 495 // config->proxy_bypass_local_names.
526 496
527 return true; 497 return true;
528 } 498 }
529 499
530 ProxyConfigServiceLinux::Delegate::Delegate( 500 ProxyConfigServiceLinux::Delegate::Delegate(
531 EnvironmentVariableGetter* env_var_getter, 501 base::EnvironmentVariableGetter* env_var_getter,
532 GConfSettingGetter* gconf_getter) 502 GConfSettingGetter* gconf_getter)
533 : env_var_getter_(env_var_getter), gconf_getter_(gconf_getter), 503 : env_var_getter_(env_var_getter), gconf_getter_(gconf_getter),
534 glib_default_loop_(NULL), io_loop_(NULL) { 504 glib_default_loop_(NULL), io_loop_(NULL) {
535 } 505 }
536 506
537 bool ProxyConfigServiceLinux::Delegate::ShouldTryGConf() { 507 bool ProxyConfigServiceLinux::Delegate::ShouldTryGConf() {
538 // GNOME_DESKTOP_SESSION_ID being defined is a good indication that
539 // we are probably running under GNOME.
540 // Note: KDE_FULL_SESSION is a corresponding env var to recognize KDE.
541 std::string dummy, desktop_session;
542 return env_var_getter_->Getenv("GNOME_DESKTOP_SESSION_ID", &dummy)
543 || (env_var_getter_->Getenv("DESKTOP_SESSION", &desktop_session)
544 && desktop_session == "gnome");
545 // I (sdoyon) would have liked to prioritize environment variables 508 // I (sdoyon) would have liked to prioritize environment variables
eroman 2009/07/22 00:33:30 seems this comment should be moved into UseGnomeFo
546 // and only fallback to gconf if env vars were unset. But 509 // and only fallback to gconf if env vars were unset. But
547 // gnome-terminal "helpfully" sets http_proxy and no_proxy, and it 510 // gnome-terminal "helpfully" sets http_proxy and no_proxy, and it
548 // does so even if the proxy mode is set to auto, which would 511 // does so even if the proxy mode is set to auto, which would
549 // mislead us. 512 // mislead us.
550 // 513 //
551 // We could introduce a CHROME_PROXY_OBEY_ENV_VARS variable...?? 514 // We could introduce a CHROME_PROXY_OBEY_ENV_VARS variable...??
515 return base::UseGnomeForSettings(env_var_getter_.get());
552 } 516 }
553 517
554 void ProxyConfigServiceLinux::Delegate::SetupAndFetchInitialConfig( 518 void ProxyConfigServiceLinux::Delegate::SetupAndFetchInitialConfig(
555 MessageLoop* glib_default_loop, MessageLoop* io_loop) { 519 MessageLoop* glib_default_loop, MessageLoop* io_loop) {
556 // We should be running on the default glib main loop thread right 520 // We should be running on the default glib main loop thread right
557 // now. gconf can only be accessed from this thread. 521 // now. gconf can only be accessed from this thread.
558 DCHECK(MessageLoop::current() == glib_default_loop); 522 DCHECK(MessageLoop::current() == glib_default_loop);
559 glib_default_loop_ = glib_default_loop; 523 glib_default_loop_ = glib_default_loop;
560 io_loop_ = io_loop; 524 io_loop_ = io_loop;
561 525
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 this, 630 this,
667 &ProxyConfigServiceLinux::Delegate::OnDestroy)); 631 &ProxyConfigServiceLinux::Delegate::OnDestroy));
668 } 632 }
669 } 633 }
670 void ProxyConfigServiceLinux::Delegate::OnDestroy() { 634 void ProxyConfigServiceLinux::Delegate::OnDestroy() {
671 DCHECK(!glib_default_loop_ || MessageLoop::current() == glib_default_loop_); 635 DCHECK(!glib_default_loop_ || MessageLoop::current() == glib_default_loop_);
672 gconf_getter_->Release(); 636 gconf_getter_->Release();
673 } 637 }
674 638
675 ProxyConfigServiceLinux::ProxyConfigServiceLinux() 639 ProxyConfigServiceLinux::ProxyConfigServiceLinux()
676 : delegate_(new Delegate(new EnvironmentVariableGetterImpl(), 640 : delegate_(new Delegate(base::EnvironmentVariableGetter::Create(),
677 new GConfSettingGetterImpl())) { 641 new GConfSettingGetterImpl())) {
678 } 642 }
679 643
680 ProxyConfigServiceLinux::ProxyConfigServiceLinux( 644 ProxyConfigServiceLinux::ProxyConfigServiceLinux(
681 EnvironmentVariableGetter* env_var_getter, 645 base::EnvironmentVariableGetter* env_var_getter,
682 GConfSettingGetter* gconf_getter) 646 GConfSettingGetter* gconf_getter)
683 : delegate_(new Delegate(env_var_getter, gconf_getter)) { 647 : delegate_(new Delegate(env_var_getter, gconf_getter)) {
684 } 648 }
685 649
686 } // namespace net 650 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_config_service_linux.h ('k') | net/proxy/proxy_config_service_linux_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698