Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(399)

Unified Diff: chrome/browser/speech/tab_watcher.h

Issue 10663018: Changing tab closure handling logic in speech recognition code and cleaning bubble controller. (Spe… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Satish review + rebase Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..adf3ef008af86faded5cf59868d16aa2e3b0e99f
--- /dev/null
+++ b/chrome/browser/speech/tab_watcher.h
@@ -0,0 +1,67 @@
+// 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 notified when a WebContent (a tab or an extension's
+// background page) is closed or crashes. Both the callback site 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);
+
+ // 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.
+ // corresponding to the tuple {|render_process_id|,|render_view_id|}.
+ void Watch(int render_process_id, int render_view_id);
+
+ 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_web_contents_;
+
+ // 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_

Powered by Google App Engine
This is Rietveld 408576698