summaryrefslogtreecommitdiffstats
path: root/chrome/browser/media/media_stream_capture_indicator.cc
blob: 48c76318c1719f2ab4c7257f41dd7a2c2c469c74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
// 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.

#include "chrome/browser/media/media_stream_capture_indicator.h"

#include "base/bind.h"
#include "base/i18n/rtl.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/prefs/pref_service.h"
#include "base/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/image_loader.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/status_icons/status_icon.h"
#include "chrome/browser/status_icons/status_tray.h"
#include "chrome/browser/tab_contents/tab_util.h"
#include "chrome/browser/ui/screen_capture_notification_ui.h"
#include "chrome/common/extensions/api/icons/icons_handler.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/invalidate_type.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "net/base/net_util.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image_skia.h"

using content::BrowserThread;
using content::WebContents;

namespace {

const extensions::Extension* GetExtension(WebContents* web_contents) {
  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));

  if (!web_contents)
    return NULL;

  Profile* profile =
      Profile::FromBrowserContext(web_contents->GetBrowserContext());
  if (!profile)
    return NULL;

  ExtensionService* extension_service = profile->GetExtensionService();
  if (!extension_service)
    return NULL;

  return extension_service->extensions()->GetExtensionOrAppByURL(
      ExtensionURLInfo(web_contents->GetURL()));
}

// Gets the security originator of the tab. It returns a string with no '/'
// at the end to display in the UI.
string16 GetSecurityOrigin(WebContents* web_contents) {
  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));

  if (!web_contents)
    return string16();

  std::string security_origin = web_contents->GetURL().GetOrigin().spec();

  // Remove the last character if it is a '/'.
  if (!security_origin.empty()) {
    std::string::iterator it = security_origin.end() - 1;
    if (*it == '/')
      security_origin.erase(it);
  }

  return UTF8ToUTF16(security_origin);
}

string16 GetTitle(WebContents* web_contents) {
  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));

  if (!web_contents)
    return string16();

  const extensions::Extension* const extension = GetExtension(web_contents);
  if (extension)
    return UTF8ToUTF16(extension->name());

  string16 tab_title = web_contents->GetTitle();

  if (tab_title.empty()) {
    // If the page's title is empty use its security originator.
    tab_title = GetSecurityOrigin(web_contents);
  } else {
    // If the page's title matches its URL, use its security originator.
    Profile* profile =
        Profile::FromBrowserContext(web_contents->GetBrowserContext());
    std::string languages =
        profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
    if (tab_title == net::FormatUrl(web_contents->GetURL(), languages))
      tab_title = GetSecurityOrigin(web_contents);
  }

  return tab_title;
}

}  // namespace

// Stores usage counts for all the capture devices associated with a single
// WebContents instance, and observes for the destruction of the WebContents
// instance.
class MediaStreamCaptureIndicator::WebContentsDeviceUsage
    : protected content::WebContentsObserver {
 public:
  explicit WebContentsDeviceUsage(WebContents* web_contents);

  bool IsWebContentsDestroyed() const { return web_contents() == NULL; }

  bool IsCapturingAudio() const { return audio_ref_count_ > 0; }
  bool IsCapturingVideo() const { return video_ref_count_ > 0; }
  bool IsMirroring() const { return mirroring_ref_count_ > 0; }
  bool IsCapturingScreen() const { return screen_capture_ref_count_ > 0; }
  const base::Closure& StopScreenCaptureCallback() const {
    return stop_screen_capture_callback_;
  }

  // Increment ref-counts up based on the type of each device provided. The
  // return value is the message ID for the balloon body to show, or zero if the
  // balloon should not be shown.
  int AddDevices(const content::MediaStreamDevices& devices,
                 const base::Closure& close_callback);

  // Decrement ref-counts up based on the type of each device provided.
  void RemoveDevices(const content::MediaStreamDevices& devices);

 private:
  int audio_ref_count_;
  int video_ref_count_;
  int mirroring_ref_count_;
  int screen_capture_ref_count_;
  base::Closure stop_screen_capture_callback_;

  DISALLOW_COPY_AND_ASSIGN(WebContentsDeviceUsage);
};

MediaStreamCaptureIndicator::WebContentsDeviceUsage::WebContentsDeviceUsage(
    WebContents* web_contents)
    : content::WebContentsObserver(web_contents),
      audio_ref_count_(0),
      video_ref_count_(0),
      mirroring_ref_count_(0),
      screen_capture_ref_count_(0) {
}

int MediaStreamCaptureIndicator::WebContentsDeviceUsage::AddDevices(
    const content::MediaStreamDevices& devices,
    const base::Closure& close_callback) {
  bool incremented_audio_count = false;
  bool incremented_video_count = false;
  for (content::MediaStreamDevices::const_iterator it = devices.begin();
       it != devices.end(); ++it) {
    if (it->type == content::MEDIA_TAB_AUDIO_CAPTURE ||
        it->type == content::MEDIA_TAB_VIDEO_CAPTURE) {
      ++mirroring_ref_count_;
    } else if (it->type == content::MEDIA_SCREEN_VIDEO_CAPTURE) {
      ++screen_capture_ref_count_;
      stop_screen_capture_callback_ = close_callback;
    } else if (content::IsAudioMediaType(it->type)) {
      ++audio_ref_count_;
    } else if (content::IsVideoMediaType(it->type)) {
      ++video_ref_count_;
    } else {
      NOTIMPLEMENTED();
    }
  }

  if (incremented_audio_count && incremented_video_count)
    return IDS_MEDIA_STREAM_STATUS_TRAY_BALLOON_BODY_AUDIO_AND_VIDEO;
  else if (incremented_audio_count)
    return IDS_MEDIA_STREAM_STATUS_TRAY_BALLOON_BODY_AUDIO_ONLY;
  else if (incremented_video_count)
    return IDS_MEDIA_STREAM_STATUS_TRAY_BALLOON_BODY_VIDEO_ONLY;
  else
    return 0;
}

void MediaStreamCaptureIndicator::WebContentsDeviceUsage::RemoveDevices(
    const content::MediaStreamDevices& devices) {
  for (content::MediaStreamDevices::const_iterator it = devices.begin();
       it != devices.end(); ++it) {
    if (it->type == content::MEDIA_TAB_AUDIO_CAPTURE ||
        it->type == content::MEDIA_TAB_VIDEO_CAPTURE) {
      --mirroring_ref_count_;
    } else if (it->type == content::MEDIA_SCREEN_VIDEO_CAPTURE) {
      --screen_capture_ref_count_;
    } else if (content::IsAudioMediaType(it->type)) {
      --audio_ref_count_;
    } else if (content::IsVideoMediaType(it->type)) {
      --video_ref_count_;
    } else {
      NOTIMPLEMENTED();
    }
  }

  DCHECK_GE(audio_ref_count_, 0);
  DCHECK_GE(video_ref_count_, 0);
  DCHECK_GE(mirroring_ref_count_, 0);
  DCHECK_GE(screen_capture_ref_count_, 0);
}

MediaStreamCaptureIndicator::MediaStreamCaptureIndicator()
    : status_icon_(NULL),
      mic_image_(NULL),
      camera_image_(NULL),
      balloon_image_(NULL),
      should_show_balloon_(false) {
}

MediaStreamCaptureIndicator::~MediaStreamCaptureIndicator() {
  // The user is responsible for cleaning up by reporting the closure of any
  // opened devices.  However, there exists a race condition at shutdown: The UI
  // thread may be stopped before CaptureDevicesClosed() posts the task to
  // invoke DoDevicesClosedOnUIThread().  In this case, usage_map_ won't be
  // empty like it should.
  DCHECK(usage_map_.empty() ||
         !BrowserThread::IsMessageLoopValid(BrowserThread::UI));

  // Free any WebContentsDeviceUsage objects left over.
  for (UsageMap::const_iterator it = usage_map_.begin(); it != usage_map_.end();
       ++it) {
    delete it->second;
  }
}

bool MediaStreamCaptureIndicator::IsCommandIdChecked(
    int command_id) const {
  NOTIMPLEMENTED() << "There are no checked items in the MediaStream menu.";
  return false;
}

bool MediaStreamCaptureIndicator::IsCommandIdEnabled(
    int command_id) const {
  return command_id != IDC_MinimumLabelValue;
}

bool MediaStreamCaptureIndicator::GetAcceleratorForCommandId(
    int command_id, ui::Accelerator* accelerator) {
  // No accelerators for status icon context menu.
  return false;
}

void MediaStreamCaptureIndicator::ExecuteCommand(int command_id,
                                                 int event_flags) {
  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));

  const int index =
      command_id - IDC_MEDIA_CONTEXT_MEDIA_STREAM_CAPTURE_LIST_FIRST;
  DCHECK_LE(0, index);
  DCHECK_GT(static_cast<int>(command_targets_.size()), index);
  WebContents* const web_contents = command_targets_[index];
  UsageMap::const_iterator it = usage_map_.find(web_contents);
  if (it == usage_map_.end() || it->second->IsWebContentsDestroyed())
    return;
  web_contents->GetDelegate()->ActivateContents(web_contents);
}

void MediaStreamCaptureIndicator::CaptureDevicesOpened(
    int render_process_id,
    int render_view_id,
    const content::MediaStreamDevices& devices,
    const base::Closure& close_callback) {
  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
  DCHECK(!devices.empty());

  BrowserThread::PostTask(
      BrowserThread::UI, FROM_HERE,
      base::Bind(&MediaStreamCaptureIndicator::AddCaptureDevices,
                 this, render_process_id, render_view_id, devices,
                 close_callback));
}

void MediaStreamCaptureIndicator::CaptureDevicesClosed(
    int render_process_id,
    int render_view_id,
    const content::MediaStreamDevices& devices) {
  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
  DCHECK(!devices.empty());

  BrowserThread::PostTask(
      BrowserThread::UI, FROM_HERE,
      base::Bind(&MediaStreamCaptureIndicator::RemoveCaptureDevices,
                 this, render_process_id, render_view_id, devices));
}


bool MediaStreamCaptureIndicator::IsCapturingUserMedia(
    content::WebContents* web_contents) const {
  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));

  UsageMap::const_iterator it = usage_map_.find(web_contents);
  return (it != usage_map_.end() &&
          (it->second->IsCapturingAudio() || it->second->IsCapturingVideo()));
}

bool MediaStreamCaptureIndicator::IsBeingMirrored(
    content::WebContents* web_contents) const {
  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));

  UsageMap::const_iterator it = usage_map_.find(web_contents);
  return it != usage_map_.end() && it->second->IsMirroring();
}

void MediaStreamCaptureIndicator::MaybeCreateStatusTrayIcon() {
  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
  if (status_icon_)
    return;

  // If there is no browser process, we should not create the status tray.
  if (!g_browser_process)
    return;

  StatusTray* status_tray = g_browser_process->status_tray();
  if (!status_tray)
    return;

  status_icon_ = status_tray->CreateStatusIcon();

  EnsureStatusTrayIconResources();
}

void MediaStreamCaptureIndicator::EnsureStatusTrayIconResources() {
  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
  if (!mic_image_) {
    mic_image_ = ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
        IDR_INFOBAR_MEDIA_STREAM_MIC);
  }
  if (!camera_image_) {
    camera_image_ = ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
        IDR_INFOBAR_MEDIA_STREAM_CAMERA);
  }
  if (!balloon_image_) {
    balloon_image_ = ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
        IDR_PRODUCT_LOGO_32);
  }
  DCHECK(mic_image_);
  DCHECK(camera_image_);
  DCHECK(balloon_image_);
}

void MediaStreamCaptureIndicator::ShowBalloon(
    WebContents* web_contents, int balloon_body_message_id) {
  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
  DCHECK_NE(0, balloon_body_message_id);

  // Only show the balloon for extensions.
  const extensions::Extension* const extension = GetExtension(web_contents);
  if (!extension) {
    DVLOG(1) << "Balloon is shown only for extensions";
    return;
  }

  string16 message =
      l10n_util::GetStringFUTF16(balloon_body_message_id,
                                 UTF8ToUTF16(extension->name()));
  Profile* profile =
      Profile::FromBrowserContext(web_contents->GetBrowserContext());

  should_show_balloon_ = true;
  extensions::ImageLoader::Get(profile)->LoadImageAsync(
      extension,
      extensions::IconsInfo::GetIconResource(
          extension, 32, ExtensionIconSet::MATCH_BIGGER),
      gfx::Size(32, 32),
      base::Bind(&MediaStreamCaptureIndicator::OnImageLoaded,
                 this, message));
}

void MediaStreamCaptureIndicator::OnImageLoaded(
    const string16& message,
    const gfx::Image& image) {
  if (!should_show_balloon_ || !status_icon_)
    return;

  const gfx::ImageSkia* image_skia = !image.IsEmpty() ? image.ToImageSkia() :
      ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
          IDR_APP_DEFAULT_ICON);
  status_icon_->DisplayBalloon(*image_skia, string16(), message);
}

void MediaStreamCaptureIndicator::MaybeDestroyStatusTrayIcon() {
  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));

  // Make sure images that finish loading don't cause a balloon to be shown.
  should_show_balloon_ = false;

  if (!status_icon_)
    return;

  // If there is no browser process, we should not do anything.
  if (!g_browser_process)
    return;

  StatusTray* status_tray = g_browser_process->status_tray();
  if (status_tray != NULL) {
    status_tray->RemoveStatusIcon(status_icon_);
    status_icon_ = NULL;
  }
}

void MediaStreamCaptureIndicator::UpdateNotificationUserInterface() {
  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
  scoped_ptr<ui::SimpleMenuModel> menu(new ui::SimpleMenuModel(this));

  bool audio = false;
  bool video = false;
  int command_id = IDC_MEDIA_CONTEXT_MEDIA_STREAM_CAPTURE_LIST_FIRST;
  command_targets_.clear();

  WebContents* screen_capturer = NULL;
  base::Closure close_callback;

  for (UsageMap::const_iterator iter = usage_map_.begin();
       iter != usage_map_.end(); ++iter) {
    // Check if any audio and video devices have been used.
    const WebContentsDeviceUsage& usage = *iter->second;
    WebContents* const web_contents = iter->first;
    if (usage.IsWebContentsDestroyed()) {
      // We only show the tray icon for extensions that have not been
      // destroyed and are capturing audio or video.
      continue;
    }

    if (usage.IsCapturingScreen()) {
      DCHECK(!screen_capturer);
      screen_capturer = web_contents;
      close_callback = usage.StopScreenCaptureCallback();
    }

    // Audio/video icon is shown only for extensions. For regular tabs, we show
    // an indicator in the tab icon.
    if (GetExtension(web_contents) &&
        (usage.IsCapturingAudio() || usage.IsCapturingVideo())) {
      audio = audio || usage.IsCapturingAudio();
      video = video || usage.IsCapturingVideo();

      command_targets_.push_back(web_contents);
      menu->AddItem(command_id, GetTitle(web_contents));

      // If reaching the maximum number, no more item will be added to the menu.
      if (command_id == IDC_MEDIA_CONTEXT_MEDIA_STREAM_CAPTURE_LIST_LAST)
        break;
      ++command_id;
    }
  }

  if (screen_capturer) {
    if (!screen_capture_notification_) {
      screen_capture_notification_ = ScreenCaptureNotificationUI::Create();
      if (!screen_capture_notification_->Show(
              base::Bind(&MediaStreamCaptureIndicator::OnStopScreenCapture,
                         this, close_callback),
              GetTitle(screen_capturer))) {
        OnStopScreenCapture(close_callback);
        screen_capture_notification_.reset();
      }
    }
  } else {
    screen_capture_notification_.reset();
  }

  if (command_targets_.empty()) {
    MaybeDestroyStatusTrayIcon();
    return;
  }

  // The icon will take the ownership of the passed context menu.
  MaybeCreateStatusTrayIcon();
  if (status_icon_) {
    status_icon_->SetContextMenu(menu.release());
    UpdateStatusTrayIconDisplay(audio, video);
  }
}

void MediaStreamCaptureIndicator::UpdateStatusTrayIconDisplay(
    bool audio, bool video) {
  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
  DCHECK(audio || video);
  DCHECK(status_icon_);
  int message_id = 0;
  if (audio && video) {
    message_id = IDS_MEDIA_STREAM_STATUS_TRAY_TEXT_AUDIO_AND_VIDEO;
    status_icon_->SetImage(*camera_image_);
  } else if (audio && !video) {
    message_id = IDS_MEDIA_STREAM_STATUS_TRAY_TEXT_AUDIO_ONLY;
    status_icon_->SetImage(*mic_image_);
  } else if (!audio && video) {
    message_id = IDS_MEDIA_STREAM_STATUS_TRAY_TEXT_VIDEO_ONLY;
    status_icon_->SetImage(*camera_image_);
  }

  status_icon_->SetToolTip(l10n_util::GetStringFUTF16(
      message_id, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
}

WebContents* MediaStreamCaptureIndicator::LookUpByKnownAlias(
    int render_process_id, int render_view_id) const {
  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));

  WebContents* result =
      tab_util::GetWebContentsByID(render_process_id, render_view_id);
  if (!result) {
    const RenderViewIDs key(render_process_id, render_view_id);
    AliasMap::const_iterator it = aliases_.find(key);
    if (it != aliases_.end())
      result = it->second;
  }
  return result;
}

void MediaStreamCaptureIndicator::AddCaptureDevices(
    int render_process_id,
    int render_view_id,
    const content::MediaStreamDevices& devices,
    const base::Closure& close_callback) {
  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));

  WebContents* const web_contents =
      LookUpByKnownAlias(render_process_id, render_view_id);
  if (!web_contents)
    return;

  // Increase the usage ref-counts.
  WebContentsDeviceUsage*& usage = usage_map_[web_contents];
  if (!usage)
    usage = new WebContentsDeviceUsage(web_contents);
  const int balloon_body_message_id =
      usage->AddDevices(devices, close_callback);

  // Keep track of the IDs as a known alias to the WebContents instance.
  const AliasMap::iterator insert_it = aliases_.insert(
      make_pair(RenderViewIDs(render_process_id, render_view_id),
                web_contents)).first;
  DCHECK_EQ(web_contents, insert_it->second)
      << "BUG: IDs refer to two different WebContents instances.";

  web_contents->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);

  UpdateNotificationUserInterface();
  if (balloon_body_message_id)
    ShowBalloon(web_contents, balloon_body_message_id);
}

void MediaStreamCaptureIndicator::RemoveCaptureDevices(
    int render_process_id,
    int render_view_id,
    const content::MediaStreamDevices& devices) {
  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));

  WebContents* const web_contents =
      LookUpByKnownAlias(render_process_id, render_view_id);
  if (!web_contents)
    return;

  // Decrease the usage ref-counts.
  const UsageMap::iterator it = usage_map_.find(web_contents);
  if (it == usage_map_.end()) {
    DLOG(FATAL) << "BUG: Attempt to remove devices more than once.";
    return;
  }
  WebContentsDeviceUsage* const usage = it->second;
  usage->RemoveDevices(devices);

  if (!usage->IsWebContentsDestroyed())
    web_contents->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);

  // Remove the usage and alias mappings if all the devices have been closed.
  if (!usage->IsCapturingAudio() && !usage->IsCapturingVideo() &&
      !usage->IsMirroring() && !usage->IsCapturingScreen()) {
    for (AliasMap::iterator alias_it = aliases_.begin();
         alias_it != aliases_.end(); ) {
      if (alias_it->second == web_contents)
        aliases_.erase(alias_it++);
      else
        ++alias_it;
    }
    delete usage;
    usage_map_.erase(it);
  }

  UpdateNotificationUserInterface();
}

void MediaStreamCaptureIndicator::OnStopScreenCapture(
    const base::Closure& stop) {
  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
  stop.Run();
}