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

Side by Side Diff: chrome/browser/media/media_stream_capture_indicator.cc

Issue 10829190: Resolve the problems where we can leak the system tray UI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed more relevant problems, ready for review now. Created 8 years, 4 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/media/media_stream_capture_indicator.h" 5 #include "chrome/browser/media/media_stream_capture_indicator.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/i18n/rtl.h" 8 #include "base/i18n/rtl.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/app/chrome_command_ids.h" 10 #include "chrome/app/chrome_command_ids.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 } 126 }
127 127
128 void MediaStreamCaptureIndicator::DoDevicesClosedOnUIThread( 128 void MediaStreamCaptureIndicator::DoDevicesClosedOnUIThread(
129 int render_process_id, 129 int render_process_id,
130 int render_view_id, 130 int render_view_id,
131 const content::MediaStreamDevices& devices) { 131 const content::MediaStreamDevices& devices) {
132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
133 if (!status_icon_) 133 if (!status_icon_)
134 return; 134 return;
135 135
136 DCHECK(!tabs_.empty());
137 RemoveCaptureDeviceTab(render_process_id, render_view_id, devices); 136 RemoveCaptureDeviceTab(render_process_id, render_view_id, devices);
138 } 137 }
139 138
140 void MediaStreamCaptureIndicator::CreateStatusTray() { 139 void MediaStreamCaptureIndicator::CreateStatusTray() {
141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
142 if (status_icon_) 141 if (status_icon_)
143 return; 142 return;
144 143
145 // If there is no browser process, we should not create the status tray. 144 // If there is no browser process, we should not create the status tray.
146 if (!g_browser_process) 145 if (!g_browser_process)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 message_id = IDS_MEDIA_STREAM_STATUS_TRAY_BALLOON_BODY_VIDEO_ONLY; 189 message_id = IDS_MEDIA_STREAM_STATUS_TRAY_BALLOON_BODY_VIDEO_ONLY;
191 190
192 string16 body = l10n_util::GetStringFUTF16( 191 string16 body = l10n_util::GetStringFUTF16(
193 message_id, GetSecurityOrigin(render_process_id, render_view_id)); 192 message_id, GetSecurityOrigin(render_process_id, render_view_id));
194 193
195 status_icon_->DisplayBalloon(*balloon_image_, title, body); 194 status_icon_->DisplayBalloon(*balloon_image_, title, body);
196 } 195 }
197 196
198 void MediaStreamCaptureIndicator::Hide() { 197 void MediaStreamCaptureIndicator::Hide() {
199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
199 DCHECK(tabs_.empty());
200 if (!status_icon_) 200 if (!status_icon_)
201 return; 201 return;
202 202
203 // If there is no browser process, we should not do anything. 203 // If there is no browser process, we should not do anything.
204 if (!g_browser_process) 204 if (!g_browser_process)
205 return; 205 return;
206 206
207 StatusTray* status_tray = g_browser_process->status_tray(); 207 StatusTray* status_tray = g_browser_process->status_tray();
208 if (status_tray != NULL) { 208 if (status_tray != NULL) {
209 status_tray->RemoveStatusIcon(status_icon_); 209 status_tray->RemoveStatusIcon(status_icon_);
210 status_icon_ = NULL; 210 status_icon_ = NULL;
211 } 211 }
212 } 212 }
213 213
214 void MediaStreamCaptureIndicator::UpdateStatusTrayIconContextMenu() { 214 void MediaStreamCaptureIndicator::UpdateStatusTrayIconContextMenu() {
215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
216 scoped_ptr<ui::SimpleMenuModel> menu(new ui::SimpleMenuModel(this)); 216 scoped_ptr<ui::SimpleMenuModel> menu(new ui::SimpleMenuModel(this));
217 217
218 bool audio = false; 218 bool audio = false;
219 bool video = false; 219 bool video = false;
220 int command_id = IDC_MEDIA_CONTEXT_MEDIA_STREAM_CAPTURE_LIST_FIRST; 220 int command_id = IDC_MEDIA_CONTEXT_MEDIA_STREAM_CAPTURE_LIST_FIRST;
221 for (CaptureDeviceTabs::iterator iter = tabs_.begin(); 221 for (CaptureDeviceTabs::iterator iter = tabs_.begin();
222 iter != tabs_.end(); ++iter) { 222 iter != tabs_.end(); ++iter) {
223 string16 tab_title = GetTitle(iter->render_process_id, 223 string16 tab_title = GetTitle(iter->render_process_id,
224 iter->render_view_id); 224 iter->render_view_id);
225 // The tab has gone away. 225 // The tab has gone away.
226 if (tab_title.empty()) 226 if (tab_title.empty()) {
227 // Delete the entry since the tab has gone away.
228 tabs_.erase(iter);
227 continue; 229 continue;
230 }
228 231
229 // Check if any audio and video devices have been used. 232 // Check if any audio and video devices have been used.
230 audio = audio || iter->audio_ref_count > 0; 233 audio = audio || iter->audio_ref_count > 0;
231 video = video || iter->video_ref_count > 0; 234 video = video || iter->video_ref_count > 0;
232 235
233 string16 message = l10n_util::GetStringFUTF16( 236 string16 message = l10n_util::GetStringFUTF16(
234 IDS_MEDIA_STREAM_STATUS_TRAY_MENU_ITEM, tab_title); 237 IDS_MEDIA_STREAM_STATUS_TRAY_MENU_ITEM, tab_title);
235 menu->AddItem(command_id, message); 238 menu->AddItem(command_id, message);
236 239
237 // If reaching the maximum number, no more item will be added to the menu. 240 // If reaching the maximum number, no more item will be added to the menu.
238 if (command_id == IDC_MEDIA_CONTEXT_MEDIA_STREAM_CAPTURE_LIST_LAST) 241 if (command_id == IDC_MEDIA_CONTEXT_MEDIA_STREAM_CAPTURE_LIST_LAST)
239 break; 242 break;
240 243
241 ++command_id; 244 ++command_id;
242 } 245 }
243 246
244 // All the tabs have gone away. 247 if (!audio && !video) {
245 if (!audio && !video) 248 Hide();
246 return; 249 return;
250 }
247 251
248 // The icon will take the ownership of the passed context menu. 252 // The icon will take the ownership of the passed context menu.
249 status_icon_->SetContextMenu(menu.release()); 253 status_icon_->SetContextMenu(menu.release());
250 UpdateStatusTrayIconDisplay(audio, video); 254 UpdateStatusTrayIconDisplay(audio, video);
251 } 255 }
252 256
253 void MediaStreamCaptureIndicator::UpdateStatusTrayIconDisplay( 257 void MediaStreamCaptureIndicator::UpdateStatusTrayIconDisplay(
254 bool audio, bool video) { 258 bool audio, bool video) {
255 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 259 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
256 DCHECK(audio || video); 260 DCHECK(audio || video);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 --iter->video_ref_count; 326 --iter->video_ref_count;
323 327
324 DCHECK_GE(iter->audio_ref_count, 0); 328 DCHECK_GE(iter->audio_ref_count, 0);
325 DCHECK_GE(iter->video_ref_count, 0); 329 DCHECK_GE(iter->video_ref_count, 0);
326 } 330 }
327 331
328 // Remove the tab if all the devices have been closed. 332 // Remove the tab if all the devices have been closed.
329 if (iter->audio_ref_count == 0 && iter->video_ref_count == 0) 333 if (iter->audio_ref_count == 0 && iter->video_ref_count == 0)
330 tabs_.erase(iter); 334 tabs_.erase(iter);
331 335
332 if (tabs_.empty()) 336 UpdateStatusTrayIconContextMenu();
333 Hide();
334 else
335 UpdateStatusTrayIconContextMenu();
336 } 337 }
337 338
338 string16 MediaStreamCaptureIndicator::GetTitle(int render_process_id, 339 string16 MediaStreamCaptureIndicator::GetTitle(int render_process_id,
339 int render_view_id) const { 340 int render_view_id) const {
340 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 341 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
341 WebContents* tab_content = tab_util::GetWebContentsByID( 342 WebContents* tab_content = tab_util::GetWebContentsByID(
342 render_process_id, render_view_id); 343 render_process_id, render_view_id);
343 if (!tab_content) 344 if (!tab_content)
344 return string16(); 345 return string16();
345 346
(...skipping 26 matching lines...) Expand all
372 373
373 // Remove the last character if it is a '/'. 374 // Remove the last character if it is a '/'.
374 if (!security_origin.empty()) { 375 if (!security_origin.empty()) {
375 std::string::iterator it = security_origin.end() - 1; 376 std::string::iterator it = security_origin.end() - 1;
376 if (*it == '/') 377 if (*it == '/')
377 security_origin.erase(it); 378 security_origin.erase(it);
378 } 379 }
379 380
380 return UTF8ToUTF16(security_origin); 381 return UTF8ToUTF16(security_origin);
381 } 382 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698