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

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 the comments and added unit tests to media_stream_device_settings_unittest 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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 } 207 }
208 208
209 void MediaStreamCaptureIndicator::DoDevicesClosedOnUIThread( 209 void MediaStreamCaptureIndicator::DoDevicesClosedOnUIThread(
210 int render_process_id, 210 int render_process_id,
211 int render_view_id, 211 int render_view_id,
212 const content::MediaStreamDevices& devices) { 212 const content::MediaStreamDevices& devices) {
213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
214 if (!status_icon_) 214 if (!status_icon_)
215 return; 215 return;
216 216
217 DCHECK(!tabs_.empty());
218 RemoveCaptureDeviceTab(render_process_id, render_view_id, devices); 217 RemoveCaptureDeviceTab(render_process_id, render_view_id, devices);
219 } 218 }
220 219
221 void MediaStreamCaptureIndicator::CreateStatusTray() { 220 void MediaStreamCaptureIndicator::CreateStatusTray() {
222 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
223 if (status_icon_) 222 if (status_icon_)
224 return; 223 return;
225 224
226 // If there is no browser process, we should not create the status tray. 225 // If there is no browser process, we should not create the status tray.
227 if (!g_browser_process) 226 if (!g_browser_process)
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 status_icon_->DisplayBalloon( 299 status_icon_->DisplayBalloon(
301 !image.IsEmpty() ? *image.ToImageSkia() : 300 !image.IsEmpty() ? *image.ToImageSkia() :
302 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 301 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
303 IDR_APP_DEFAULT_ICON), 302 IDR_APP_DEFAULT_ICON),
304 string16(), 303 string16(),
305 message); 304 message);
306 } 305 }
307 306
308 void MediaStreamCaptureIndicator::Hide() { 307 void MediaStreamCaptureIndicator::Hide() {
309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 308 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
309 DCHECK(tabs_.empty());
310 if (!status_icon_) 310 if (!status_icon_)
311 return; 311 return;
312 312
313 // If there is no browser process, we should not do anything. 313 // If there is no browser process, we should not do anything.
314 if (!g_browser_process) 314 if (!g_browser_process)
315 return; 315 return;
316 316
317 StatusTray* status_tray = g_browser_process->status_tray(); 317 StatusTray* status_tray = g_browser_process->status_tray();
318 if (status_tray != NULL) { 318 if (status_tray != NULL) {
319 status_tray->RemoveStatusIcon(status_icon_); 319 status_tray->RemoveStatusIcon(status_icon_);
320 status_icon_ = NULL; 320 status_icon_ = NULL;
321 } 321 }
322 } 322 }
323 323
324 void MediaStreamCaptureIndicator::UpdateStatusTrayIconContextMenu() { 324 void MediaStreamCaptureIndicator::UpdateStatusTrayIconContextMenu() {
325 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 325 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
326 scoped_ptr<ui::SimpleMenuModel> menu(new ui::SimpleMenuModel(this)); 326 scoped_ptr<ui::SimpleMenuModel> menu(new ui::SimpleMenuModel(this));
327 327
328 bool audio = false; 328 bool audio = false;
329 bool video = false; 329 bool video = false;
330 int command_id = IDC_MEDIA_CONTEXT_MEDIA_STREAM_CAPTURE_LIST_FIRST; 330 int command_id = IDC_MEDIA_CONTEXT_MEDIA_STREAM_CAPTURE_LIST_FIRST;
331 for (CaptureDeviceTabs::iterator iter = tabs_.begin(); 331 for (CaptureDeviceTabs::iterator iter = tabs_.begin();
332 iter != tabs_.end(); ++iter) { 332 iter != tabs_.end(); ++iter) {
333 string16 tab_title = GetTitle(iter->render_process_id, 333 string16 tab_title = GetTitle(iter->render_process_id,
334 iter->render_view_id); 334 iter->render_view_id);
335 // The tab has gone away. 335 // The tab has gone away.
336 if (tab_title.empty()) 336 if (tab_title.empty()) {
337 // Delete the entry since the tab has gone away.
338 tabs_.erase(iter);
337 continue; 339 continue;
340 }
338 341
339 // Check if any audio and video devices have been used. 342 // Check if any audio and video devices have been used.
340 audio = audio || iter->audio_ref_count > 0; 343 audio = audio || iter->audio_ref_count > 0;
341 video = video || iter->video_ref_count > 0; 344 video = video || iter->video_ref_count > 0;
342 345
343 string16 message = l10n_util::GetStringFUTF16( 346 string16 message = l10n_util::GetStringFUTF16(
344 IDS_MEDIA_STREAM_STATUS_TRAY_MENU_ITEM, tab_title); 347 IDS_MEDIA_STREAM_STATUS_TRAY_MENU_ITEM, tab_title);
345 menu->AddItem(command_id, message); 348 menu->AddItem(command_id, message);
346 349
347 // If reaching the maximum number, no more item will be added to the menu. 350 // If reaching the maximum number, no more item will be added to the menu.
348 if (command_id == IDC_MEDIA_CONTEXT_MEDIA_STREAM_CAPTURE_LIST_LAST) 351 if (command_id == IDC_MEDIA_CONTEXT_MEDIA_STREAM_CAPTURE_LIST_LAST)
349 break; 352 break;
350 353
351 ++command_id; 354 ++command_id;
352 } 355 }
353 356
354 // All the tabs have gone away. 357 if (!audio && !video) {
355 if (!audio && !video) 358 Hide();
356 return; 359 return;
360 }
357 361
358 // The icon will take the ownership of the passed context menu. 362 // The icon will take the ownership of the passed context menu.
359 status_icon_->SetContextMenu(menu.release()); 363 status_icon_->SetContextMenu(menu.release());
360 UpdateStatusTrayIconDisplay(audio, video); 364 UpdateStatusTrayIconDisplay(audio, video);
361 } 365 }
362 366
363 void MediaStreamCaptureIndicator::UpdateStatusTrayIconDisplay( 367 void MediaStreamCaptureIndicator::UpdateStatusTrayIconDisplay(
364 bool audio, bool video) { 368 bool audio, bool video) {
365 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 369 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
366 DCHECK(audio || video); 370 DCHECK(audio || video);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 --iter->video_ref_count; 436 --iter->video_ref_count;
433 437
434 DCHECK_GE(iter->audio_ref_count, 0); 438 DCHECK_GE(iter->audio_ref_count, 0);
435 DCHECK_GE(iter->video_ref_count, 0); 439 DCHECK_GE(iter->video_ref_count, 0);
436 } 440 }
437 441
438 // Remove the tab if all the devices have been closed. 442 // Remove the tab if all the devices have been closed.
439 if (iter->audio_ref_count == 0 && iter->video_ref_count == 0) 443 if (iter->audio_ref_count == 0 && iter->video_ref_count == 0)
440 tabs_.erase(iter); 444 tabs_.erase(iter);
441 445
442 if (tabs_.empty()) 446 UpdateStatusTrayIconContextMenu();
443 Hide();
444 else
445 UpdateStatusTrayIconContextMenu();
446 } 447 }
447 448
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698