Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h" | 5 #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 // TODO(primiano) turn this line into a DCHECK once speech input extension | 161 // TODO(primiano) turn this line into a DCHECK once speech input extension |
| 162 // API is deprecated. | 162 // API is deprecated. |
| 163 if (!web_contents) | 163 if (!web_contents) |
| 164 return; | 164 return; |
| 165 | 165 |
| 166 // Avoid multiple registrations on |registrar_| for the same |web_contents|. | 166 // Avoid multiple registrations on |registrar_| for the same |web_contents|. |
| 167 if (registered_web_contents_.find(web_contents) != | 167 if (registered_web_contents_.find(web_contents) != |
| 168 registered_web_contents_.end()) { | 168 registered_web_contents_.end()) { |
| 169 return; | 169 return; |
| 170 } | 170 } |
| 171 registered_web_contents_.insert(web_contents); | 171 registered_web_contents_[web_contents] = |
| 172 std::make_pair(render_process_id, render_view_id); | |
| 172 | 173 |
| 173 // Lazy initialize the registrar. | 174 // Lazy initialize the registrar. |
| 174 if (!registrar_.get()) | 175 if (!registrar_.get()) |
| 175 registrar_.reset(new content::NotificationRegistrar()); | 176 registrar_.reset(new content::NotificationRegistrar()); |
| 176 | 177 |
| 177 registrar_->Add(this, | 178 registrar_->Add(this, |
| 179 content::NOTIFICATION_WEB_CONTENTS_SWAPPED, | |
| 180 content::Source<WebContents>(web_contents)); | |
| 181 registrar_->Add(this, | |
| 178 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, | 182 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
| 179 content::Source<WebContents>(web_contents)); | 183 content::Source<WebContents>(web_contents)); |
| 180 } | 184 } |
| 181 | 185 |
| 182 // content::NotificationObserver implementation. | 186 // content::NotificationObserver implementation. |
| 183 virtual void Observe(int type, | 187 virtual void Observe(int type, |
| 184 const content::NotificationSource& source, | 188 const content::NotificationSource& source, |
| 185 const content::NotificationDetails& details) OVERRIDE { | 189 const content::NotificationDetails& details) OVERRIDE { |
| 186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 187 DCHECK_EQ(content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, type); | 191 DCHECK(type == content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED || |
| 192 type == content::NOTIFICATION_WEB_CONTENTS_SWAPPED); | |
| 188 | 193 |
| 189 WebContents* web_contents = content::Source<WebContents>(source).ptr(); | 194 WebContents* web_contents = content::Source<WebContents>(source).ptr(); |
| 190 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); | 195 WebContentsMap::const_iterator iter = |
| 191 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); | 196 registered_web_contents_.find(web_contents); |
| 197 DCHECK(iter != registered_web_contents_.end()); | |
| 198 int render_process_id = iter->second.first; | |
| 199 int render_view_id = iter->second.second; | |
| 192 | 200 |
| 193 registrar_->Remove(this, | 201 registrar_->Remove(this, |
| 202 content::NOTIFICATION_WEB_CONTENTS_SWAPPED, | |
| 203 content::Source<WebContents>(web_contents)); | |
| 204 registrar_->Remove(this, | |
| 194 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, | 205 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
| 195 content::Source<WebContents>(web_contents)); | 206 content::Source<WebContents>(web_contents)); |
| 196 registered_web_contents_.erase(web_contents); | 207 registered_web_contents_.erase(web_contents); |
| 197 | 208 |
| 198 BrowserThread::PostTask(callback_thread_, FROM_HERE, base::Bind( | 209 BrowserThread::PostTask(callback_thread_, FROM_HERE, base::Bind( |
| 199 tab_closed_callback_, render_process_id, render_view_id)); | 210 tab_closed_callback_, render_process_id, render_view_id)); |
| 200 } | 211 } |
| 201 | 212 |
| 202 private: | 213 private: |
| 203 friend class base::RefCountedThreadSafe<TabWatcher>; | 214 friend class base::RefCountedThreadSafe<TabWatcher>; |
| 204 | 215 |
| 205 virtual ~TabWatcher() { | 216 virtual ~TabWatcher() { |
| 206 // Must be destroyed on the UI thread due to |registrar_| non thread-safety. | 217 // Must be destroyed on the UI thread due to |registrar_| non thread-safety. |
| 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 218 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 208 } | 219 } |
| 209 | 220 |
| 210 // Lazy-initialized and used on the UI thread to handle web contents | 221 // Lazy-initialized and used on the UI thread to handle web contents |
| 211 // notifications (tab closing). | 222 // notifications (tab closing). |
| 212 scoped_ptr<content::NotificationRegistrar> registrar_; | 223 scoped_ptr<content::NotificationRegistrar> registrar_; |
| 213 | 224 |
| 214 // Keeps track of which WebContent(s) have been registered, in order to avoid | 225 // Keeps track of which WebContent(s) have been registered, in order to avoid |
| 215 // double registrations on |registrar_| | 226 // double registrations on |registrar_|. The ProcessID+ViewID pair is stored |
| 216 std::set<content::WebContents*> registered_web_contents_; | 227 // and used for |tab_closed_callback_| after the process has gone away. |
| 228 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
| |
| 229 WebContentsMap registered_web_contents_; | |
| 217 | 230 |
| 218 // Callback used to notify, on the thread specified by |callback_thread_| the | 231 // Callback used to notify, on the thread specified by |callback_thread_| the |
| 219 // closure of a registered tab. | 232 // closure of a registered tab. |
| 220 TabClosedCallback tab_closed_callback_; | 233 TabClosedCallback tab_closed_callback_; |
| 221 content::BrowserThread::ID callback_thread_; | 234 content::BrowserThread::ID callback_thread_; |
| 222 | 235 |
| 223 DISALLOW_COPY_AND_ASSIGN(TabWatcher); | 236 DISALLOW_COPY_AND_ASSIGN(TabWatcher); |
| 224 }; | 237 }; |
| 225 | 238 |
| 226 ChromeSpeechRecognitionManagerDelegate | 239 ChromeSpeechRecognitionManagerDelegate |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 523 } | 536 } |
| 524 | 537 |
| 525 SpeechRecognitionBubbleController* | 538 SpeechRecognitionBubbleController* |
| 526 ChromeSpeechRecognitionManagerDelegate::GetBubbleController() { | 539 ChromeSpeechRecognitionManagerDelegate::GetBubbleController() { |
| 527 if (!bubble_controller_.get()) | 540 if (!bubble_controller_.get()) |
| 528 bubble_controller_ = new SpeechRecognitionBubbleController(this); | 541 bubble_controller_ = new SpeechRecognitionBubbleController(this); |
| 529 return bubble_controller_.get(); | 542 return bubble_controller_.get(); |
| 530 } | 543 } |
| 531 | 544 |
| 532 } // namespace speech | 545 } // namespace speech |
| OLD | NEW |