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 a callback when a tab closes. Both the callback site | |
|
Satish
2012/07/02 21:44:41
get a callback -> get notified
Primiano Tucci (use gerrit)
2012/07/03 10:05:02
Done.
| |
| 23 // and the callback thread are passed by the caller in the constructor. | |
| 24 // There is no restriction on the constructor, however this class must be | |
| 25 // destroyed on the UI thread, due to the NotificationRegistrar dependency. | |
| 26 class TabWatcher | |
| 27 : public base::RefCountedThreadSafe<TabWatcher>, | |
| 28 public content::NotificationObserver { | |
| 29 public: | |
| 30 typedef base::Callback<void(int render_process_id, int render_view_id)> | |
| 31 TabClosedCallback; | |
| 32 | |
| 33 TabWatcher(TabClosedCallback tab_closed_callback, | |
| 34 content::BrowserThread::ID callback_thread); | |
| 35 | |
| 36 void Watch(int render_process_id, int render_view_id); | |
|
Satish
2012/07/02 21:44:41
add comment
Primiano Tucci (use gerrit)
2012/07/03 10:05:02
Done.
| |
| 37 | |
| 38 private: | |
| 39 friend class base::RefCountedThreadSafe<TabWatcher>; | |
| 40 | |
| 41 virtual ~TabWatcher(); | |
| 42 | |
| 43 // content::NotificationObserver implementation. | |
| 44 virtual void Observe(int type, | |
| 45 const content::NotificationSource& source, | |
| 46 const content::NotificationDetails& details) OVERRIDE; | |
| 47 | |
| 48 // Lazy-initialized and used on the UI thread to handle web contents | |
| 49 // notifications (tab closing). | |
| 50 scoped_ptr<content::NotificationRegistrar> registrar_; | |
| 51 | |
| 52 // Keeps track of which WebContent(s) have been registered, in order to avoid | |
| 53 // double registrations on |registrar_| | |
| 54 std::set<content::WebContents*> registered_contents_; | |
|
Satish
2012/07/02 21:44:41
registered_web_contents_
Primiano Tucci (use gerrit)
2012/07/03 10:05:02
Done.
| |
| 55 | |
| 56 // Callback used to notify, on the thread specified by |callback_thread_| the | |
| 57 // closure of a registered tab. | |
| 58 TabClosedCallback tab_closed_callback_; | |
| 59 content::BrowserThread::ID callback_thread_; | |
| 60 | |
| 61 DISALLOW_COPY_AND_ASSIGN(TabWatcher); | |
| 62 }; | |
| 63 | |
| 64 #endif // CHROME_BROWSER_SPEECH_TAB_WATCHER_H_ | |
| OLD | NEW |