| 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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 if (added_system_proxy) | 263 if (added_system_proxy) |
| 264 gconf_client_remove_dir(client_, "/system/proxy", NULL); | 264 gconf_client_remove_dir(client_, "/system/proxy", NULL); |
| 265 g_object_unref(client_); | 265 g_object_unref(client_); |
| 266 client_ = NULL; | 266 client_ = NULL; |
| 267 task_runner_ = NULL; | 267 task_runner_ = NULL; |
| 268 return false; | 268 return false; |
| 269 } | 269 } |
| 270 return true; | 270 return true; |
| 271 } | 271 } |
| 272 | 272 |
| 273 void ShutDown() { | 273 virtual void ShutDown() OVERRIDE { |
| 274 if (client_) { | 274 if (client_) { |
| 275 DCHECK(task_runner_->BelongsToCurrentThread()); | 275 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 276 // We must explicitly disable gconf notifications here, because the gconf | 276 // We must explicitly disable gconf notifications here, because the gconf |
| 277 // client will be shared between all setting getters, and they do not all | 277 // client will be shared between all setting getters, and they do not all |
| 278 // have the same lifetimes. (For instance, incognito sessions get their | 278 // have the same lifetimes. (For instance, incognito sessions get their |
| 279 // own, which is destroyed when the session ends.) | 279 // own, which is destroyed when the session ends.) |
| 280 gconf_client_notify_remove(client_, system_http_proxy_id_); | 280 gconf_client_notify_remove(client_, system_http_proxy_id_); |
| 281 gconf_client_notify_remove(client_, system_proxy_id_); | 281 gconf_client_notify_remove(client_, system_proxy_id_); |
| 282 gconf_client_remove_dir(client_, "/system/http_proxy", NULL); | 282 gconf_client_remove_dir(client_, "/system/http_proxy", NULL); |
| 283 gconf_client_remove_dir(client_, "/system/proxy", NULL); | 283 gconf_client_remove_dir(client_, "/system/proxy", NULL); |
| 284 g_object_unref(client_); | 284 g_object_unref(client_); |
| 285 client_ = NULL; | 285 client_ = NULL; |
| 286 task_runner_ = NULL; | 286 task_runner_ = NULL; |
| 287 } | 287 } |
| 288 } | 288 } |
| 289 | 289 |
| 290 bool SetUpNotifications(ProxyConfigServiceLinux::Delegate* delegate) { | 290 virtual bool SetUpNotifications( |
| 291 ProxyConfigServiceLinux::Delegate* delegate) OVERRIDE { |
| 291 DCHECK(client_); | 292 DCHECK(client_); |
| 292 DCHECK(task_runner_->BelongsToCurrentThread()); | 293 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 293 GError* error = NULL; | 294 GError* error = NULL; |
| 294 notify_delegate_ = delegate; | 295 notify_delegate_ = delegate; |
| 295 // We have to keep track of the IDs returned by gconf_client_notify_add() so | 296 // We have to keep track of the IDs returned by gconf_client_notify_add() so |
| 296 // that we can remove them in ShutDown(). (Otherwise, notifications will be | 297 // that we can remove them in ShutDown(). (Otherwise, notifications will be |
| 297 // delivered to this object after it is deleted, which is bad, m'kay?) | 298 // delivered to this object after it is deleted, which is bad, m'kay?) |
| 298 system_proxy_id_ = gconf_client_notify_add( | 299 system_proxy_id_ = gconf_client_notify_add( |
| 299 client_, "/system/proxy", | 300 client_, "/system/proxy", |
| 300 OnGConfChangeNotification, this, | 301 OnGConfChangeNotification, this, |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 task_runner_ = glib_thread_task_runner; | 590 task_runner_ = glib_thread_task_runner; |
| 590 // We assume these all work if the above call worked. | 591 // We assume these all work if the above call worked. |
| 591 http_client_ = g_settings_get_child(client_, "http"); | 592 http_client_ = g_settings_get_child(client_, "http"); |
| 592 https_client_ = g_settings_get_child(client_, "https"); | 593 https_client_ = g_settings_get_child(client_, "https"); |
| 593 ftp_client_ = g_settings_get_child(client_, "ftp"); | 594 ftp_client_ = g_settings_get_child(client_, "ftp"); |
| 594 socks_client_ = g_settings_get_child(client_, "socks"); | 595 socks_client_ = g_settings_get_child(client_, "socks"); |
| 595 DCHECK(http_client_ && https_client_ && ftp_client_ && socks_client_); | 596 DCHECK(http_client_ && https_client_ && ftp_client_ && socks_client_); |
| 596 return true; | 597 return true; |
| 597 } | 598 } |
| 598 | 599 |
| 599 void ShutDown() { | 600 virtual void ShutDown() OVERRIDE { |
| 600 if (client_) { | 601 if (client_) { |
| 601 DCHECK(task_runner_->BelongsToCurrentThread()); | 602 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 602 // This also disables gsettings notifications. | 603 // This also disables gsettings notifications. |
| 603 g_object_unref(socks_client_); | 604 g_object_unref(socks_client_); |
| 604 g_object_unref(ftp_client_); | 605 g_object_unref(ftp_client_); |
| 605 g_object_unref(https_client_); | 606 g_object_unref(https_client_); |
| 606 g_object_unref(http_client_); | 607 g_object_unref(http_client_); |
| 607 g_object_unref(client_); | 608 g_object_unref(client_); |
| 608 // We only need to null client_ because it's the only one that we check. | 609 // We only need to null client_ because it's the only one that we check. |
| 609 client_ = NULL; | 610 client_ = NULL; |
| 610 task_runner_ = NULL; | 611 task_runner_ = NULL; |
| 611 } | 612 } |
| 612 } | 613 } |
| 613 | 614 |
| 614 bool SetUpNotifications(ProxyConfigServiceLinux::Delegate* delegate) { | 615 virtual bool SetUpNotifications( |
| 616 ProxyConfigServiceLinux::Delegate* delegate) OVERRIDE { |
| 615 DCHECK(client_); | 617 DCHECK(client_); |
| 616 DCHECK(task_runner_->BelongsToCurrentThread()); | 618 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 617 notify_delegate_ = delegate; | 619 notify_delegate_ = delegate; |
| 618 // We could watch for the change-event signal instead of changed, but | 620 // We could watch for the change-event signal instead of changed, but |
| 619 // since we have to watch more than one object, we'd still have to | 621 // since we have to watch more than one object, we'd still have to |
| 620 // debounce change notifications. This is conceptually simpler. | 622 // debounce change notifications. This is conceptually simpler. |
| 621 g_signal_connect(G_OBJECT(client_), "changed", | 623 g_signal_connect(G_OBJECT(client_), "changed", |
| 622 G_CALLBACK(OnGSettingsChangeNotification), this); | 624 G_CALLBACK(OnGSettingsChangeNotification), this); |
| 623 g_signal_connect(G_OBJECT(http_client_), "changed", | 625 g_signal_connect(G_OBJECT(http_client_), "changed", |
| 624 G_CALLBACK(OnGSettingsChangeNotification), this); | 626 G_CALLBACK(OnGSettingsChangeNotification), this); |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 995 inotify_fd_ = -1; | 997 inotify_fd_ = -1; |
| 996 return false; | 998 return false; |
| 997 } | 999 } |
| 998 file_loop_ = file_loop; | 1000 file_loop_ = file_loop; |
| 999 // The initial read is done on the current thread, not |file_loop_|, | 1001 // The initial read is done on the current thread, not |file_loop_|, |
| 1000 // since we will need to have it for SetUpAndFetchInitialConfig(). | 1002 // since we will need to have it for SetUpAndFetchInitialConfig(). |
| 1001 UpdateCachedSettings(); | 1003 UpdateCachedSettings(); |
| 1002 return true; | 1004 return true; |
| 1003 } | 1005 } |
| 1004 | 1006 |
| 1005 void ShutDown() { | 1007 virtual void ShutDown() OVERRIDE { |
| 1006 if (inotify_fd_ >= 0) { | 1008 if (inotify_fd_ >= 0) { |
| 1007 ResetCachedSettings(); | 1009 ResetCachedSettings(); |
| 1008 inotify_watcher_.StopWatchingFileDescriptor(); | 1010 inotify_watcher_.StopWatchingFileDescriptor(); |
| 1009 close(inotify_fd_); | 1011 close(inotify_fd_); |
| 1010 inotify_fd_ = -1; | 1012 inotify_fd_ = -1; |
| 1011 } | 1013 } |
| 1012 } | 1014 } |
| 1013 | 1015 |
| 1014 bool SetUpNotifications(ProxyConfigServiceLinux::Delegate* delegate) { | 1016 virtual bool SetUpNotifications( |
| 1017 ProxyConfigServiceLinux::Delegate* delegate) OVERRIDE { |
| 1015 DCHECK(inotify_fd_ >= 0); | 1018 DCHECK(inotify_fd_ >= 0); |
| 1016 DCHECK(MessageLoop::current() == file_loop_); | 1019 DCHECK(MessageLoop::current() == file_loop_); |
| 1017 // We can't just watch the kioslaverc file directly, since KDE will write | 1020 // We can't just watch the kioslaverc file directly, since KDE will write |
| 1018 // a new copy of it and then rename it whenever settings are changed and | 1021 // a new copy of it and then rename it whenever settings are changed and |
| 1019 // inotify watches inodes (so we'll be watching the old deleted file after | 1022 // inotify watches inodes (so we'll be watching the old deleted file after |
| 1020 // the first change, and it will never change again). So, we watch the | 1023 // the first change, and it will never change again). So, we watch the |
| 1021 // directory instead. We then act only on changes to the kioslaverc entry. | 1024 // directory instead. We then act only on changes to the kioslaverc entry. |
| 1022 if (inotify_add_watch(inotify_fd_, kde_config_dir_.value().c_str(), | 1025 if (inotify_add_watch(inotify_fd_, kde_config_dir_.value().c_str(), |
| 1023 IN_MODIFY | IN_MOVED_TO) < 0) | 1026 IN_MODIFY | IN_MOVED_TO) < 0) |
| 1024 return false; | 1027 return false; |
| 1025 notify_delegate_ = delegate; | 1028 notify_delegate_ = delegate; |
| 1026 if (!file_loop_->WatchFileDescriptor(inotify_fd_, true, | 1029 if (!file_loop_->WatchFileDescriptor(inotify_fd_, true, |
| 1027 MessageLoopForIO::WATCH_READ, &inotify_watcher_, this)) | 1030 MessageLoopForIO::WATCH_READ, &inotify_watcher_, this)) |
| 1028 return false; | 1031 return false; |
| 1029 // Simulate a change to avoid possibly losing updates before this point. | 1032 // Simulate a change to avoid possibly losing updates before this point. |
| 1030 OnChangeNotification(); | 1033 OnChangeNotification(); |
| 1031 return true; | 1034 return true; |
| 1032 } | 1035 } |
| 1033 | 1036 |
| 1034 virtual base::SingleThreadTaskRunner* GetNotificationTaskRunner() OVERRIDE { | 1037 virtual base::SingleThreadTaskRunner* GetNotificationTaskRunner() OVERRIDE { |
| 1035 return file_loop_ ? file_loop_->message_loop_proxy() : NULL; | 1038 return file_loop_ ? file_loop_->message_loop_proxy() : NULL; |
| 1036 } | 1039 } |
| 1037 | 1040 |
| 1038 // Implement base::MessagePumpLibevent::Watcher. | 1041 // Implement base::MessagePumpLibevent::Watcher. |
| 1039 void OnFileCanReadWithoutBlocking(int fd) { | 1042 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE { |
| 1040 DCHECK_EQ(fd, inotify_fd_); | 1043 DCHECK_EQ(fd, inotify_fd_); |
| 1041 DCHECK(MessageLoop::current() == file_loop_); | 1044 DCHECK(MessageLoop::current() == file_loop_); |
| 1042 OnChangeNotification(); | 1045 OnChangeNotification(); |
| 1043 } | 1046 } |
| 1044 void OnFileCanWriteWithoutBlocking(int fd) { | 1047 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE { |
| 1045 NOTREACHED(); | 1048 NOTREACHED(); |
| 1046 } | 1049 } |
| 1047 | 1050 |
| 1048 virtual ProxyConfigSource GetConfigSource() OVERRIDE { | 1051 virtual ProxyConfigSource GetConfigSource() OVERRIDE { |
| 1049 return PROXY_CONFIG_SOURCE_KDE; | 1052 return PROXY_CONFIG_SOURCE_KDE; |
| 1050 } | 1053 } |
| 1051 | 1054 |
| 1052 virtual bool GetString(StringSetting key, std::string* result) OVERRIDE { | 1055 virtual bool GetString(StringSetting key, std::string* result) OVERRIDE { |
| 1053 string_map_type::iterator it = string_table_.find(key); | 1056 string_map_type::iterator it = string_table_.find(key); |
| 1054 if (it == string_table_.end()) | 1057 if (it == string_table_.end()) |
| (...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1813 void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) { | 1816 void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) { |
| 1814 delegate_->RemoveObserver(observer); | 1817 delegate_->RemoveObserver(observer); |
| 1815 } | 1818 } |
| 1816 | 1819 |
| 1817 ProxyConfigService::ConfigAvailability | 1820 ProxyConfigService::ConfigAvailability |
| 1818 ProxyConfigServiceLinux::GetLatestProxyConfig(ProxyConfig* config) { | 1821 ProxyConfigServiceLinux::GetLatestProxyConfig(ProxyConfig* config) { |
| 1819 return delegate_->GetLatestProxyConfig(config); | 1822 return delegate_->GetLatestProxyConfig(config); |
| 1820 } | 1823 } |
| 1821 | 1824 |
| 1822 } // namespace net | 1825 } // namespace net |
| OLD | NEW |