Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_SPEECH_TAB_WATCHER_H_ | |
| 6 #define CHROME_BROWSER_SPEECH_TAB_WATCHER_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <set> | |
| 10 | |
| 11 #include "base/callback.h" | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "content/public/browser/browser_thread.h" | |
| 15 #include "content/public/browser/notification_observer.h" | |
| 16 | |
| 17 namespace content { | |
| 18 class NotificationRegistrar; | |
| 19 class WebContents; | |
| 20 } | |
| 21 | |
| 22 // Simple utility to get notified when a WebContent (a tab or an extension's | |
| 23 // background page) is closed or crashes. Both the callback site and the | |
| 24 // callback thread are passed by the caller in the constructor. | |
| 25 // There is no restriction on the constructor, however this class must be | |
| 26 // destroyed on the UI thread, due to the NotificationRegistrar dependency. | |
| 27 class TabWatcher | |
| 28 : public base::RefCountedThreadSafe<TabWatcher>, | |
| 29 public content::NotificationObserver { | |
| 30 public: | |
| 31 typedef base::Callback<void(int render_process_id, int render_view_id)> | |
| 32 TabClosedCallback; | |
| 33 | |
| 34 TabWatcher(TabClosedCallback tab_closed_callback, | |
| 35 content::BrowserThread::ID callback_thread); | |
| 36 | |
| 37 // Register, for later receiving a closure notification, the WebContent | |
|
Satish
2012/07/03 15:11:57
this comment is talking about how the method is im
Primiano Tucci (use gerrit)
2012/07/03 16:54:35
Done.
| |
| 38 // corresponding to the tuple {|render_process_id|,|render_view_id|}. | |
| 39 void Watch(int render_process_id, int render_view_id); | |
| 40 | |
| 41 private: | |
| 42 friend class base::RefCountedThreadSafe<TabWatcher>; | |
| 43 | |
| 44 virtual ~TabWatcher(); | |
| 45 | |
| 46 // content::NotificationObserver implementation. | |
| 47 virtual void Observe(int type, | |
| 48 const content::NotificationSource& source, | |
| 49 const content::NotificationDetails& details) OVERRIDE; | |
| 50 | |
| 51 // Lazy-initialized and used on the UI thread to handle web contents | |
| 52 // notifications (tab closing). | |
| 53 scoped_ptr<content::NotificationRegistrar> registrar_; | |
| 54 | |
| 55 // Keeps track of which WebContent(s) have been registered, in order to avoid | |
| 56 // double registrations on |registrar_| | |
| 57 std::set<content::WebContents*> registered_web_contents_; | |
| 58 | |
| 59 // Callback used to notify, on the thread specified by |callback_thread_| the | |
| 60 // closure of a registered tab. | |
| 61 TabClosedCallback tab_closed_callback_; | |
| 62 content::BrowserThread::ID callback_thread_; | |
| 63 | |
| 64 DISALLOW_COPY_AND_ASSIGN(TabWatcher); | |
| 65 }; | |
| 66 | |
| 67 #endif // CHROME_BROWSER_SPEECH_TAB_WATCHER_H_ | |
| OLD | NEW |