| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <gconf/gconf-client.h> | 9 #include <gconf/gconf-client.h> |
| 10 #include <limits.h> | 10 #include <limits.h> |
| 11 #include <stdio.h> | 11 #include <stdio.h> |
| 12 #include <stdlib.h> | 12 #include <stdlib.h> |
| 13 #include <sys/inotify.h> | 13 #include <sys/inotify.h> |
| 14 #include <unistd.h> | 14 #include <unistd.h> |
| 15 | 15 |
| 16 #include <map> | 16 #include <map> |
| 17 | 17 |
| 18 #include "base/env_var.h" | 18 #include "base/environment.h" |
| 19 #include "base/file_path.h" | 19 #include "base/file_path.h" |
| 20 #include "base/file_util.h" | 20 #include "base/file_util.h" |
| 21 #include "base/logging.h" | 21 #include "base/logging.h" |
| 22 #include "base/message_loop.h" | 22 #include "base/message_loop.h" |
| 23 #include "base/string_number_conversions.h" | 23 #include "base/string_number_conversions.h" |
| 24 #include "base/string_tokenizer.h" | 24 #include "base/string_tokenizer.h" |
| 25 #include "base/string_util.h" | 25 #include "base/string_util.h" |
| 26 #include "base/task.h" | 26 #include "base/task.h" |
| 27 #include "base/timer.h" | 27 #include "base/timer.h" |
| 28 #include "base/xdg_util.h" | 28 #include "base/xdg_util.h" |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 DISALLOW_COPY_AND_ASSIGN(GConfSettingGetterImplGConf); | 415 DISALLOW_COPY_AND_ASSIGN(GConfSettingGetterImplGConf); |
| 416 }; | 416 }; |
| 417 | 417 |
| 418 // This is the KDE version that reads kioslaverc and simulates gconf. | 418 // This is the KDE version that reads kioslaverc and simulates gconf. |
| 419 // Doing this allows the main Delegate code, as well as the unit tests | 419 // Doing this allows the main Delegate code, as well as the unit tests |
| 420 // for it, to stay the same - and the settings map fairly well besides. | 420 // for it, to stay the same - and the settings map fairly well besides. |
| 421 class GConfSettingGetterImplKDE | 421 class GConfSettingGetterImplKDE |
| 422 : public ProxyConfigServiceLinux::GConfSettingGetter, | 422 : public ProxyConfigServiceLinux::GConfSettingGetter, |
| 423 public base::MessagePumpLibevent::Watcher { | 423 public base::MessagePumpLibevent::Watcher { |
| 424 public: | 424 public: |
| 425 explicit GConfSettingGetterImplKDE(base::EnvVarGetter* env_var_getter) | 425 explicit GConfSettingGetterImplKDE(base::Environment* env_var_getter) |
| 426 : inotify_fd_(-1), notify_delegate_(NULL), indirect_manual_(false), | 426 : inotify_fd_(-1), notify_delegate_(NULL), indirect_manual_(false), |
| 427 auto_no_pac_(false), reversed_bypass_list_(false), | 427 auto_no_pac_(false), reversed_bypass_list_(false), |
| 428 env_var_getter_(env_var_getter), file_loop_(NULL) { | 428 env_var_getter_(env_var_getter), file_loop_(NULL) { |
| 429 // Derive the location of the kde config dir from the environment. | 429 // Derive the location of the kde config dir from the environment. |
| 430 std::string home; | 430 std::string home; |
| 431 if (env_var_getter->GetEnv("KDEHOME", &home) && !home.empty()) { | 431 if (env_var_getter->GetEnv("KDEHOME", &home) && !home.empty()) { |
| 432 // $KDEHOME is set. Use it unconditionally. | 432 // $KDEHOME is set. Use it unconditionally. |
| 433 kde_config_dir_ = KDEHomeToConfigPath(FilePath(home)); | 433 kde_config_dir_ = KDEHomeToConfigPath(FilePath(home)); |
| 434 } else { | 434 } else { |
| 435 // $KDEHOME is unset. Try to figure out what to use. This seems to be | 435 // $KDEHOME is unset. Try to figure out what to use. This seems to be |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 base::MessagePumpLibevent::FileDescriptorWatcher inotify_watcher_; | 872 base::MessagePumpLibevent::FileDescriptorWatcher inotify_watcher_; |
| 873 ProxyConfigServiceLinux::Delegate* notify_delegate_; | 873 ProxyConfigServiceLinux::Delegate* notify_delegate_; |
| 874 base::OneShotTimer<GConfSettingGetterImplKDE> debounce_timer_; | 874 base::OneShotTimer<GConfSettingGetterImplKDE> debounce_timer_; |
| 875 FilePath kde_config_dir_; | 875 FilePath kde_config_dir_; |
| 876 bool indirect_manual_; | 876 bool indirect_manual_; |
| 877 bool auto_no_pac_; | 877 bool auto_no_pac_; |
| 878 bool reversed_bypass_list_; | 878 bool reversed_bypass_list_; |
| 879 // We don't own |env_var_getter_|. It's safe to hold a pointer to it, since | 879 // We don't own |env_var_getter_|. It's safe to hold a pointer to it, since |
| 880 // both it and us are owned by ProxyConfigServiceLinux::Delegate, and have the | 880 // both it and us are owned by ProxyConfigServiceLinux::Delegate, and have the |
| 881 // same lifetime. | 881 // same lifetime. |
| 882 base::EnvVarGetter* env_var_getter_; | 882 base::Environment* env_var_getter_; |
| 883 | 883 |
| 884 // We cache these settings whenever we re-read the kioslaverc file. | 884 // We cache these settings whenever we re-read the kioslaverc file. |
| 885 string_map_type string_table_; | 885 string_map_type string_table_; |
| 886 strings_map_type strings_table_; | 886 strings_map_type strings_table_; |
| 887 | 887 |
| 888 // Message loop of the file thread, for reading kioslaverc. If NULL, | 888 // Message loop of the file thread, for reading kioslaverc. If NULL, |
| 889 // just read it directly (for testing). We also handle inotify events | 889 // just read it directly (for testing). We also handle inotify events |
| 890 // on this thread. | 890 // on this thread. |
| 891 MessageLoopForIO* file_loop_; | 891 MessageLoopForIO* file_loop_; |
| 892 | 892 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1044 // Note that there are no settings with semantics corresponding to | 1044 // Note that there are no settings with semantics corresponding to |
| 1045 // bypass of local names in GNOME. In KDE, "<local>" is supported | 1045 // bypass of local names in GNOME. In KDE, "<local>" is supported |
| 1046 // as a hostname rule. | 1046 // as a hostname rule. |
| 1047 | 1047 |
| 1048 // KDE allows one to reverse the bypass rules. | 1048 // KDE allows one to reverse the bypass rules. |
| 1049 config->proxy_rules().reverse_bypass = gconf_getter_->BypassListIsReversed(); | 1049 config->proxy_rules().reverse_bypass = gconf_getter_->BypassListIsReversed(); |
| 1050 | 1050 |
| 1051 return true; | 1051 return true; |
| 1052 } | 1052 } |
| 1053 | 1053 |
| 1054 ProxyConfigServiceLinux::Delegate::Delegate(base::EnvVarGetter* env_var_getter) | 1054 ProxyConfigServiceLinux::Delegate::Delegate(base::Environment* env_var_getter) |
| 1055 : env_var_getter_(env_var_getter), | 1055 : env_var_getter_(env_var_getter), |
| 1056 glib_default_loop_(NULL), io_loop_(NULL) { | 1056 glib_default_loop_(NULL), io_loop_(NULL) { |
| 1057 // Figure out which GConfSettingGetterImpl to use, if any. | 1057 // Figure out which GConfSettingGetterImpl to use, if any. |
| 1058 switch (base::GetDesktopEnvironment(env_var_getter)) { | 1058 switch (base::GetDesktopEnvironment(env_var_getter)) { |
| 1059 case base::DESKTOP_ENVIRONMENT_GNOME: | 1059 case base::DESKTOP_ENVIRONMENT_GNOME: |
| 1060 gconf_getter_.reset(new GConfSettingGetterImplGConf()); | 1060 gconf_getter_.reset(new GConfSettingGetterImplGConf()); |
| 1061 break; | 1061 break; |
| 1062 case base::DESKTOP_ENVIRONMENT_KDE3: | 1062 case base::DESKTOP_ENVIRONMENT_KDE3: |
| 1063 case base::DESKTOP_ENVIRONMENT_KDE4: | 1063 case base::DESKTOP_ENVIRONMENT_KDE4: |
| 1064 gconf_getter_.reset(new GConfSettingGetterImplKDE(env_var_getter)); | 1064 gconf_getter_.reset(new GConfSettingGetterImplKDE(env_var_getter)); |
| 1065 break; | 1065 break; |
| 1066 case base::DESKTOP_ENVIRONMENT_XFCE: | 1066 case base::DESKTOP_ENVIRONMENT_XFCE: |
| 1067 case base::DESKTOP_ENVIRONMENT_OTHER: | 1067 case base::DESKTOP_ENVIRONMENT_OTHER: |
| 1068 break; | 1068 break; |
| 1069 } | 1069 } |
| 1070 } | 1070 } |
| 1071 | 1071 |
| 1072 ProxyConfigServiceLinux::Delegate::Delegate(base::EnvVarGetter* env_var_getter, | 1072 ProxyConfigServiceLinux::Delegate::Delegate(base::Environment* env_var_getter, |
| 1073 GConfSettingGetter* gconf_getter) | 1073 GConfSettingGetter* gconf_getter) |
| 1074 : env_var_getter_(env_var_getter), gconf_getter_(gconf_getter), | 1074 : env_var_getter_(env_var_getter), gconf_getter_(gconf_getter), |
| 1075 glib_default_loop_(NULL), io_loop_(NULL) { | 1075 glib_default_loop_(NULL), io_loop_(NULL) { |
| 1076 } | 1076 } |
| 1077 | 1077 |
| 1078 void ProxyConfigServiceLinux::Delegate::SetupAndFetchInitialConfig( | 1078 void ProxyConfigServiceLinux::Delegate::SetupAndFetchInitialConfig( |
| 1079 MessageLoop* glib_default_loop, MessageLoop* io_loop, | 1079 MessageLoop* glib_default_loop, MessageLoop* io_loop, |
| 1080 MessageLoopForIO* file_loop) { | 1080 MessageLoopForIO* file_loop) { |
| 1081 // We should be running on the default glib main loop thread right | 1081 // We should be running on the default glib main loop thread right |
| 1082 // now. gconf can only be accessed from this thread. | 1082 // now. gconf can only be accessed from this thread. |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1217 &ProxyConfigServiceLinux::Delegate::OnDestroy)); | 1217 &ProxyConfigServiceLinux::Delegate::OnDestroy)); |
| 1218 } | 1218 } |
| 1219 } | 1219 } |
| 1220 void ProxyConfigServiceLinux::Delegate::OnDestroy() { | 1220 void ProxyConfigServiceLinux::Delegate::OnDestroy() { |
| 1221 MessageLoop* shutdown_loop = gconf_getter_->GetNotificationLoop(); | 1221 MessageLoop* shutdown_loop = gconf_getter_->GetNotificationLoop(); |
| 1222 DCHECK(!shutdown_loop || MessageLoop::current() == shutdown_loop); | 1222 DCHECK(!shutdown_loop || MessageLoop::current() == shutdown_loop); |
| 1223 gconf_getter_->Shutdown(); | 1223 gconf_getter_->Shutdown(); |
| 1224 } | 1224 } |
| 1225 | 1225 |
| 1226 ProxyConfigServiceLinux::ProxyConfigServiceLinux() | 1226 ProxyConfigServiceLinux::ProxyConfigServiceLinux() |
| 1227 : delegate_(new Delegate(base::EnvVarGetter::Create())) { | 1227 : delegate_(new Delegate(base::Environment::Create())) { |
| 1228 } | 1228 } |
| 1229 | 1229 |
| 1230 ProxyConfigServiceLinux::ProxyConfigServiceLinux( | 1230 ProxyConfigServiceLinux::ProxyConfigServiceLinux( |
| 1231 base::EnvVarGetter* env_var_getter) | 1231 base::Environment* env_var_getter) |
| 1232 : delegate_(new Delegate(env_var_getter)) { | 1232 : delegate_(new Delegate(env_var_getter)) { |
| 1233 } | 1233 } |
| 1234 | 1234 |
| 1235 ProxyConfigServiceLinux::ProxyConfigServiceLinux( | 1235 ProxyConfigServiceLinux::ProxyConfigServiceLinux( |
| 1236 base::EnvVarGetter* env_var_getter, | 1236 base::Environment* env_var_getter, |
| 1237 GConfSettingGetter* gconf_getter) | 1237 GConfSettingGetter* gconf_getter) |
| 1238 : delegate_(new Delegate(env_var_getter, gconf_getter)) { | 1238 : delegate_(new Delegate(env_var_getter, gconf_getter)) { |
| 1239 } | 1239 } |
| 1240 | 1240 |
| 1241 } // namespace net | 1241 } // namespace net |
| OLD | NEW |