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

Side by Side Diff: chrome/browser/speech/tab_watcher.cc

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, 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 #include "chrome/browser/speech/tab_watcher.h"
6
7 #include "base/bind.h"
8 #include "chrome/browser/tab_contents/tab_util.h"
9 #include "content/public/browser/notification_registrar.h"
10 #include "content/public/browser/notification_source.h"
11 #include "content/public/browser/notification_types.h"
12 #include "content/public/browser/render_process_host.h"
13 #include "content/public/browser/render_view_host.h"
14 #include "content/public/browser/web_contents.h"
15
16 using content::BrowserThread;
17 using content::WebContents;
18
19 namespace {
20 const int kNotificationType = content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED;
21 }
22
23 TabWatcher::TabWatcher(
24 TabClosedCallback tab_closed_callback, BrowserThread::ID callback_thread)
25 : tab_closed_callback_(tab_closed_callback),
Satish 2012/07/02 21:44:41 indent this and next line by 2 spaces
Primiano Tucci (use gerrit) 2012/07/03 10:05:02 Done.
26 callback_thread_(callback_thread) {
27 }
28
29 TabWatcher::~TabWatcher() {
30 // Must be destroyed on the UI thread due to |registrar_| non thread-safety.
31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
32 }
33
34 void TabWatcher::Watch(
35 int render_process_id, int render_view_id) {
Satish 2012/07/02 21:44:41 seems like this can fit in previous line?
Primiano Tucci (use gerrit) 2012/07/03 10:05:02 Oh right!
36 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
37 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(
38 &TabWatcher::Watch, this, render_process_id, render_view_id));
39 return;
40 }
41
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
Satish 2012/07/02 21:44:41 this seems unnecessary given the if statement abov
Primiano Tucci (use gerrit) 2012/07/03 10:05:02 Done.
43 WebContents* web_contents = tab_util::GetWebContentsByID(render_process_id,
44 render_view_id);
45
46 // Sessions initiated by extensions might not have a corresponding WebContent.
Satish 2012/07/02 21:44:41 for extensions should you listen for background pa
Primiano Tucci (use gerrit) 2012/07/03 10:05:02 Well, there is a bit of confusion here using the t
47 if (!web_contents)
48 return;
49
50 // Avoid multiple registrations on |registrar_| for the same |web_contents|.
51 if (registered_contents_.find(web_contents) != registered_contents_.end())
52 return;
53 registered_contents_.insert(web_contents);
54
55 // Lazy initialize the registrar.
56 if (!registrar_.get())
57 registrar_.reset(new content::NotificationRegistrar());
58
59 registrar_->Add(this,
60 kNotificationType,
61 content::Source<WebContents>(web_contents));
62 }
63
64 void TabWatcher::Observe(
65 int type,
66 const content::NotificationSource& source,
67 const content::NotificationDetails& details) {
68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
69 DCHECK_EQ(kNotificationType, type);
70
71 WebContents* web_contents = content::Source<WebContents>(source).ptr();
Satish 2012/07/02 21:44:41 any chance this could return null, i.e. this notif
Primiano Tucci (use gerrit) 2012/07/03 10:05:02 I added a paranoid DCHECK, however IMHO, even in c
72 const int render_process_id = web_contents->GetRenderProcessHost()->GetID();
73 const int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID();
74
75 registrar_->Remove(this,
76 kNotificationType,
77 content::Source<WebContents>(web_contents));
78 registered_contents_.erase(web_contents);
79
80 BrowserThread::PostTask(callback_thread_, FROM_HERE, base::Bind(
81 tab_closed_callback_, render_process_id, render_view_id));
82 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698