OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #if defined(USE_GCONF) | 9 #if defined(USE_GCONF) |
10 #include <gconf/gconf-client.h> | 10 #include <gconf/gconf-client.h> |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 // the UI thread. This is not supposed to happen: the setting getter is | 225 // the UI thread. This is not supposed to happen: the setting getter is |
226 // owned by the proxy config service's delegate, which is supposed to be | 226 // owned by the proxy config service's delegate, which is supposed to be |
227 // destroyed on the UI thread only. We will get change notifications to | 227 // destroyed on the UI thread only. We will get change notifications to |
228 // a deleted object if we continue here, so fail now. | 228 // a deleted object if we continue here, so fail now. |
229 LOG(FATAL) << "~SettingGetterImplGConf: deleting on wrong thread!"; | 229 LOG(FATAL) << "~SettingGetterImplGConf: deleting on wrong thread!"; |
230 } | 230 } |
231 } | 231 } |
232 DCHECK(!client_); | 232 DCHECK(!client_); |
233 } | 233 } |
234 | 234 |
235 virtual bool Init(base::SingleThreadTaskRunner* glib_thread_task_runner, | 235 virtual bool Init( |
236 base::MessageLoopForIO* file_loop) OVERRIDE { | 236 const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner, |
237 DCHECK(glib_thread_task_runner->BelongsToCurrentThread()); | 237 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) |
| 238 OVERRIDE { |
| 239 DCHECK(glib_task_runner->BelongsToCurrentThread()); |
238 DCHECK(!client_); | 240 DCHECK(!client_); |
239 DCHECK(!task_runner_.get()); | 241 DCHECK(!task_runner_.get()); |
240 task_runner_ = glib_thread_task_runner; | 242 task_runner_ = glib_task_runner; |
241 client_ = gconf_client_get_default(); | 243 client_ = gconf_client_get_default(); |
242 if (!client_) { | 244 if (!client_) { |
243 // It's not clear whether/when this can return NULL. | 245 // It's not clear whether/when this can return NULL. |
244 LOG(ERROR) << "Unable to create a gconf client"; | 246 LOG(ERROR) << "Unable to create a gconf client"; |
245 task_runner_ = NULL; | 247 task_runner_ = NULL; |
246 return false; | 248 return false; |
247 } | 249 } |
248 GError* error = NULL; | 250 GError* error = NULL; |
249 bool added_system_proxy = false; | 251 bool added_system_proxy = false; |
250 // We need to add the directories for which we'll be asking | 252 // We need to add the directories for which we'll be asking |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 LOG(ERROR) << "Error requesting gconf notifications: " << error->message; | 313 LOG(ERROR) << "Error requesting gconf notifications: " << error->message; |
312 g_error_free(error); | 314 g_error_free(error); |
313 ShutDown(); | 315 ShutDown(); |
314 return false; | 316 return false; |
315 } | 317 } |
316 // Simulate a change to avoid possibly losing updates before this point. | 318 // Simulate a change to avoid possibly losing updates before this point. |
317 OnChangeNotification(); | 319 OnChangeNotification(); |
318 return true; | 320 return true; |
319 } | 321 } |
320 | 322 |
321 virtual base::SingleThreadTaskRunner* GetNotificationTaskRunner() OVERRIDE { | 323 virtual const scoped_refptr<base::SingleThreadTaskRunner>& |
322 return task_runner_.get(); | 324 GetNotificationTaskRunner() OVERRIDE { |
| 325 return task_runner_; |
323 } | 326 } |
324 | 327 |
325 virtual ProxyConfigSource GetConfigSource() OVERRIDE { | 328 virtual ProxyConfigSource GetConfigSource() OVERRIDE { |
326 return PROXY_CONFIG_SOURCE_GCONF; | 329 return PROXY_CONFIG_SOURCE_GCONF; |
327 } | 330 } |
328 | 331 |
329 virtual bool GetString(StringSetting key, std::string* result) OVERRIDE { | 332 virtual bool GetString(StringSetting key, std::string* result) OVERRIDE { |
330 switch (key) { | 333 switch (key) { |
331 case PROXY_MODE: | 334 case PROXY_MODE: |
332 return GetStringByPath("/system/proxy/mode", result); | 335 return GetStringByPath("/system/proxy/mode", result); |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 if (strcmp(schema_name, static_cast<const char*>(*schemas)) == 0) | 558 if (strcmp(schema_name, static_cast<const char*>(*schemas)) == 0) |
556 return true; | 559 return true; |
557 schemas++; | 560 schemas++; |
558 } | 561 } |
559 return false; | 562 return false; |
560 } | 563 } |
561 | 564 |
562 // LoadAndCheckVersion() must be called *before* Init()! | 565 // LoadAndCheckVersion() must be called *before* Init()! |
563 bool LoadAndCheckVersion(base::Environment* env); | 566 bool LoadAndCheckVersion(base::Environment* env); |
564 | 567 |
565 virtual bool Init(base::SingleThreadTaskRunner* glib_thread_task_runner, | 568 virtual bool Init( |
566 base::MessageLoopForIO* file_loop) OVERRIDE { | 569 const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner, |
567 DCHECK(glib_thread_task_runner->BelongsToCurrentThread()); | 570 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) |
| 571 OVERRIDE { |
| 572 DCHECK(glib_task_runner->BelongsToCurrentThread()); |
568 DCHECK(!client_); | 573 DCHECK(!client_); |
569 DCHECK(!task_runner_.get()); | 574 DCHECK(!task_runner_.get()); |
570 | 575 |
571 if (!SchemaExists(kProxyGConfSchema) || | 576 if (!SchemaExists(kProxyGConfSchema) || |
572 !(client_ = libgio_loader_.g_settings_new(kProxyGConfSchema))) { | 577 !(client_ = libgio_loader_.g_settings_new(kProxyGConfSchema))) { |
573 // It's not clear whether/when this can return NULL. | 578 // It's not clear whether/when this can return NULL. |
574 LOG(ERROR) << "Unable to create a gsettings client"; | 579 LOG(ERROR) << "Unable to create a gsettings client"; |
575 return false; | 580 return false; |
576 } | 581 } |
577 task_runner_ = glib_thread_task_runner; | 582 task_runner_ = glib_task_runner; |
578 // We assume these all work if the above call worked. | 583 // We assume these all work if the above call worked. |
579 http_client_ = libgio_loader_.g_settings_get_child(client_, "http"); | 584 http_client_ = libgio_loader_.g_settings_get_child(client_, "http"); |
580 https_client_ = libgio_loader_.g_settings_get_child(client_, "https"); | 585 https_client_ = libgio_loader_.g_settings_get_child(client_, "https"); |
581 ftp_client_ = libgio_loader_.g_settings_get_child(client_, "ftp"); | 586 ftp_client_ = libgio_loader_.g_settings_get_child(client_, "ftp"); |
582 socks_client_ = libgio_loader_.g_settings_get_child(client_, "socks"); | 587 socks_client_ = libgio_loader_.g_settings_get_child(client_, "socks"); |
583 DCHECK(http_client_ && https_client_ && ftp_client_ && socks_client_); | 588 DCHECK(http_client_ && https_client_ && ftp_client_ && socks_client_); |
584 return true; | 589 return true; |
585 } | 590 } |
586 | 591 |
587 virtual void ShutDown() OVERRIDE { | 592 virtual void ShutDown() OVERRIDE { |
(...skipping 27 matching lines...) Expand all Loading... |
615 G_CALLBACK(OnGSettingsChangeNotification), this); | 620 G_CALLBACK(OnGSettingsChangeNotification), this); |
616 g_signal_connect(G_OBJECT(ftp_client_), "changed", | 621 g_signal_connect(G_OBJECT(ftp_client_), "changed", |
617 G_CALLBACK(OnGSettingsChangeNotification), this); | 622 G_CALLBACK(OnGSettingsChangeNotification), this); |
618 g_signal_connect(G_OBJECT(socks_client_), "changed", | 623 g_signal_connect(G_OBJECT(socks_client_), "changed", |
619 G_CALLBACK(OnGSettingsChangeNotification), this); | 624 G_CALLBACK(OnGSettingsChangeNotification), this); |
620 // Simulate a change to avoid possibly losing updates before this point. | 625 // Simulate a change to avoid possibly losing updates before this point. |
621 OnChangeNotification(); | 626 OnChangeNotification(); |
622 return true; | 627 return true; |
623 } | 628 } |
624 | 629 |
625 virtual base::SingleThreadTaskRunner* GetNotificationTaskRunner() OVERRIDE { | 630 virtual const scoped_refptr<base::SingleThreadTaskRunner>& |
626 return task_runner_.get(); | 631 GetNotificationTaskRunner() OVERRIDE { |
| 632 return task_runner_; |
627 } | 633 } |
628 | 634 |
629 virtual ProxyConfigSource GetConfigSource() OVERRIDE { | 635 virtual ProxyConfigSource GetConfigSource() OVERRIDE { |
630 return PROXY_CONFIG_SOURCE_GSETTINGS; | 636 return PROXY_CONFIG_SOURCE_GSETTINGS; |
631 } | 637 } |
632 | 638 |
633 virtual bool GetString(StringSetting key, std::string* result) OVERRIDE { | 639 virtual bool GetString(StringSetting key, std::string* result) OVERRIDE { |
634 DCHECK(client_); | 640 DCHECK(client_); |
635 switch (key) { | 641 switch (key) { |
636 case PROXY_MODE: | 642 case PROXY_MODE: |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 | 853 |
848 // This is the KDE version that reads kioslaverc and simulates gconf. | 854 // This is the KDE version that reads kioslaverc and simulates gconf. |
849 // Doing this allows the main Delegate code, as well as the unit tests | 855 // Doing this allows the main Delegate code, as well as the unit tests |
850 // for it, to stay the same - and the settings map fairly well besides. | 856 // for it, to stay the same - and the settings map fairly well besides. |
851 class SettingGetterImplKDE : public ProxyConfigServiceLinux::SettingGetter, | 857 class SettingGetterImplKDE : public ProxyConfigServiceLinux::SettingGetter, |
852 public base::MessagePumpLibevent::Watcher { | 858 public base::MessagePumpLibevent::Watcher { |
853 public: | 859 public: |
854 explicit SettingGetterImplKDE(base::Environment* env_var_getter) | 860 explicit SettingGetterImplKDE(base::Environment* env_var_getter) |
855 : inotify_fd_(-1), notify_delegate_(NULL), indirect_manual_(false), | 861 : inotify_fd_(-1), notify_delegate_(NULL), indirect_manual_(false), |
856 auto_no_pac_(false), reversed_bypass_list_(false), | 862 auto_no_pac_(false), reversed_bypass_list_(false), |
857 env_var_getter_(env_var_getter), file_loop_(NULL) { | 863 env_var_getter_(env_var_getter), file_task_runner_(NULL) { |
858 // This has to be called on the UI thread (http://crbug.com/69057). | 864 // This has to be called on the UI thread (http://crbug.com/69057). |
859 base::ThreadRestrictions::ScopedAllowIO allow_io; | 865 base::ThreadRestrictions::ScopedAllowIO allow_io; |
860 | 866 |
861 // Derive the location of the kde config dir from the environment. | 867 // Derive the location of the kde config dir from the environment. |
862 std::string home; | 868 std::string home; |
863 if (env_var_getter->GetVar("KDEHOME", &home) && !home.empty()) { | 869 if (env_var_getter->GetVar("KDEHOME", &home) && !home.empty()) { |
864 // $KDEHOME is set. Use it unconditionally. | 870 // $KDEHOME is set. Use it unconditionally. |
865 kde_config_dir_ = KDEHomeToConfigPath(base::FilePath(home)); | 871 kde_config_dir_ = KDEHomeToConfigPath(base::FilePath(home)); |
866 } else { | 872 } else { |
867 // $KDEHOME is unset. Try to figure out what to use. This seems to be | 873 // $KDEHOME is unset. Try to figure out what to use. This seems to be |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 // on exiting the process, it may happen that Delegate::OnDestroy() | 922 // on exiting the process, it may happen that Delegate::OnDestroy() |
917 // task is left pending on the file loop after the loop was quit, | 923 // task is left pending on the file loop after the loop was quit, |
918 // and pending tasks may then be deleted without being run. | 924 // and pending tasks may then be deleted without being run. |
919 // Here in the KDE version, we can safely close the file descriptor | 925 // Here in the KDE version, we can safely close the file descriptor |
920 // anyway. (Not that it really matters; the process is exiting.) | 926 // anyway. (Not that it really matters; the process is exiting.) |
921 if (inotify_fd_ >= 0) | 927 if (inotify_fd_ >= 0) |
922 ShutDown(); | 928 ShutDown(); |
923 DCHECK(inotify_fd_ < 0); | 929 DCHECK(inotify_fd_ < 0); |
924 } | 930 } |
925 | 931 |
926 virtual bool Init(base::SingleThreadTaskRunner* glib_thread_task_runner, | 932 virtual bool Init( |
927 base::MessageLoopForIO* file_loop) OVERRIDE { | 933 const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner, |
| 934 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) |
| 935 OVERRIDE { |
928 // This has to be called on the UI thread (http://crbug.com/69057). | 936 // This has to be called on the UI thread (http://crbug.com/69057). |
929 base::ThreadRestrictions::ScopedAllowIO allow_io; | 937 base::ThreadRestrictions::ScopedAllowIO allow_io; |
930 DCHECK(inotify_fd_ < 0); | 938 DCHECK(inotify_fd_ < 0); |
931 inotify_fd_ = inotify_init(); | 939 inotify_fd_ = inotify_init(); |
932 if (inotify_fd_ < 0) { | 940 if (inotify_fd_ < 0) { |
933 PLOG(ERROR) << "inotify_init failed"; | 941 PLOG(ERROR) << "inotify_init failed"; |
934 return false; | 942 return false; |
935 } | 943 } |
936 int flags = fcntl(inotify_fd_, F_GETFL); | 944 int flags = fcntl(inotify_fd_, F_GETFL); |
937 if (fcntl(inotify_fd_, F_SETFL, flags | O_NONBLOCK) < 0) { | 945 if (fcntl(inotify_fd_, F_SETFL, flags | O_NONBLOCK) < 0) { |
938 PLOG(ERROR) << "fcntl failed"; | 946 PLOG(ERROR) << "fcntl failed"; |
939 close(inotify_fd_); | 947 close(inotify_fd_); |
940 inotify_fd_ = -1; | 948 inotify_fd_ = -1; |
941 return false; | 949 return false; |
942 } | 950 } |
943 file_loop_ = file_loop; | 951 file_task_runner_ = file_task_runner; |
944 // The initial read is done on the current thread, not |file_loop_|, | 952 // The initial read is done on the current thread, not |
945 // since we will need to have it for SetUpAndFetchInitialConfig(). | 953 // |file_task_runner_|, since we will need to have it for |
| 954 // SetUpAndFetchInitialConfig(). |
946 UpdateCachedSettings(); | 955 UpdateCachedSettings(); |
947 return true; | 956 return true; |
948 } | 957 } |
949 | 958 |
950 virtual void ShutDown() OVERRIDE { | 959 virtual void ShutDown() OVERRIDE { |
951 if (inotify_fd_ >= 0) { | 960 if (inotify_fd_ >= 0) { |
952 ResetCachedSettings(); | 961 ResetCachedSettings(); |
953 inotify_watcher_.StopWatchingFileDescriptor(); | 962 inotify_watcher_.StopWatchingFileDescriptor(); |
954 close(inotify_fd_); | 963 close(inotify_fd_); |
955 inotify_fd_ = -1; | 964 inotify_fd_ = -1; |
956 } | 965 } |
957 } | 966 } |
958 | 967 |
959 virtual bool SetUpNotifications( | 968 virtual bool SetUpNotifications( |
960 ProxyConfigServiceLinux::Delegate* delegate) OVERRIDE { | 969 ProxyConfigServiceLinux::Delegate* delegate) OVERRIDE { |
961 DCHECK(inotify_fd_ >= 0); | 970 DCHECK(inotify_fd_ >= 0); |
962 DCHECK(base::MessageLoop::current() == file_loop_); | 971 DCHECK(file_task_runner_->BelongsToCurrentThread()); |
963 // We can't just watch the kioslaverc file directly, since KDE will write | 972 // We can't just watch the kioslaverc file directly, since KDE will write |
964 // a new copy of it and then rename it whenever settings are changed and | 973 // a new copy of it and then rename it whenever settings are changed and |
965 // inotify watches inodes (so we'll be watching the old deleted file after | 974 // inotify watches inodes (so we'll be watching the old deleted file after |
966 // the first change, and it will never change again). So, we watch the | 975 // the first change, and it will never change again). So, we watch the |
967 // directory instead. We then act only on changes to the kioslaverc entry. | 976 // directory instead. We then act only on changes to the kioslaverc entry. |
968 if (inotify_add_watch(inotify_fd_, kde_config_dir_.value().c_str(), | 977 if (inotify_add_watch(inotify_fd_, kde_config_dir_.value().c_str(), |
969 IN_MODIFY | IN_MOVED_TO) < 0) | 978 IN_MODIFY | IN_MOVED_TO) < 0) { |
970 return false; | 979 return false; |
| 980 } |
971 notify_delegate_ = delegate; | 981 notify_delegate_ = delegate; |
972 if (!file_loop_->WatchFileDescriptor(inotify_fd_, | 982 if (!base::MessageLoopForIO::current()->WatchFileDescriptor( |
973 true, | 983 inotify_fd_, true, base::MessageLoopForIO::WATCH_READ, |
974 base::MessageLoopForIO::WATCH_READ, | 984 &inotify_watcher_, this)) { |
975 &inotify_watcher_, | |
976 this)) | |
977 return false; | 985 return false; |
| 986 } |
978 // Simulate a change to avoid possibly losing updates before this point. | 987 // Simulate a change to avoid possibly losing updates before this point. |
979 OnChangeNotification(); | 988 OnChangeNotification(); |
980 return true; | 989 return true; |
981 } | 990 } |
982 | 991 |
983 virtual base::SingleThreadTaskRunner* GetNotificationTaskRunner() OVERRIDE { | 992 virtual const scoped_refptr<base::SingleThreadTaskRunner>& |
984 return file_loop_ ? file_loop_->message_loop_proxy().get() : NULL; | 993 GetNotificationTaskRunner() OVERRIDE { |
| 994 return file_task_runner_; |
985 } | 995 } |
986 | 996 |
987 // Implement base::MessagePumpLibevent::Watcher. | 997 // Implement base::MessagePumpLibevent::Watcher. |
988 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE { | 998 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE { |
989 DCHECK_EQ(fd, inotify_fd_); | 999 DCHECK_EQ(fd, inotify_fd_); |
990 DCHECK(base::MessageLoop::current() == file_loop_); | 1000 DCHECK(file_task_runner_->BelongsToCurrentThread()); |
991 OnChangeNotification(); | 1001 OnChangeNotification(); |
992 } | 1002 } |
993 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE { | 1003 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE { |
994 NOTREACHED(); | 1004 NOTREACHED(); |
995 } | 1005 } |
996 | 1006 |
997 virtual ProxyConfigSource GetConfigSource() OVERRIDE { | 1007 virtual ProxyConfigSource GetConfigSource() OVERRIDE { |
998 return PROXY_CONFIG_SOURCE_KDE; | 1008 return PROXY_CONFIG_SOURCE_KDE; |
999 } | 1009 } |
1000 | 1010 |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1246 AddKDESetting(key, value); | 1256 AddKDESetting(key, value); |
1247 } | 1257 } |
1248 } | 1258 } |
1249 if (ferror(input.get())) | 1259 if (ferror(input.get())) |
1250 LOG(ERROR) << "error reading " << kioslaverc.value(); | 1260 LOG(ERROR) << "error reading " << kioslaverc.value(); |
1251 ResolveModeEffects(); | 1261 ResolveModeEffects(); |
1252 } | 1262 } |
1253 | 1263 |
1254 // This is the callback from the debounce timer. | 1264 // This is the callback from the debounce timer. |
1255 void OnDebouncedNotification() { | 1265 void OnDebouncedNotification() { |
1256 DCHECK(base::MessageLoop::current() == file_loop_); | 1266 DCHECK(file_task_runner_->BelongsToCurrentThread()); |
1257 VLOG(1) << "inotify change notification for kioslaverc"; | 1267 VLOG(1) << "inotify change notification for kioslaverc"; |
1258 UpdateCachedSettings(); | 1268 UpdateCachedSettings(); |
1259 CHECK(notify_delegate_); | 1269 CHECK(notify_delegate_); |
1260 // Forward to a method on the proxy config service delegate object. | 1270 // Forward to a method on the proxy config service delegate object. |
1261 notify_delegate_->OnCheckProxyConfigSettings(); | 1271 notify_delegate_->OnCheckProxyConfigSettings(); |
1262 } | 1272 } |
1263 | 1273 |
1264 // Called by OnFileCanReadWithoutBlocking() on the file thread. Reads | 1274 // Called by OnFileCanReadWithoutBlocking() on the file thread. Reads |
1265 // from the inotify file descriptor and starts up a debounce timer if | 1275 // from the inotify file descriptor and starts up a debounce timer if |
1266 // an event for kioslaverc is seen. | 1276 // an event for kioslaverc is seen. |
1267 void OnChangeNotification() { | 1277 void OnChangeNotification() { |
1268 DCHECK_GE(inotify_fd_, 0); | 1278 DCHECK_GE(inotify_fd_, 0); |
1269 DCHECK(base::MessageLoop::current() == file_loop_); | 1279 DCHECK(file_task_runner_->BelongsToCurrentThread()); |
1270 char event_buf[(sizeof(inotify_event) + NAME_MAX + 1) * 4]; | 1280 char event_buf[(sizeof(inotify_event) + NAME_MAX + 1) * 4]; |
1271 bool kioslaverc_touched = false; | 1281 bool kioslaverc_touched = false; |
1272 ssize_t r; | 1282 ssize_t r; |
1273 while ((r = read(inotify_fd_, event_buf, sizeof(event_buf))) > 0) { | 1283 while ((r = read(inotify_fd_, event_buf, sizeof(event_buf))) > 0) { |
1274 // inotify returns variable-length structures, which is why we have | 1284 // inotify returns variable-length structures, which is why we have |
1275 // this strange-looking loop instead of iterating through an array. | 1285 // this strange-looking loop instead of iterating through an array. |
1276 char* event_ptr = event_buf; | 1286 char* event_ptr = event_buf; |
1277 while (event_ptr < event_buf + r) { | 1287 while (event_ptr < event_buf + r) { |
1278 inotify_event* event = reinterpret_cast<inotify_event*>(event_ptr); | 1288 inotify_event* event = reinterpret_cast<inotify_event*>(event_ptr); |
1279 // The kernel always feeds us whole events. | 1289 // The kernel always feeds us whole events. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1329 bool reversed_bypass_list_; | 1339 bool reversed_bypass_list_; |
1330 // We don't own |env_var_getter_|. It's safe to hold a pointer to it, since | 1340 // We don't own |env_var_getter_|. It's safe to hold a pointer to it, since |
1331 // both it and us are owned by ProxyConfigServiceLinux::Delegate, and have the | 1341 // both it and us are owned by ProxyConfigServiceLinux::Delegate, and have the |
1332 // same lifetime. | 1342 // same lifetime. |
1333 base::Environment* env_var_getter_; | 1343 base::Environment* env_var_getter_; |
1334 | 1344 |
1335 // We cache these settings whenever we re-read the kioslaverc file. | 1345 // We cache these settings whenever we re-read the kioslaverc file. |
1336 string_map_type string_table_; | 1346 string_map_type string_table_; |
1337 strings_map_type strings_table_; | 1347 strings_map_type strings_table_; |
1338 | 1348 |
1339 // Message loop of the file thread, for reading kioslaverc. If NULL, | 1349 // Task runner of the file thread, for reading kioslaverc. If NULL, |
1340 // just read it directly (for testing). We also handle inotify events | 1350 // just read it directly (for testing). We also handle inotify events |
1341 // on this thread. | 1351 // on this thread. |
1342 base::MessageLoopForIO* file_loop_; | 1352 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; |
1343 | 1353 |
1344 DISALLOW_COPY_AND_ASSIGN(SettingGetterImplKDE); | 1354 DISALLOW_COPY_AND_ASSIGN(SettingGetterImplKDE); |
1345 }; | 1355 }; |
1346 | 1356 |
1347 } // namespace | 1357 } // namespace |
1348 | 1358 |
1349 bool ProxyConfigServiceLinux::Delegate::GetProxyFromSettings( | 1359 bool ProxyConfigServiceLinux::Delegate::GetProxyFromSettings( |
1350 SettingGetter::StringSetting host_key, | 1360 SettingGetter::StringSetting host_key, |
1351 ProxyServer* result_server) { | 1361 ProxyServer* result_server) { |
1352 std::string host; | 1362 std::string host; |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1549 break; | 1559 break; |
1550 } | 1560 } |
1551 } | 1561 } |
1552 | 1562 |
1553 ProxyConfigServiceLinux::Delegate::Delegate( | 1563 ProxyConfigServiceLinux::Delegate::Delegate( |
1554 base::Environment* env_var_getter, SettingGetter* setting_getter) | 1564 base::Environment* env_var_getter, SettingGetter* setting_getter) |
1555 : env_var_getter_(env_var_getter), setting_getter_(setting_getter) { | 1565 : env_var_getter_(env_var_getter), setting_getter_(setting_getter) { |
1556 } | 1566 } |
1557 | 1567 |
1558 void ProxyConfigServiceLinux::Delegate::SetUpAndFetchInitialConfig( | 1568 void ProxyConfigServiceLinux::Delegate::SetUpAndFetchInitialConfig( |
1559 base::SingleThreadTaskRunner* glib_thread_task_runner, | 1569 const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner, |
1560 base::SingleThreadTaskRunner* io_thread_task_runner, | 1570 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
1561 base::MessageLoopForIO* file_loop) { | 1571 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) { |
1562 // We should be running on the default glib main loop thread right | 1572 // We should be running on the default glib main loop thread right |
1563 // now. gconf can only be accessed from this thread. | 1573 // now. gconf can only be accessed from this thread. |
1564 DCHECK(glib_thread_task_runner->BelongsToCurrentThread()); | 1574 DCHECK(glib_task_runner->BelongsToCurrentThread()); |
1565 glib_thread_task_runner_ = glib_thread_task_runner; | 1575 glib_task_runner_ = glib_task_runner; |
1566 io_thread_task_runner_ = io_thread_task_runner; | 1576 io_task_runner_ = io_task_runner; |
1567 | 1577 |
1568 // If we are passed a NULL |io_thread_task_runner| or |file_loop|, | 1578 // If we are passed a NULL |io_task_runner| or |file_task_runner|, then we |
1569 // then we don't set up proxy setting change notifications. This | 1579 // don't set up proxy setting change notifications. This should not be the |
1570 // should not be the usual case but is intended to simplify test | 1580 // usual case but is intended to/ simplify test setups. |
1571 // setups. | 1581 if (!io_task_runner_.get() || !file_task_runner) |
1572 if (!io_thread_task_runner_.get() || !file_loop) | |
1573 VLOG(1) << "Monitoring of proxy setting changes is disabled"; | 1582 VLOG(1) << "Monitoring of proxy setting changes is disabled"; |
1574 | 1583 |
1575 // Fetch and cache the current proxy config. The config is left in | 1584 // Fetch and cache the current proxy config. The config is left in |
1576 // cached_config_, where GetLatestProxyConfig() running on the IO thread | 1585 // cached_config_, where GetLatestProxyConfig() running on the IO thread |
1577 // will expect to find it. This is safe to do because we return | 1586 // will expect to find it. This is safe to do because we return |
1578 // before this ProxyConfigServiceLinux is passed on to | 1587 // before this ProxyConfigServiceLinux is passed on to |
1579 // the ProxyService. | 1588 // the ProxyService. |
1580 | 1589 |
1581 // Note: It would be nice to prioritize environment variables | 1590 // Note: It would be nice to prioritize environment variables |
1582 // and only fall back to gconf if env vars were unset. But | 1591 // and only fall back to gconf if env vars were unset. But |
1583 // gnome-terminal "helpfully" sets http_proxy and no_proxy, and it | 1592 // gnome-terminal "helpfully" sets http_proxy and no_proxy, and it |
1584 // does so even if the proxy mode is set to auto, which would | 1593 // does so even if the proxy mode is set to auto, which would |
1585 // mislead us. | 1594 // mislead us. |
1586 | 1595 |
1587 bool got_config = false; | 1596 bool got_config = false; |
1588 if (setting_getter_.get() && | 1597 if (setting_getter_.get() && |
1589 setting_getter_->Init(glib_thread_task_runner, file_loop) && | 1598 setting_getter_->Init(glib_task_runner, file_task_runner) && |
1590 GetConfigFromSettings(&cached_config_)) { | 1599 GetConfigFromSettings(&cached_config_)) { |
1591 cached_config_.set_id(1); // Mark it as valid. | 1600 cached_config_.set_id(1); // Mark it as valid. |
1592 cached_config_.set_source(setting_getter_->GetConfigSource()); | 1601 cached_config_.set_source(setting_getter_->GetConfigSource()); |
1593 VLOG(1) << "Obtained proxy settings from " | 1602 VLOG(1) << "Obtained proxy settings from " |
1594 << ProxyConfigSourceToString(cached_config_.source()); | 1603 << ProxyConfigSourceToString(cached_config_.source()); |
1595 | 1604 |
1596 // If gconf proxy mode is "none", meaning direct, then we take | 1605 // If gconf proxy mode is "none", meaning direct, then we take |
1597 // that to be a valid config and will not check environment | 1606 // that to be a valid config and will not check environment |
1598 // variables. The alternative would have been to look for a proxy | 1607 // variables. The alternative would have been to look for a proxy |
1599 // whereever we can find one. | 1608 // whereever we can find one. |
1600 got_config = true; | 1609 got_config = true; |
1601 | 1610 |
1602 // Keep a copy of the config for use from this thread for | 1611 // Keep a copy of the config for use from this thread for |
1603 // comparison with updated settings when we get notifications. | 1612 // comparison with updated settings when we get notifications. |
1604 reference_config_ = cached_config_; | 1613 reference_config_ = cached_config_; |
1605 reference_config_.set_id(1); // Mark it as valid. | 1614 reference_config_.set_id(1); // Mark it as valid. |
1606 | 1615 |
1607 // We only set up notifications if we have IO and file loops available. | 1616 // We only set up notifications if we have IO and file loops available. |
1608 // We do this after getting the initial configuration so that we don't have | 1617 // We do this after getting the initial configuration so that we don't have |
1609 // to worry about cancelling it if the initial fetch above fails. Note that | 1618 // to worry about cancelling it if the initial fetch above fails. Note that |
1610 // setting up notifications has the side effect of simulating a change, so | 1619 // setting up notifications has the side effect of simulating a change, so |
1611 // that we won't lose any updates that may have happened after the initial | 1620 // that we won't lose any updates that may have happened after the initial |
1612 // fetch and before setting up notifications. We'll detect the common case | 1621 // fetch and before setting up notifications. We'll detect the common case |
1613 // of no changes in OnCheckProxyConfigSettings() (or sooner) and ignore it. | 1622 // of no changes in OnCheckProxyConfigSettings() (or sooner) and ignore it. |
1614 if (io_thread_task_runner && file_loop) { | 1623 if (io_task_runner && file_task_runner) { |
1615 scoped_refptr<base::SingleThreadTaskRunner> required_loop = | 1624 scoped_refptr<base::SingleThreadTaskRunner> required_loop = |
1616 setting_getter_->GetNotificationTaskRunner(); | 1625 setting_getter_->GetNotificationTaskRunner(); |
1617 if (!required_loop.get() || required_loop->BelongsToCurrentThread()) { | 1626 if (!required_loop.get() || required_loop->BelongsToCurrentThread()) { |
1618 // In this case we are already on an acceptable thread. | 1627 // In this case we are already on an acceptable thread. |
1619 SetUpNotifications(); | 1628 SetUpNotifications(); |
1620 } else { | 1629 } else { |
1621 // Post a task to set up notifications. We don't wait for success. | 1630 // Post a task to set up notifications. We don't wait for success. |
1622 required_loop->PostTask(FROM_HERE, base::Bind( | 1631 required_loop->PostTask(FROM_HERE, base::Bind( |
1623 &ProxyConfigServiceLinux::Delegate::SetUpNotifications, this)); | 1632 &ProxyConfigServiceLinux::Delegate::SetUpNotifications, this)); |
1624 } | 1633 } |
(...skipping 28 matching lines...) Expand all Loading... |
1653 } | 1662 } |
1654 | 1663 |
1655 void ProxyConfigServiceLinux::Delegate::RemoveObserver(Observer* observer) { | 1664 void ProxyConfigServiceLinux::Delegate::RemoveObserver(Observer* observer) { |
1656 observers_.RemoveObserver(observer); | 1665 observers_.RemoveObserver(observer); |
1657 } | 1666 } |
1658 | 1667 |
1659 ProxyConfigService::ConfigAvailability | 1668 ProxyConfigService::ConfigAvailability |
1660 ProxyConfigServiceLinux::Delegate::GetLatestProxyConfig( | 1669 ProxyConfigServiceLinux::Delegate::GetLatestProxyConfig( |
1661 ProxyConfig* config) { | 1670 ProxyConfig* config) { |
1662 // This is called from the IO thread. | 1671 // This is called from the IO thread. |
1663 DCHECK(!io_thread_task_runner_.get() || | 1672 DCHECK(!io_task_runner_.get() || |
1664 io_thread_task_runner_->BelongsToCurrentThread()); | 1673 io_task_runner_->BelongsToCurrentThread()); |
1665 | 1674 |
1666 // Simply return the last proxy configuration that glib_default_loop | 1675 // Simply return the last proxy configuration that glib_default_loop |
1667 // notified us of. | 1676 // notified us of. |
1668 if (cached_config_.is_valid()) { | 1677 if (cached_config_.is_valid()) { |
1669 *config = cached_config_; | 1678 *config = cached_config_; |
1670 } else { | 1679 } else { |
1671 *config = ProxyConfig::CreateDirect(); | 1680 *config = ProxyConfig::CreateDirect(); |
1672 config->set_source(PROXY_CONFIG_SOURCE_SYSTEM_FAILED); | 1681 config->set_source(PROXY_CONFIG_SOURCE_SYSTEM_FAILED); |
1673 } | 1682 } |
1674 | 1683 |
(...skipping 14 matching lines...) Expand all Loading... |
1689 ProxyConfig new_config; | 1698 ProxyConfig new_config; |
1690 bool valid = GetConfigFromSettings(&new_config); | 1699 bool valid = GetConfigFromSettings(&new_config); |
1691 if (valid) | 1700 if (valid) |
1692 new_config.set_id(1); // mark it as valid | 1701 new_config.set_id(1); // mark it as valid |
1693 | 1702 |
1694 // See if it is different from what we had before. | 1703 // See if it is different from what we had before. |
1695 if (new_config.is_valid() != reference_config_.is_valid() || | 1704 if (new_config.is_valid() != reference_config_.is_valid() || |
1696 !new_config.Equals(reference_config_)) { | 1705 !new_config.Equals(reference_config_)) { |
1697 // Post a task to the IO thread with the new configuration, so it can | 1706 // Post a task to the IO thread with the new configuration, so it can |
1698 // update |cached_config_|. | 1707 // update |cached_config_|. |
1699 io_thread_task_runner_->PostTask(FROM_HERE, base::Bind( | 1708 io_task_runner_->PostTask(FROM_HERE, base::Bind( |
1700 &ProxyConfigServiceLinux::Delegate::SetNewProxyConfig, | 1709 &ProxyConfigServiceLinux::Delegate::SetNewProxyConfig, |
1701 this, new_config)); | 1710 this, new_config)); |
1702 // Update the thread-private copy in |reference_config_| as well. | 1711 // Update the thread-private copy in |reference_config_| as well. |
1703 reference_config_ = new_config; | 1712 reference_config_ = new_config; |
1704 } else { | 1713 } else { |
1705 VLOG(1) << "Detected no-op change to proxy settings. Doing nothing."; | 1714 VLOG(1) << "Detected no-op change to proxy settings. Doing nothing."; |
1706 } | 1715 } |
1707 } | 1716 } |
1708 | 1717 |
1709 void ProxyConfigServiceLinux::Delegate::SetNewProxyConfig( | 1718 void ProxyConfigServiceLinux::Delegate::SetNewProxyConfig( |
1710 const ProxyConfig& new_config) { | 1719 const ProxyConfig& new_config) { |
1711 DCHECK(io_thread_task_runner_->BelongsToCurrentThread()); | 1720 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
1712 VLOG(1) << "Proxy configuration changed"; | 1721 VLOG(1) << "Proxy configuration changed"; |
1713 cached_config_ = new_config; | 1722 cached_config_ = new_config; |
1714 FOR_EACH_OBSERVER( | 1723 FOR_EACH_OBSERVER( |
1715 Observer, observers_, | 1724 Observer, observers_, |
1716 OnProxyConfigChanged(new_config, ProxyConfigService::CONFIG_VALID)); | 1725 OnProxyConfigChanged(new_config, ProxyConfigService::CONFIG_VALID)); |
1717 } | 1726 } |
1718 | 1727 |
1719 void ProxyConfigServiceLinux::Delegate::PostDestroyTask() { | 1728 void ProxyConfigServiceLinux::Delegate::PostDestroyTask() { |
1720 if (!setting_getter_.get()) | 1729 if (!setting_getter_.get()) |
1721 return; | 1730 return; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1764 void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) { | 1773 void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) { |
1765 delegate_->RemoveObserver(observer); | 1774 delegate_->RemoveObserver(observer); |
1766 } | 1775 } |
1767 | 1776 |
1768 ProxyConfigService::ConfigAvailability | 1777 ProxyConfigService::ConfigAvailability |
1769 ProxyConfigServiceLinux::GetLatestProxyConfig(ProxyConfig* config) { | 1778 ProxyConfigServiceLinux::GetLatestProxyConfig(ProxyConfig* config) { |
1770 return delegate_->GetLatestProxyConfig(config); | 1779 return delegate_->GetLatestProxyConfig(config); |
1771 } | 1780 } |
1772 | 1781 |
1773 } // namespace net | 1782 } // namespace net |
OLD | NEW |