Index: chrome/browser/dom_ui/chrome_url_data_manager.cc |
diff --git a/chrome/browser/dom_ui/chrome_url_data_manager.cc b/chrome/browser/dom_ui/chrome_url_data_manager.cc |
index 5b69fe543baa61f3ec36e027ae7cb64736f56114..3193d7b2c64e1fbda3e16e2b1d2153e8d0fd8268 100644 |
--- a/chrome/browser/dom_ui/chrome_url_data_manager.cc |
+++ b/chrome/browser/dom_ui/chrome_url_data_manager.cc |
@@ -5,12 +5,14 @@ |
#include "chrome/browser/dom_ui/chrome_url_data_manager.h" |
#include "app/l10n_util.h" |
+ #include "base/debug/stack_trace.h" |
eroman
2011/01/19 22:47:01
Is this intentional? Please remove.
ahendrickson
2011/01/21 16:04:31
Cleanup fail.
Removed.
|
#include "base/file_util.h" |
#include "base/i18n/rtl.h" |
#include "base/message_loop.h" |
#include "base/path_service.h" |
#include "base/ref_counted_memory.h" |
#include "base/singleton.h" |
+#include "base/stl_util-inl.h" |
#include "base/string_util.h" |
#include "base/threading/thread.h" |
#include "base/values.h" |
@@ -186,9 +188,29 @@ ChromeURLDataManager* ChromeURLDataManager::GetInstance() { |
void ChromeURLDataManager::AddDataSource(scoped_refptr<DataSource> source) { |
// TODO(jackson): A new data source with same name should not clobber the |
// existing one. |
+ if (ContainsKey(data_sources_, source->source_name())) { |
+ // Some |DataSource| derived classes contain |CancellationFlag| members, |
+ // which DCHECK if they are deleted in a different thread than they are |
+ // created in. This is the IO thread, so we can't delete it here (for |
+ // example, by reassigning a |data_sources_| entry). |
+ // Create another reference and post a call to the UI thread to delete it. |
+ // Any classes that weren't created on the UI thread are thread safe, |
+ // and won't care if they're deleted on another thread. |
+ BrowserThread::PostTask( |
+ BrowserThread::UI, FROM_HERE, |
+ NewRunnableMethod( |
+ ChromeURLDataManager::GetInstance(), |
+ &ChromeURLDataManager::ReleaseDataSource, |
+ source)); |
+ } |
data_sources_[source->source_name()] = source; |
} |
+void ChromeURLDataManager::ReleaseDataSource(scoped_refptr<DataSource> source) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ source.release(); |
+} |
+ |
void ChromeURLDataManager::AddFileSource(const std::string& source_name, |
const FilePath& file_path) { |
DCHECK(file_sources_.count(source_name) == 0); |