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

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: Slight refactor to fix a bug on mac + 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..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_

Powered by Google App Engine
This is Rietveld 408576698