Chromium Code Reviews| Index: chrome/browser/speech/tab_watcher.h |
| diff --git a/chrome/browser/speech/tab_watcher.h b/chrome/browser/speech/tab_watcher.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1ca2e42ddb0908910bfe8926cfba81224bb1bd95 |
| --- /dev/null |
| +++ b/chrome/browser/speech/tab_watcher.h |
| @@ -0,0 +1,64 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_SPEECH_TAB_WATCHER_H_ |
| +#define CHROME_BROWSER_SPEECH_TAB_WATCHER_H_ |
| +#pragma once |
| + |
| +#include <set> |
| + |
| +#include "base/callback.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/notification_observer.h" |
| + |
| +namespace content { |
| +class NotificationRegistrar; |
| +class WebContents; |
| +} |
| + |
| +// 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.
|
| +// and the callback thread are passed by the caller in the constructor. |
| +// There is no restriction on the constructor, however this class must be |
| +// destroyed on the UI thread, due to the NotificationRegistrar dependency. |
| +class TabWatcher |
| + : public base::RefCountedThreadSafe<TabWatcher>, |
| + public content::NotificationObserver { |
| + public: |
| + typedef base::Callback<void(int render_process_id, int render_view_id)> |
| + TabClosedCallback; |
| + |
| + TabWatcher(TabClosedCallback tab_closed_callback, |
| + content::BrowserThread::ID callback_thread); |
| + |
| + 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.
|
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<TabWatcher>; |
| + |
| + virtual ~TabWatcher(); |
| + |
| + // content::NotificationObserver implementation. |
| + virtual void Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) OVERRIDE; |
| + |
| + // Lazy-initialized and used on the UI thread to handle web contents |
| + // notifications (tab closing). |
| + 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_contents_; |
|
Satish
2012/07/02 21:44:41
registered_web_contents_
Primiano Tucci (use gerrit)
2012/07/03 10:05:02
Done.
|
| + |
| + // Callback used to notify, on the thread specified by |callback_thread_| the |
| + // closure of a registered tab. |
| + TabClosedCallback tab_closed_callback_; |
| + content::BrowserThread::ID callback_thread_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TabWatcher); |
| +}; |
| + |
| +#endif // CHROME_BROWSER_SPEECH_TAB_WATCHER_H_ |