diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-22 21:24:36 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-22 21:24:36 +0000 |
commit | 23056f87ae27274aae0ce642de01c5737b7882f4 (patch) | |
tree | 09d8c93071a13f11a5f9150e7eacfbb4a883eb20 | |
parent | 2123cbae0986af60da4159862d7ac10a417de8fd (diff) | |
download | chromium_src-23056f87ae27274aae0ce642de01c5737b7882f4.zip chromium_src-23056f87ae27274aae0ce642de01c5737b7882f4.tar.gz chromium_src-23056f87ae27274aae0ce642de01c5737b7882f4.tar.bz2 |
Make sure the service process kills all URLFetcher::Cores on shutdown.
I'm not sure this is strictly necessary, since it may be that due to how the service process uses URLFetcher, that all fetches are already canceled by the time its IO thread shuts down. But this makes absolutely sure this is the case. Good practice in any case.
This also makes it completely safe for us to have URLFetcher::Core stop using the DestructionObserver.
BUG=59630
TEST=existing
Review URL: http://codereview.chromium.org/3969006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63568 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/common/net/url_fetcher.cc | 14 | ||||
-rw-r--r-- | chrome/service/service_process.cc | 32 |
2 files changed, 30 insertions, 16 deletions
diff --git a/chrome/common/net/url_fetcher.cc b/chrome/common/net/url_fetcher.cc index dda3ca7..ebc876d 100644 --- a/chrome/common/net/url_fetcher.cc +++ b/chrome/common/net/url_fetcher.cc @@ -30,7 +30,6 @@ bool URLFetcher::g_interception_enabled = false; class URLFetcher::Core : public base::RefCountedThreadSafe<URLFetcher::Core>, - public MessageLoop::DestructionObserver, public URLRequest::Delegate { public: // For POST requests, set |content_type| to the MIME type of the content @@ -54,10 +53,6 @@ class URLFetcher::Core // safe to call this multiple times. void Stop(); - // MessageLoop::DestructionObserver implementation. We are only registered as - // a DestructionObserver when |request_| exists. - virtual void WillDestroyCurrentMessageLoop(); - // URLRequest::Delegate implementation. virtual void OnResponseStarted(URLRequest* request); virtual void OnReadCompleted(URLRequest* request, int bytes_read); @@ -235,13 +230,6 @@ void URLFetcher::Core::Stop() { } } -void URLFetcher::Core::WillDestroyCurrentMessageLoop() { - CancelURLRequest(); - // Don't bother to try and notify the delegate thread portion of this object, - // since if the IO thread is shutting down, everything is shutting down, and - // we just want to avoid leaks. -} - void URLFetcher::Core::CancelAll() { g_registry.Get().CancelAll(); } @@ -299,7 +287,6 @@ void URLFetcher::Core::StartURLRequest() { CHECK(request_context_getter_); DCHECK(!request_.get()); - MessageLoop::current()->AddDestructionObserver(this); g_registry.Get().AddURLFetcherCore(this); request_.reset(new URLRequest(original_url_, this)); int flags = request_->load_flags() | load_flags_; @@ -392,7 +379,6 @@ void URLFetcher::Core::OnCompletedURLRequest(const URLRequestStatus& status) { void URLFetcher::Core::ReleaseRequest() { request_.reset(); g_registry.Get().RemoveURLFetcherCore(this); - MessageLoop::current()->RemoveDestructionObserver(this); } void URLFetcher::set_upload_data(const std::string& upload_content_type, diff --git a/chrome/service/service_process.cc b/chrome/service/service_process.cc index 97919cd..1ec4a83 100644 --- a/chrome/service/service_process.cc +++ b/chrome/service/service_process.cc @@ -6,6 +6,7 @@ #include <algorithm> +#include "base/basictypes.h" #include "base/command_line.h" #include "base/path_service.h" #include "base/singleton.h" @@ -43,9 +44,36 @@ ServiceProcess* g_service_process = NULL; +namespace { + // Delay in millseconds after the last service is disabled before we attempt // a shutdown. -static const int64 kShutdownDelay = 60000; +const int64 kShutdownDelay = 60000; + +class ServiceIOThread : public base::Thread { + public: + explicit ServiceIOThread(const char* name); + virtual ~ServiceIOThread(); + + protected: + virtual void CleanUp(); + + private: + DISALLOW_COPY_AND_ASSIGN(ServiceIOThread); +}; + +ServiceIOThread::ServiceIOThread(const char* name) : base::Thread(name) {} +ServiceIOThread::~ServiceIOThread() { + // We cannot rely on our base class to stop the thread since we want our + // CleanUp function to run. + Stop(); +} + +void ServiceIOThread::CleanUp() { + URLFetcher::CancelAll(); +} + +} // namespace ServiceProcess::ServiceProcess() : shutdown_event_(true, false), @@ -62,7 +90,7 @@ bool ServiceProcess::Initialize(MessageLoop* message_loop, network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); base::Thread::Options options; options.message_loop_type = MessageLoop::TYPE_IO; - io_thread_.reset(new base::Thread("ServiceProcess_IO")); + io_thread_.reset(new ServiceIOThread("ServiceProcess_IO")); file_thread_.reset(new base::Thread("ServiceProcess_File")); if (!io_thread_->StartWithOptions(options) || !file_thread_->StartWithOptions(options)) { |