Index: chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc |
diff --git a/chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc b/chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc |
index b09d38f82abf83a47f912a954918b8bd720ed23a..1c81ba7941e2934279c2b5ee62c346301150cff7 100644 |
--- a/chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc |
+++ b/chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc |
@@ -168,13 +168,17 @@ class ChromeSpeechRecognitionManagerDelegate::TabWatcher |
registered_web_contents_.end()) { |
return; |
} |
- registered_web_contents_.insert(web_contents); |
+ registered_web_contents_[web_contents] = |
+ std::make_pair(render_process_id, render_view_id); |
// Lazy initialize the registrar. |
if (!registrar_.get()) |
registrar_.reset(new content::NotificationRegistrar()); |
registrar_->Add(this, |
+ content::NOTIFICATION_WEB_CONTENTS_SWAPPED, |
+ content::Source<WebContents>(web_contents)); |
+ registrar_->Add(this, |
content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
content::Source<WebContents>(web_contents)); |
} |
@@ -184,13 +188,20 @@ class ChromeSpeechRecognitionManagerDelegate::TabWatcher |
const content::NotificationSource& source, |
const content::NotificationDetails& details) OVERRIDE { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- DCHECK_EQ(content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, type); |
+ DCHECK(type == content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED || |
+ type == content::NOTIFICATION_WEB_CONTENTS_SWAPPED); |
WebContents* web_contents = content::Source<WebContents>(source).ptr(); |
- int render_process_id = web_contents->GetRenderProcessHost()->GetID(); |
- int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); |
+ WebContentsMap::const_iterator iter = |
+ registered_web_contents_.find(web_contents); |
+ DCHECK(iter != registered_web_contents_.end()); |
+ int render_process_id = iter->second.first; |
+ int render_view_id = iter->second.second; |
registrar_->Remove(this, |
+ content::NOTIFICATION_WEB_CONTENTS_SWAPPED, |
+ content::Source<WebContents>(web_contents)); |
+ registrar_->Remove(this, |
content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
content::Source<WebContents>(web_contents)); |
registered_web_contents_.erase(web_contents); |
@@ -212,8 +223,10 @@ class ChromeSpeechRecognitionManagerDelegate::TabWatcher |
scoped_ptr<content::NotificationRegistrar> registrar_; |
// Keeps track of which WebContent(s) have been registered, in order to avoid |
- // double registrations on |registrar_| |
- std::set<content::WebContents*> registered_web_contents_; |
+ // double registrations on |registrar_|. The ProcessID+ViewID pair is stored |
+ // and used for |tab_closed_callback_| after the process has gone away. |
+ typedef std::map< content::WebContents*, std::pair<int, int> > WebContentsMap; |
tommi (sloooow) - chröme
2013/04/03 09:38:30
no space after <
tommi (sloooow) - chröme
2013/04/03 09:38:30
instead of std::pair, let's define a struct with p
no longer working on chromium
2013/04/03 11:19:55
Done with changing the code to use vector with str
|
+ WebContentsMap registered_web_contents_; |
// Callback used to notify, on the thread specified by |callback_thread_| the |
// closure of a registered tab. |