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

Side by Side 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: Relaxed thread checks for tests. Created 8 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 // Starts monitoring the WebContents corresponding to the given
38 // |render_process_id|, |render_view_id| pair, invoking |tab_closed_callback_|
39 // if closed/unloaded.
40 void Watch(int render_process_id, int render_view_id);
41
42 private:
43 friend class base::RefCountedThreadSafe<TabWatcher>;
44
45 virtual ~TabWatcher();
46
47 // content::NotificationObserver implementation.
48 virtual void Observe(int type,
49 const content::NotificationSource& source,
50 const content::NotificationDetails& details) OVERRIDE;
51
52 // Lazy-initialized and used on the UI thread to handle web contents
53 // notifications (tab closing).
54 scoped_ptr<content::NotificationRegistrar> registrar_;
55
56 // Keeps track of which WebContent(s) have been registered, in order to avoid
57 // double registrations on |registrar_|
58 std::set<content::WebContents*> registered_web_contents_;
59
60 // Callback used to notify, on the thread specified by |callback_thread_| the
61 // closure of a registered tab.
62 TabClosedCallback tab_closed_callback_;
63 content::BrowserThread::ID callback_thread_;
64
65 DISALLOW_COPY_AND_ASSIGN(TabWatcher);
66 };
67
68 #endif // CHROME_BROWSER_SPEECH_TAB_WATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698