summaryrefslogtreecommitdiffstats
path: root/chrome/browser/browser_about_handler.cc
diff options
context:
space:
mode:
authoreroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-08 18:35:14 +0000
committereroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-08 18:35:14 +0000
commitec86bea44a17187127f3b5a07524dc533d07705c (patch)
treee81b90e5151fb3b29d345abb4408bf0e1288d099 /chrome/browser/browser_about_handler.cc
parent53a8ff8ea2865783e63ffa3d8388a5b023353b39 (diff)
downloadchromium_src-ec86bea44a17187127f3b5a07524dc533d07705c.zip
chromium_src-ec86bea44a17187127f3b5a07524dc533d07705c.tar.gz
chromium_src-ec86bea44a17187127f3b5a07524dc533d07705c.tar.bz2
Refactor: Eliminte locking from PrefetchObserver and DnsMaster in favor of making these classes non-threadsafe.
Conceptually, PrefetchObserver and DnsMaster live on the IO thread, and their methods can only be called from the IO thread. In the cases where calls do need to be made from the UI thread, we post a task to be run on the IO loop and return without blocking. The only time where we block is during shutdown, when we must wait on the IO thread to get us the startup list and referral list. BUG=25335 Review URL: http://codereview.chromium.org/300032 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34066 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/browser_about_handler.cc')
-rw-r--r--chrome/browser/browser_about_handler.cc57
1 files changed, 51 insertions, 6 deletions
diff --git a/chrome/browser/browser_about_handler.cc b/chrome/browser/browser_about_handler.cc
index 8ae39e0..128ad14 100644
--- a/chrome/browser/browser_about_handler.cc
+++ b/chrome/browser/browser_about_handler.cc
@@ -210,11 +210,55 @@ std::string AboutOSCredits() {
}
#endif
-std::string AboutDns() {
- std::string data;
- chrome_browser_net::DnsPrefetchGetHtmlInfo(&data);
- return data;
-}
+// AboutDnsHandler bounces the request back to the IO thread to collect
+// the DNS information.
+class AboutDnsHandler : public base::RefCountedThreadSafe<AboutDnsHandler> {
+ public:
+ static void Start(AboutSource* source, int request_id) {
+ scoped_refptr<AboutDnsHandler> handler =
+ new AboutDnsHandler(source, request_id);
+ handler->StartOnUIThread();
+ }
+
+ private:
+ AboutDnsHandler(AboutSource* source, int request_id)
+ : source_(source),
+ request_id_(request_id) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
+ }
+
+ // Calls FinishOnUIThread() on completion.
+ void StartOnUIThread() {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(this, &AboutDnsHandler::StartOnIOThread));
+ }
+
+ void StartOnIOThread() {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+
+ std::string data;
+ chrome_browser_net::DnsPrefetchGetHtmlInfo(&data);
+
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE,
+ NewRunnableMethod(this, &AboutDnsHandler::FinishOnUIThread, data));
+ }
+
+ void FinishOnUIThread(const std::string& data) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
+ source_->FinishDataRequest(data, request_id_);
+ }
+
+ // Where the results are fed to.
+ scoped_refptr<AboutSource> source_;
+
+ // ID identifying the request.
+ int request_id_;
+
+ DISALLOW_COPY_AND_ASSIGN(AboutDnsHandler);
+};
#if defined(USE_TCMALLOC)
std::string AboutTcmalloc(const std::string& query) {
@@ -619,7 +663,8 @@ void AboutSource::StartDataRequest(const std::string& path_raw,
std::string response;
if (path == kDnsPath) {
- response = AboutDns();
+ AboutDnsHandler::Start(this, request_id);
+ return;
} else if (path == kHistogramsPath) {
response = AboutHistograms(info);
} else if (path == kMemoryPath) {