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

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

Issue 159297: linux: generalize desktop environment guessing to encompass KDE (Closed)
Patch Set: 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"
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 return true; 497 return true;
498 } 498 }
499 499
500 ProxyConfigServiceLinux::Delegate::Delegate( 500 ProxyConfigServiceLinux::Delegate::Delegate(
501 base::EnvironmentVariableGetter* env_var_getter, 501 base::EnvironmentVariableGetter* env_var_getter,
502 GConfSettingGetter* gconf_getter) 502 GConfSettingGetter* gconf_getter)
503 : env_var_getter_(env_var_getter), gconf_getter_(gconf_getter), 503 : env_var_getter_(env_var_getter), gconf_getter_(gconf_getter),
504 glib_default_loop_(NULL), io_loop_(NULL) { 504 glib_default_loop_(NULL), io_loop_(NULL) {
505 } 505 }
506 506
507 bool ProxyConfigServiceLinux::Delegate::ShouldTryGConf() {
508 // I (sdoyon) would have liked to prioritize environment variables
509 // and only fallback to gconf if env vars were unset. But
510 // gnome-terminal "helpfully" sets http_proxy and no_proxy, and it
511 // does so even if the proxy mode is set to auto, which would
512 // mislead us.
513 //
514 // We could introduce a CHROME_PROXY_OBEY_ENV_VARS variable...??
515 return base::UseGnomeForSettings(env_var_getter_.get());
516 }
517
518 void ProxyConfigServiceLinux::Delegate::SetupAndFetchInitialConfig( 507 void ProxyConfigServiceLinux::Delegate::SetupAndFetchInitialConfig(
519 MessageLoop* glib_default_loop, MessageLoop* io_loop) { 508 MessageLoop* glib_default_loop, MessageLoop* io_loop) {
520 // We should be running on the default glib main loop thread right 509 // We should be running on the default glib main loop thread right
521 // now. gconf can only be accessed from this thread. 510 // now. gconf can only be accessed from this thread.
522 DCHECK(MessageLoop::current() == glib_default_loop); 511 DCHECK(MessageLoop::current() == glib_default_loop);
523 glib_default_loop_ = glib_default_loop; 512 glib_default_loop_ = glib_default_loop;
524 io_loop_ = io_loop; 513 io_loop_ = io_loop;
525 514
526 // If we are passed a NULL io_loop, then we don't setup gconf 515 // If we are passed a NULL io_loop, then we don't setup gconf
527 // notifications. This should not be the usual case but is intended 516 // notifications. This should not be the usual case but is intended
528 // to simplify test setups. 517 // to simplify test setups.
529 if (!io_loop_) 518 if (!io_loop_)
530 LOG(INFO) << "Monitoring of gconf setting changes is disabled"; 519 LOG(INFO) << "Monitoring of gconf setting changes is disabled";
531 520
532 // Fetch and cache the current proxy config. The config is left in 521 // Fetch and cache the current proxy config. The config is left in
533 // cached_config_, where GetProxyConfig() running on the IO thread 522 // cached_config_, where GetProxyConfig() running on the IO thread
534 // will expect to find it. This is safe to do because we return 523 // will expect to find it. This is safe to do because we return
535 // before this ProxyConfigServiceLinux is passed on to 524 // before this ProxyConfigServiceLinux is passed on to
536 // the ProxyService. 525 // the ProxyService.
526
527 // Note: It would be nice to prioritize environment variables
528 // and only fallback to gconf if env vars were unset. But
529 // gnome-terminal "helpfully" sets http_proxy and no_proxy, and it
530 // does so even if the proxy mode is set to auto, which would
531 // mislead us.
532
537 bool got_config = false; 533 bool got_config = false;
538 if (ShouldTryGConf() && 534 switch (base::GetDesktopEnvironment(env_var_getter_.get())) {
539 gconf_getter_->Init() && 535 case base::DESKTOP_ENVIRONMENT_GNOME:
540 (!io_loop || gconf_getter_->SetupNotification(this))) { 536 if (gconf_getter_->Init() &&
541 if (GetConfigFromGConf(&cached_config_)) { 537 (!io_loop || gconf_getter_->SetupNotification(this))) {
542 cached_config_.set_id(1); // mark it as valid 538 if (GetConfigFromGConf(&cached_config_)) {
543 got_config = true; 539 cached_config_.set_id(1); // mark it as valid
544 LOG(INFO) << "Obtained proxy setting from gconf"; 540 got_config = true;
545 // If gconf proxy mode is "none", meaning direct, then we take 541 LOG(INFO) << "Obtained proxy setting from gconf";
546 // that to be a valid config and will not check environment 542 // If gconf proxy mode is "none", meaning direct, then we take
547 // variables. The alternative would have been to look for a proxy 543 // that to be a valid config and will not check environment
548 // where ever we can find one. 544 // variables. The alternative would have been to look for a proxy
549 // 545 // where ever we can find one.
550 // Keep a copy of the config for use from this thread for 546 //
551 // comparison with updated settings when we get notifications. 547 // Keep a copy of the config for use from this thread for
552 reference_config_ = cached_config_; 548 // comparison with updated settings when we get notifications.
553 reference_config_.set_id(1); // mark it as valid 549 reference_config_ = cached_config_;
554 } else { 550 reference_config_.set_id(1); // mark it as valid
555 gconf_getter_->Release(); // Stop notifications 551 } else {
556 } 552 gconf_getter_->Release(); // Stop notifications
553 }
554 }
555 break;
556
557 case base::DESKTOP_ENVIRONMENT_KDE:
558 NOTIMPLEMENTED() << "Bug 17363: obey KDE proxy settings.";
559 break;
560
561 case base::DESKTOP_ENVIRONMENT_OTHER:
562 break;
557 } 563 }
564
558 if (!got_config) { 565 if (!got_config) {
559 // An implementation for KDE settings would be welcome here. 566 // We fall back on environment variables.
560 // 567 //
561 // Consulting environment variables doesn't need to be done from 568 // Consulting environment variables doesn't need to be done from
562 // the default glib main loop, but it's a tiny enough amount of 569 // the default glib main loop, but it's a tiny enough amount of
563 // work. 570 // work.
564 if (GetConfigFromEnv(&cached_config_)) { 571 if (GetConfigFromEnv(&cached_config_)) {
565 cached_config_.set_id(1); // mark it as valid 572 cached_config_.set_id(1); // mark it as valid
566 LOG(INFO) << "Obtained proxy setting from environment variables"; 573 LOG(INFO) << "Obtained proxy setting from environment variables";
567 } 574 }
568 } 575 }
569 } 576 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 new GConfSettingGetterImpl())) { 648 new GConfSettingGetterImpl())) {
642 } 649 }
643 650
644 ProxyConfigServiceLinux::ProxyConfigServiceLinux( 651 ProxyConfigServiceLinux::ProxyConfigServiceLinux(
645 base::EnvironmentVariableGetter* env_var_getter, 652 base::EnvironmentVariableGetter* env_var_getter,
646 GConfSettingGetter* gconf_getter) 653 GConfSettingGetter* gconf_getter)
647 : delegate_(new Delegate(env_var_getter, gconf_getter)) { 654 : delegate_(new Delegate(env_var_getter, gconf_getter)) {
648 } 655 }
649 656
650 } // namespace net 657 } // 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