diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-24 08:26:46 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-24 08:26:46 +0000 |
commit | 7672247cf3de10b55378d0591bdd5970c17a7f31 (patch) | |
tree | ca71a66222a57afc352e44bb0cde5ba274137064 /net | |
parent | df6f2e1db4e6478dc62b5aa11f33e845734e6717 (diff) | |
download | chromium_src-7672247cf3de10b55378d0591bdd5970c17a7f31.zip chromium_src-7672247cf3de10b55378d0591bdd5970c17a7f31.tar.gz chromium_src-7672247cf3de10b55378d0591bdd5970c17a7f31.tar.bz2 |
Use SingleThreadTaskRunner instead of MessageLoopProxy in ProxyConfigService.
MessageLoopProxy is not usable in plugin, and so it's not possible to use ProxyConfigService in plugins if it uses MessageLoopProxy.
Review URL: https://chromiumcodereview.appspot.com/10414061
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138751 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/proxy/proxy_config_service_linux.cc | 143 | ||||
-rw-r--r-- | net/proxy/proxy_config_service_linux.h | 34 | ||||
-rw-r--r-- | net/proxy/proxy_config_service_linux_unittest.cc | 4 | ||||
-rw-r--r-- | net/proxy/proxy_config_service_mac.cc | 19 | ||||
-rw-r--r-- | net/proxy/proxy_config_service_mac.h | 11 | ||||
-rw-r--r-- | net/proxy/proxy_service.cc | 18 | ||||
-rw-r--r-- | net/proxy/proxy_service.h | 7 | ||||
-rw-r--r-- | net/url_request/url_request_context_builder.cc | 3 |
8 files changed, 126 insertions, 113 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(); } diff --git a/net/proxy/proxy_config_service_linux.h b/net/proxy/proxy_config_service_linux.h index ffaa988..ed8cef1 100644 --- a/net/proxy/proxy_config_service_linux.h +++ b/net/proxy/proxy_config_service_linux.h @@ -23,7 +23,7 @@ class MessageLoopForIO; namespace base { -class MessageLoopProxy; +class SingleThreadTaskRunner; } // namespace base namespace net { @@ -49,10 +49,10 @@ class NET_EXPORT_PRIVATE ProxyConfigServiceLinux : public ProxyConfigService { // one, in the concrete implementations. Returns true on success. Must be // called before using other methods, and should be called on the thread // running the glib main loop. - // One of |glib_default_loop| and |file_loop| will be used for + // One of |glib_thread_task_runner| and |file_loop| will be used for // gconf/gsettings calls or reading necessary files, depending on the // implementation. - virtual bool Init(base::MessageLoopProxy* glib_default_loop, + virtual bool Init(base::SingleThreadTaskRunner* glib_thread_task_runner, MessageLoopForIO* file_loop) = 0; // Releases the gconf/gsettings client, which clears cached directories and @@ -66,7 +66,7 @@ class NET_EXPORT_PRIVATE ProxyConfigServiceLinux : public ProxyConfigService { // Returns the message loop for the thread on which this object // handles notifications, and also on which it must be destroyed. // Returns NULL if it does not matter. - virtual base::MessageLoopProxy* GetNotificationLoop() = 0; + virtual base::SingleThreadTaskRunner* GetNotificationTaskRunner() = 0; // Returns the data source's name (e.g. "gconf", "gsettings", "KDE", // "test"). Used only for diagnostic purposes (e.g. VLOG(1) etc.). @@ -182,9 +182,10 @@ class NET_EXPORT_PRIVATE ProxyConfigServiceLinux : public ProxyConfigService { // thread is specified so that notifications can post tasks to it // (and for assertions). The message loop for the file thread is // used to read any files needed to determine proxy settings. - void SetUpAndFetchInitialConfig(base::MessageLoopProxy* glib_default_loop, - base::MessageLoopProxy* io_loop, - MessageLoopForIO* file_loop); + void SetUpAndFetchInitialConfig( + base::SingleThreadTaskRunner* glib_thread_task_runner, + base::SingleThreadTaskRunner* io_thread_task_runner, + MessageLoopForIO* file_loop); // Handler for setting change notifications: fetches a new proxy // configuration from settings, and if this config is different @@ -252,7 +253,7 @@ class NET_EXPORT_PRIVATE ProxyConfigServiceLinux : public ProxyConfigService { // notification but the config has not actually changed. ProxyConfig reference_config_; - // The MessageLoop for the UI thread, aka main browser thread. This thread + // The task runner for the glib thread, aka main browser thread. This thread // is where we run the glib main loop (see base/message_pump_glib.h). It is // the glib default loop in the sense that it runs the glib default context: // as in the context where sources are added by g_timeout_add and @@ -260,10 +261,10 @@ class NET_EXPORT_PRIVATE ProxyConfigServiceLinux : public ProxyConfigService { // timeouts and idles and possibly other callbacks that will all be // dispatched on this thread. Since gconf is not thread safe, any use of // gconf must be done on the thread running this loop. - scoped_refptr<base::MessageLoopProxy> glib_default_loop_; - // MessageLoop for the IO thread. GetLatestProxyConfig() is called from + scoped_refptr<base::SingleThreadTaskRunner> glib_thread_task_runner_; + // Task runner for the IO thread. GetLatestProxyConfig() is called from // the thread running this loop. - scoped_refptr<base::MessageLoopProxy> io_loop_; + scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner_; ObserverList<Observer> observers_; @@ -281,11 +282,12 @@ class NET_EXPORT_PRIVATE ProxyConfigServiceLinux : public ProxyConfigService { virtual ~ProxyConfigServiceLinux(); - void SetupAndFetchInitialConfig(base::MessageLoopProxy* glib_default_loop, - base::MessageLoopProxy* io_loop, - MessageLoopForIO* file_loop) { - delegate_->SetUpAndFetchInitialConfig(glib_default_loop, io_loop, - file_loop); + void SetupAndFetchInitialConfig( + base::SingleThreadTaskRunner* glib_thread_task_runner, + base::SingleThreadTaskRunner* io_thread_task_runner, + MessageLoopForIO* file_loop) { + delegate_->SetUpAndFetchInitialConfig(glib_thread_task_runner, + io_thread_task_runner, file_loop); } void OnCheckProxyConfigSettings() { delegate_->OnCheckProxyConfigSettings(); diff --git a/net/proxy/proxy_config_service_linux_unittest.cc b/net/proxy/proxy_config_service_linux_unittest.cc index 766155b..0c292a5 100644 --- a/net/proxy/proxy_config_service_linux_unittest.cc +++ b/net/proxy/proxy_config_service_linux_unittest.cc @@ -175,7 +175,7 @@ class MockSettingGetter values = zero_values; } - virtual bool Init(base::MessageLoopProxy* glib_default_loop, + virtual bool Init(base::SingleThreadTaskRunner* glib_thread_task_runner, MessageLoopForIO* file_loop) OVERRIDE { return true; } @@ -187,7 +187,7 @@ class MockSettingGetter return true; } - virtual base::MessageLoopProxy* GetNotificationLoop() OVERRIDE { + virtual base::SingleThreadTaskRunner* GetNotificationTaskRunner() OVERRIDE { return NULL; } diff --git a/net/proxy/proxy_config_service_mac.cc b/net/proxy/proxy_config_service_mac.cc index a3b2f2b..7c4b8bf 100644 --- a/net/proxy/proxy_config_service_mac.cc +++ b/net/proxy/proxy_config_service_mac.cc @@ -185,17 +185,18 @@ class ProxyConfigServiceMac::Helper ProxyConfigServiceMac* parent_; }; -ProxyConfigServiceMac::ProxyConfigServiceMac(MessageLoop* io_loop) +ProxyConfigServiceMac::ProxyConfigServiceMac( + base::SingleThreadTaskRunner* io_thread_task_runner) : forwarder_(this), has_fetched_config_(false), helper_(new Helper(this)), - io_loop_(io_loop) { - DCHECK(io_loop); + io_thread_task_runner_(io_thread_task_runner) { + DCHECK(io_thread_task_runner_); config_watcher_.reset(new NetworkConfigWatcherMac(&forwarder_)); } ProxyConfigServiceMac::~ProxyConfigServiceMac() { - DCHECK_EQ(io_loop_, MessageLoop::current()); + DCHECK(io_thread_task_runner_->BelongsToCurrentThread()); // Delete the config_watcher_ to ensure the notifier thread finishes before // this object is destroyed. config_watcher_.reset(); @@ -203,18 +204,18 @@ ProxyConfigServiceMac::~ProxyConfigServiceMac() { } void ProxyConfigServiceMac::AddObserver(Observer* observer) { - DCHECK_EQ(io_loop_, MessageLoop::current()); + DCHECK(io_thread_task_runner_->BelongsToCurrentThread()); observers_.AddObserver(observer); } void ProxyConfigServiceMac::RemoveObserver(Observer* observer) { - DCHECK_EQ(io_loop_, MessageLoop::current()); + DCHECK(io_thread_task_runner_->BelongsToCurrentThread()); observers_.RemoveObserver(observer); } net::ProxyConfigService::ConfigAvailability ProxyConfigServiceMac::GetLatestProxyConfig(ProxyConfig* config) { - DCHECK_EQ(io_loop_, MessageLoop::current()); + DCHECK(io_thread_task_runner_->BelongsToCurrentThread()); // Lazy-initialize by fetching the proxy setting from this thread. if (!has_fetched_config_) { @@ -250,14 +251,14 @@ void ProxyConfigServiceMac::OnNetworkConfigChange(CFArrayRef changed_keys) { GetCurrentProxyConfig(&new_config); // Call OnProxyConfigChanged() on the IO thread to notify our observers. - io_loop_->PostTask( + io_thread_task_runner_->PostTask( FROM_HERE, base::Bind(&Helper::OnProxyConfigChanged, helper_.get(), new_config)); } void ProxyConfigServiceMac::OnProxyConfigChanged( const ProxyConfig& new_config) { - DCHECK_EQ(io_loop_, MessageLoop::current()); + DCHECK(io_thread_task_runner_->BelongsToCurrentThread()); // Keep track of the last value we have seen. has_fetched_config_ = true; diff --git a/net/proxy/proxy_config_service_mac.h b/net/proxy/proxy_config_service_mac.h index 8056b7a..8e9e59c 100644 --- a/net/proxy/proxy_config_service_mac.h +++ b/net/proxy/proxy_config_service_mac.h @@ -15,7 +15,9 @@ #include "net/proxy/proxy_config.h" #include "net/proxy/proxy_config_service.h" -class MessageLoop; +namespace base { +class SingleThreadTaskRunner; +} // namespace base namespace net { @@ -25,9 +27,10 @@ namespace net { class NET_EXPORT ProxyConfigServiceMac : public ProxyConfigService { public: // Constructs a ProxyConfigService that watches the Mac OS system settings. - // This instance is expected to be operated and deleted on |io_loop| + // This instance is expected to be operated and deleted on the IO thread // (however it may be constructed from a different thread). - explicit ProxyConfigServiceMac(MessageLoop* io_loop); + explicit ProxyConfigServiceMac( + base::SingleThreadTaskRunner* io_thread_task_runner); virtual ~ProxyConfigServiceMac(); public: @@ -80,7 +83,7 @@ class NET_EXPORT ProxyConfigServiceMac : public ProxyConfigService { scoped_refptr<Helper> helper_; // The thread that we expect to be operated on. - MessageLoop* io_loop_; + const scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner_; DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceMac); }; diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc index 1c92033..3cd82a5 100644 --- a/net/proxy/proxy_service.cc +++ b/net/proxy/proxy_service.cc @@ -14,6 +14,7 @@ #include "base/message_loop.h" #include "base/message_loop_proxy.h" #include "base/string_util.h" +#include "base/thread_task_runner_handle.h" #include "base/values.h" #include "googleurl/src/gurl.h" #include "net/base/completion_callback.h" @@ -1419,11 +1420,12 @@ void ProxyService::ForceReloadProxyConfig() { // static ProxyConfigService* ProxyService::CreateSystemProxyConfigService( - MessageLoop* io_loop, MessageLoop* file_loop) { + base::SingleThreadTaskRunner* io_thread_task_runner, + MessageLoop* file_loop) { #if defined(OS_WIN) return new ProxyConfigServiceWin(); #elif defined(OS_MACOSX) - return new ProxyConfigServiceMac(io_loop); + return new ProxyConfigServiceMac(io_thread_task_runner); #elif defined(OS_CHROMEOS) LOG(ERROR) << "ProxyConfigService for ChromeOS should be created in " << "profile_io_data.cc::CreateProxyConfigService and this should " @@ -1433,10 +1435,11 @@ ProxyConfigService* ProxyService::CreateSystemProxyConfigService( ProxyConfigServiceLinux* linux_config_service = new ProxyConfigServiceLinux(); - // Assume we got called from the UI loop, which runs the default - // glib main loop, so the current thread is where we should be - // running gconf calls from. - MessageLoop* glib_default_loop = MessageLoopForUI::current(); + // Assume we got called on the thread that runs the default glib + // main loop, so the current thread is where we should be running + // gconf calls from. + scoped_refptr<base::SingleThreadTaskRunner> glib_thread_task_runner = + base::ThreadTaskRunnerHandle::Get(); // The file loop should be a MessageLoopForIO on Linux. DCHECK_EQ(MessageLoop::TYPE_IO, file_loop->type()); @@ -1446,8 +1449,7 @@ ProxyConfigService* ProxyService::CreateSystemProxyConfigService( // notifications (delivered in either |glib_default_loop| or // |file_loop|) to keep us updated when the proxy config changes. linux_config_service->SetupAndFetchInitialConfig( - glib_default_loop->message_loop_proxy(), - io_loop->message_loop_proxy(), + glib_thread_task_runner, io_thread_task_runner, static_cast<MessageLoopForIO*>(file_loop)); return linux_config_service; diff --git a/net/proxy/proxy_service.h b/net/proxy/proxy_service.h index ac32408..31d00be 100644 --- a/net/proxy/proxy_service.h +++ b/net/proxy/proxy_service.h @@ -26,6 +26,10 @@ class GURL; class MessageLoop; +namespace base { +class SingleThreadTaskRunner; +} // namespace base + namespace net { class DhcpProxyScriptFetcher; @@ -271,7 +275,8 @@ class NET_EXPORT ProxyService : public NetworkChangeNotifier::IPAddressObserver, // Creates a config service appropriate for this platform that fetches the // system proxy settings. static ProxyConfigService* CreateSystemProxyConfigService( - MessageLoop* io_loop, MessageLoop* file_loop); + base::SingleThreadTaskRunner* io_thread_task_runner, + MessageLoop* file_loop); // This method should only be used by unit tests. void set_stall_proxy_auto_config_delay(base::TimeDelta delay) { diff --git a/net/url_request/url_request_context_builder.cc b/net/url_request/url_request_context_builder.cc index d4fab8a..b08904e 100644 --- a/net/url_request/url_request_context_builder.cc +++ b/net/url_request/url_request_context_builder.cc @@ -10,6 +10,7 @@ #include "base/compiler_specific.h" #include "base/logging.h" #include "base/threading/thread.h" +#include "base/thread_task_runner_handle.h" #include "net/base/cert_verifier.h" #include "net/base/host_resolver.h" #include "net/base/net_errors.h" @@ -207,7 +208,7 @@ URLRequestContext* URLRequestContextBuilder::Build() { #else ProxyConfigService* proxy_config_service = ProxyService::CreateSystemProxyConfigService( - MessageLoop::current(), + base::ThreadTaskRunnerHandle::Get(), context->file_message_loop()); #endif // defined(OS_LINUX) storage->set_proxy_service( |