diff options
Diffstat (limited to 'net/proxy/proxy_config_service_linux.cc')
-rw-r--r-- | net/proxy/proxy_config_service_linux.cc | 143 |
1 files changed, 71 insertions, 72 deletions
diff --git a/net/proxy/proxy_config_service_linux.cc b/net/proxy/proxy_config_service_linux.cc index c05e84f..732ac59 100644 --- a/net/proxy/proxy_config_service_linux.cc +++ b/net/proxy/proxy_config_service_linux.cc @@ -30,8 +30,8 @@ #include "base/file_util.h" #include "base/logging.h" #include "base/message_loop.h" -#include "base/message_loop_proxy.h" #include "base/nix/xdg_util.h" +#include "base/single_thread_task_runner.h" #include "base/string_number_conversions.h" #include "base/string_tokenizer.h" #include "base/string_util.h" @@ -202,7 +202,7 @@ class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter { public: SettingGetterImplGConf() : client_(NULL), system_proxy_id_(0), system_http_proxy_id_(0), - notify_delegate_(NULL), loop_(NULL) { + notify_delegate_(NULL) { } virtual ~SettingGetterImplGConf() { @@ -213,7 +213,7 @@ class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter { // and pending tasks may then be deleted without being run. if (client_) { // gconf client was not cleaned up. - if (loop_->BelongsToCurrentThread()) { + if (task_runner_->BelongsToCurrentThread()) { // We are on the UI thread so we can clean it safely. This is // the case at least for ui_tests running under Valgrind in // bug 16076. @@ -231,17 +231,17 @@ class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter { DCHECK(!client_); } - virtual bool Init(base::MessageLoopProxy* glib_default_loop, + virtual bool Init(base::SingleThreadTaskRunner* glib_thread_task_runner, MessageLoopForIO* file_loop) OVERRIDE { - DCHECK(glib_default_loop->BelongsToCurrentThread()); + DCHECK(glib_thread_task_runner->BelongsToCurrentThread()); DCHECK(!client_); - DCHECK(!loop_); - loop_ = glib_default_loop; + DCHECK(!task_runner_); + task_runner_ = glib_thread_task_runner; client_ = gconf_client_get_default(); if (!client_) { // It's not clear whether/when this can return NULL. LOG(ERROR) << "Unable to create a gconf client"; - loop_ = NULL; + task_runner_ = NULL; return false; } GError* error = NULL; @@ -264,7 +264,7 @@ class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter { gconf_client_remove_dir(client_, "/system/proxy", NULL); g_object_unref(client_); client_ = NULL; - loop_ = NULL; + task_runner_ = NULL; return false; } return true; @@ -272,7 +272,7 @@ class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter { void ShutDown() { if (client_) { - DCHECK(loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); // We must explicitly disable gconf notifications here, because the gconf // client will be shared between all setting getters, and they do not all // have the same lifetimes. (For instance, incognito sessions get their @@ -283,13 +283,13 @@ class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter { gconf_client_remove_dir(client_, "/system/proxy", NULL); g_object_unref(client_); client_ = NULL; - loop_ = NULL; + task_runner_ = NULL; } } bool SetUpNotifications(ProxyConfigServiceLinux::Delegate* delegate) { DCHECK(client_); - DCHECK(loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); GError* error = NULL; notify_delegate_ = delegate; // We have to keep track of the IDs returned by gconf_client_notify_add() so @@ -316,8 +316,8 @@ class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter { return true; } - virtual base::MessageLoopProxy* GetNotificationLoop() OVERRIDE { - return loop_; + virtual base::SingleThreadTaskRunner* GetNotificationTaskRunner() OVERRIDE { + return task_runner_; } virtual const char* GetDataSource() OVERRIDE { @@ -386,7 +386,7 @@ class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter { private: bool GetStringByPath(const char* key, std::string* result) { DCHECK(client_); - DCHECK(loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); GError* error = NULL; gchar* value = gconf_client_get_string(client_, key, &error); if (HandleGError(error, key)) @@ -399,7 +399,7 @@ class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter { } bool GetBoolByPath(const char* key, bool* result) { DCHECK(client_); - DCHECK(loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); GError* error = NULL; // We want to distinguish unset values from values defaulting to // false. For that we need to use the type-generic @@ -422,7 +422,7 @@ class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter { } bool GetIntByPath(const char* key, int* result) { DCHECK(client_); - DCHECK(loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); GError* error = NULL; int value = gconf_client_get_int(client_, key, &error); if (HandleGError(error, key)) @@ -434,7 +434,7 @@ class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter { } bool GetStringListByPath(const char* key, std::vector<std::string>* result) { DCHECK(client_); - DCHECK(loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); GError* error = NULL; GSList* list = gconf_client_get_list(client_, key, GCONF_VALUE_STRING, &error); @@ -464,7 +464,7 @@ class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter { // This is the callback from the debounce timer. void OnDebouncedNotification() { - DCHECK(loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); CHECK(notify_delegate_); // Forward to a method on the proxy config service delegate object. notify_delegate_->OnCheckProxyConfigSettings(); @@ -499,10 +499,10 @@ class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter { ProxyConfigServiceLinux::Delegate* notify_delegate_; base::OneShotTimer<SettingGetterImplGConf> debounce_timer_; - // Message loop of the thread that we make gconf calls on. It should + // Task runner for the thread that we make gconf calls on. It should // be the UI thread and all our methods should be called on this // thread. Only for assertions. - scoped_refptr<base::MessageLoopProxy> loop_; + scoped_refptr<base::SingleThreadTaskRunner> task_runner_; DISALLOW_COPY_AND_ASSIGN(SettingGetterImplGConf); }; @@ -529,8 +529,7 @@ class SettingGetterImplGSettings https_client_(NULL), ftp_client_(NULL), socks_client_(NULL), - notify_delegate_(NULL), - loop_(NULL) { + notify_delegate_(NULL) { } virtual ~SettingGetterImplGSettings() { @@ -542,7 +541,7 @@ class SettingGetterImplGSettings // without being run. if (client_) { // gconf client was not cleaned up. - if (loop_->BelongsToCurrentThread()) { + if (task_runner_->BelongsToCurrentThread()) { // We are on the UI thread so we can clean it safely. This is // the case at least for ui_tests running under Valgrind in // bug 16076. @@ -575,11 +574,11 @@ class SettingGetterImplGSettings // LoadAndCheckVersion() must be called *before* Init()! bool LoadAndCheckVersion(base::Environment* env); - virtual bool Init(base::MessageLoopProxy* glib_default_loop, + virtual bool Init(base::SingleThreadTaskRunner* glib_thread_task_runner, MessageLoopForIO* file_loop) OVERRIDE { - DCHECK(glib_default_loop->BelongsToCurrentThread()); + DCHECK(glib_thread_task_runner->BelongsToCurrentThread()); DCHECK(!client_); - DCHECK(!loop_); + DCHECK(!task_runner_); if (!SchemaExists("org.gnome.system.proxy") || !(client_ = g_settings_new("org.gnome.system.proxy"))) { @@ -587,7 +586,7 @@ class SettingGetterImplGSettings LOG(ERROR) << "Unable to create a gsettings client"; return false; } - loop_ = glib_default_loop; + task_runner_ = glib_thread_task_runner; // We assume these all work if the above call worked. http_client_ = g_settings_get_child(client_, "http"); https_client_ = g_settings_get_child(client_, "https"); @@ -599,7 +598,7 @@ class SettingGetterImplGSettings void ShutDown() { if (client_) { - DCHECK(loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); // This also disables gsettings notifications. g_object_unref(socks_client_); g_object_unref(ftp_client_); @@ -608,13 +607,13 @@ class SettingGetterImplGSettings g_object_unref(client_); // We only need to null client_ because it's the only one that we check. client_ = NULL; - loop_ = NULL; + task_runner_ = NULL; } } bool SetUpNotifications(ProxyConfigServiceLinux::Delegate* delegate) { DCHECK(client_); - DCHECK(loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); notify_delegate_ = delegate; // We could watch for the change-event signal instead of changed, but // since we have to watch more than one object, we'd still have to @@ -634,8 +633,8 @@ class SettingGetterImplGSettings return true; } - virtual base::MessageLoopProxy* GetNotificationLoop() OVERRIDE { - return loop_; + virtual base::SingleThreadTaskRunner* GetNotificationTaskRunner() OVERRIDE { + return task_runner_; } virtual const char* GetDataSource() OVERRIDE { @@ -745,7 +744,7 @@ class SettingGetterImplGSettings bool GetStringByPath(GSettings* client, const char* key, std::string* result) { - DCHECK(loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); gchar* value = g_settings_get_string(client, key); if (!value) return false; @@ -754,18 +753,18 @@ class SettingGetterImplGSettings return true; } bool GetBoolByPath(GSettings* client, const char* key, bool* result) { - DCHECK(loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); *result = static_cast<bool>(g_settings_get_boolean(client, key)); return true; } bool GetIntByPath(GSettings* client, const char* key, int* result) { - DCHECK(loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); *result = g_settings_get_int(client, key); return true; } bool GetStringListByPath(GSettings* client, const char* key, std::vector<std::string>* result) { - DCHECK(loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); gchar** list = g_settings_get_strv(client, key); if (!list) return false; @@ -779,7 +778,7 @@ class SettingGetterImplGSettings // This is the callback from the debounce timer. void OnDebouncedNotification() { - DCHECK(loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); CHECK(notify_delegate_); // Forward to a method on the proxy config service delegate object. notify_delegate_->OnCheckProxyConfigSettings(); @@ -812,10 +811,10 @@ class SettingGetterImplGSettings ProxyConfigServiceLinux::Delegate* notify_delegate_; base::OneShotTimer<SettingGetterImplGSettings> debounce_timer_; - // Message loop of the thread that we make gsettings calls on. It should + // Task runner for the thread that we make gsettings calls on. It should // be the UI thread and all our methods should be called on this // thread. Only for assertions. - scoped_refptr<base::MessageLoopProxy> loop_; + scoped_refptr<base::SingleThreadTaskRunner> task_runner_; DISALLOW_COPY_AND_ASSIGN(SettingGetterImplGSettings); }; @@ -979,7 +978,7 @@ class SettingGetterImplKDE : public ProxyConfigServiceLinux::SettingGetter, DCHECK(inotify_fd_ < 0); } - virtual bool Init(base::MessageLoopProxy* glib_default_loop, + virtual bool Init(base::SingleThreadTaskRunner* glib_thread_task_runner, MessageLoopForIO* file_loop) OVERRIDE { // This has to be called on the UI thread (http://crbug.com/69057). base::ThreadRestrictions::ScopedAllowIO allow_io; @@ -1032,7 +1031,7 @@ class SettingGetterImplKDE : public ProxyConfigServiceLinux::SettingGetter, return true; } - virtual base::MessageLoopProxy* GetNotificationLoop() OVERRIDE { + virtual base::SingleThreadTaskRunner* GetNotificationTaskRunner() OVERRIDE { return file_loop_->message_loop_proxy(); } @@ -1567,8 +1566,7 @@ bool ProxyConfigServiceLinux::Delegate::GetConfigFromSettings( } ProxyConfigServiceLinux::Delegate::Delegate(base::Environment* env_var_getter) - : env_var_getter_(env_var_getter), - glib_default_loop_(NULL), io_loop_(NULL) { + : env_var_getter_(env_var_getter) { // Figure out which SettingGetterImpl to use, if any. switch (base::nix::GetDesktopEnvironment(env_var_getter)) { case base::nix::DESKTOP_ENVIRONMENT_GNOME: @@ -1600,24 +1598,24 @@ ProxyConfigServiceLinux::Delegate::Delegate(base::Environment* env_var_getter) ProxyConfigServiceLinux::Delegate::Delegate( base::Environment* env_var_getter, SettingGetter* setting_getter) - : env_var_getter_(env_var_getter), setting_getter_(setting_getter), - glib_default_loop_(NULL), io_loop_(NULL) { + : env_var_getter_(env_var_getter), setting_getter_(setting_getter) { } void ProxyConfigServiceLinux::Delegate::SetUpAndFetchInitialConfig( - base::MessageLoopProxy* glib_default_loop, - base::MessageLoopProxy* io_loop, + base::SingleThreadTaskRunner* glib_thread_task_runner, + base::SingleThreadTaskRunner* io_thread_task_runner, MessageLoopForIO* file_loop) { // We should be running on the default glib main loop thread right // now. gconf can only be accessed from this thread. - DCHECK(glib_default_loop->BelongsToCurrentThread()); - glib_default_loop_ = glib_default_loop; - io_loop_ = io_loop; - - // If we are passed a NULL io_loop or file_loop, then we don't set up - // proxy setting change notifications. This should not be the usual - // case but is intended to simplify test setups. - if (!io_loop_ || !file_loop) + DCHECK(glib_thread_task_runner->BelongsToCurrentThread()); + glib_thread_task_runner_ = glib_thread_task_runner; + io_thread_task_runner_ = io_thread_task_runner; + + // If we are passed a NULL |io_thread_task_runner| or |file_loop|, + // then we don't set up proxy setting change notifications. This + // should not be the usual case but is intended to simplify test + // setups. + if (!io_thread_task_runner_ || !file_loop) VLOG(1) << "Monitoring of proxy setting changes is disabled"; // Fetch and cache the current proxy config. The config is left in @@ -1634,7 +1632,7 @@ void ProxyConfigServiceLinux::Delegate::SetUpAndFetchInitialConfig( bool got_config = false; if (setting_getter_.get() && - setting_getter_->Init(glib_default_loop, file_loop) && + setting_getter_->Init(glib_thread_task_runner, file_loop) && GetConfigFromSettings(&cached_config_)) { cached_config_.set_id(1); // Mark it as valid. VLOG(1) << "Obtained proxy settings from " @@ -1658,9 +1656,9 @@ void ProxyConfigServiceLinux::Delegate::SetUpAndFetchInitialConfig( // that we won't lose any updates that may have happened after the initial // fetch and before setting up notifications. We'll detect the common case // of no changes in OnCheckProxyConfigSettings() (or sooner) and ignore it. - if (io_loop && file_loop) { - scoped_refptr<base::MessageLoopProxy> required_loop = - setting_getter_->GetNotificationLoop(); + if (io_thread_task_runner && file_loop) { + scoped_refptr<base::SingleThreadTaskRunner> required_loop = + setting_getter_->GetNotificationTaskRunner(); if (!required_loop || required_loop->BelongsToCurrentThread()) { // In this case we are already on an acceptable thread. SetUpNotifications(); @@ -1687,8 +1685,8 @@ void ProxyConfigServiceLinux::Delegate::SetUpAndFetchInitialConfig( // Depending on the SettingGetter in use, this method will be called // on either the UI thread (GConf) or the file thread (KDE). void ProxyConfigServiceLinux::Delegate::SetUpNotifications() { - scoped_refptr<base::MessageLoopProxy> required_loop = - setting_getter_->GetNotificationLoop(); + scoped_refptr<base::SingleThreadTaskRunner> required_loop = + setting_getter_->GetNotificationTaskRunner(); DCHECK(!required_loop || required_loop->BelongsToCurrentThread()); if (!setting_getter_->SetUpNotifications(this)) LOG(ERROR) << "Unable to set up proxy configuration change notifications"; @@ -1706,7 +1704,8 @@ ProxyConfigService::ConfigAvailability ProxyConfigServiceLinux::Delegate::GetLatestProxyConfig( ProxyConfig* config) { // This is called from the IO thread. - DCHECK(!io_loop_ || io_loop_->BelongsToCurrentThread()); + DCHECK(!io_thread_task_runner_ || + io_thread_task_runner_->BelongsToCurrentThread()); // Simply return the last proxy configuration that glib_default_loop // notified us of. @@ -1724,8 +1723,8 @@ ProxyConfigService::ConfigAvailability // Depending on the SettingGetter in use, this method will be called // on either the UI thread (GConf) or the file thread (KDE). void ProxyConfigServiceLinux::Delegate::OnCheckProxyConfigSettings() { - scoped_refptr<base::MessageLoopProxy> required_loop = - setting_getter_->GetNotificationLoop(); + scoped_refptr<base::SingleThreadTaskRunner> required_loop = + setting_getter_->GetNotificationTaskRunner(); DCHECK(!required_loop || required_loop->BelongsToCurrentThread()); ProxyConfig new_config; bool valid = GetConfigFromSettings(&new_config); @@ -1735,9 +1734,9 @@ void ProxyConfigServiceLinux::Delegate::OnCheckProxyConfigSettings() { // See if it is different from what we had before. if (new_config.is_valid() != reference_config_.is_valid() || !new_config.Equals(reference_config_)) { - // Post a task to |io_loop| with the new configuration, so it can + // Post a task to the IO thread with the new configuration, so it can // update |cached_config_|. - io_loop_->PostTask(FROM_HERE, base::Bind( + io_thread_task_runner_->PostTask(FROM_HERE, base::Bind( &ProxyConfigServiceLinux::Delegate::SetNewProxyConfig, this, new_config)); // Update the thread-private copy in |reference_config_| as well. @@ -1749,7 +1748,7 @@ void ProxyConfigServiceLinux::Delegate::OnCheckProxyConfigSettings() { void ProxyConfigServiceLinux::Delegate::SetNewProxyConfig( const ProxyConfig& new_config) { - DCHECK(io_loop_->BelongsToCurrentThread()); + DCHECK(io_thread_task_runner_->BelongsToCurrentThread()); VLOG(1) << "Proxy configuration changed"; cached_config_ = new_config; FOR_EACH_OBSERVER( @@ -1760,8 +1759,8 @@ void ProxyConfigServiceLinux::Delegate::SetNewProxyConfig( void ProxyConfigServiceLinux::Delegate::PostDestroyTask() { if (!setting_getter_.get()) return; - scoped_refptr<base::MessageLoopProxy> shutdown_loop = - setting_getter_->GetNotificationLoop(); + scoped_refptr<base::SingleThreadTaskRunner> shutdown_loop = + setting_getter_->GetNotificationTaskRunner(); if (!shutdown_loop || shutdown_loop->BelongsToCurrentThread()) { // Already on the right thread, call directly. // This is the case for the unittests. @@ -1774,8 +1773,8 @@ void ProxyConfigServiceLinux::Delegate::PostDestroyTask() { } } void ProxyConfigServiceLinux::Delegate::OnDestroy() { - scoped_refptr<base::MessageLoopProxy> shutdown_loop = - setting_getter_->GetNotificationLoop(); + scoped_refptr<base::SingleThreadTaskRunner> shutdown_loop = + setting_getter_->GetNotificationTaskRunner(); DCHECK(!shutdown_loop || shutdown_loop->BelongsToCurrentThread()); setting_getter_->ShutDown(); } |